diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e2939ce..99ec393 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,8 +6,8 @@ The following is a set of guidelines for contributing to this repository, which ## What does this repo do? -This repo is a GitHub Action, meaning it integrates with the GitHub Actions CI/CD pipeline. It's meant to take formatted reports with code coverage stats and upload them to codecov.io. What's essentially happening in the background is that Actions is spinning up a Linux Docker container with the contents of this repository. Inside that container, we then call a shell scipt that runs Codecov's Bash uploader. +This repo is a GitHub Action, meaning it integrates with the GitHub Actions CI/CD pipeline. It's meant to take formatted reports with code coverage stats and upload them to codecov.io. Our Node action uses the Actions toolkit to make system calls that allow us to run Codecov's bash uploader inside of Node. Essentially what we're doing in this action is downloading Codecov's bash uploader script from codecov.io/bash, saving it as a file in the current directory, executing the file via `exec` calls, then removing the script from the current directory. -## PRs and Support +## PRs, Issues, and Support -Feel free to clone, modify code and request a PR to this repository. All PRs will be reviewed by the Codecov team. If your PR has been sitting for a while or if you have any questions, ping us at support@codecov.io +Feel free to clone, modify code and request a PR to this repository. All PRs and issues will be reviewed by the Codecov team. If your PR/issue has been sitting for a while or if you have any questions, ping us at support@codecov.io diff --git a/README.md b/README.md index a8bb866..e7e4c72 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,51 @@ # Codecov GitHub Action -[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-v1.0.3-undefined.svg?logo=github&logoColor=white&style=flat)](https://github.com/marketplace/actions/codecov) +[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-v1.0.4-undefined.svg?logo=github&logoColor=white&style=flat)](https://github.com/marketplace/actions/codecov) ### Easily upload coverage reports to Codecov from GitHub Actions ## Usage -To integrate Codecov with your Actions pipeline, specify the name of this repository with a tag number as a `step` within your `workflow.yml` file. This Action also requires you to [provide an upload token](https://docs.codecov.io/docs/frequently-asked-questions#section-where-is-the-repository-upload-token-found-) from [codecov.io](https://www.codecov.io) (tip: in order to avoid exposing your token, store it as a `secret`). Optionally, you can choose to include three additional inputs to customize the upload context. +To integrate Codecov with your Actions pipeline, specify the name of this repository with a tag number as a `step` within your `workflow.yml` file. This Action also requires you to [provide an upload token](https://docs.codecov.io/docs/frequently-asked-questions#section-where-is-the-repository-upload-token-found-) from [codecov.io](https://www.codecov.io) (tip: in order to avoid exposing your token, store it as a `secret`). Optionally, you can choose to include up to four additional inputs to customize the upload context. Inside your `.github/workflows/workflow.yml` file: ```yaml steps: - uses: actions/checkout@master -- uses: codecov/codecov-action@v1.0.3 +- uses: codecov/codecov-action@v1 with: - token: ${{secrets.CODECOV_TOKEN}} #required + token: ${{ secrets.CODECOV_TOKEN }} #required file: ./coverage.xml #optional flags: unittests #optional name: codecov-umbrella #optional + yml: ./codecov.yml #optional ``` >**Note**: This assumes that you've set your Codecov token inside *Settings > Secrets* as `CODECOV_TOKEN`. If not, you can [get an upload token](https://docs.codecov.io/docs/frequently-asked-questions#section-where-is-the-repository-upload-token-found-) for your specific repo on [codecov.io](https://www.codecov.io). ## Arguments -Codecov's Action currently supports four inputs from the user: `token`, `file`, `flags`, and `name`. These inputs, along with their descriptions and usage contexts, are listed in the table below: +Codecov's Action currently supports five inputs from the user: `token`, `file`, `flags`,`name`, and `yml`. These inputs, along with their descriptions and usage contexts, are listed in the table below: | Input | Description | Usage | | :---: | :---: | :---: | | `token` | Used to authorize coverage report uploads | *Required* | -| `file` | Location of the coverage report | Optional +| `file` | Path to the coverage report(s) | Optional | `flags` | Flag upload under a certain group | Optional | `name` | Custom defined name for the upload | Optional +| `yml` | Path to codecov.yml config file | Optional ### Example `workflow.yml` with Codecov Action -> **Note**: This is a Docker based action and will only run on Linux based systems (e.g Ubuntu). Windows and macOS builds are currently not supported. +>**Note**: The latest release of this Action adds support for macOS and Windows builds! ```yaml name: Example workflow for Codecov on: [push] jobs: run: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@master - name: Setup Python @@ -53,12 +58,13 @@ jobs: pip install pytest-cov pytest --cov=./ --cov-report=xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1.0.3 + uses: codecov/codecov-action@v1 with: - token: ${{secrets.CODECOV_TOKEN}} + token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.xml flags: unittests - name: codecov-umbrella + name: codecov-umbrella + yml: ./codecov.yml ``` ## Contributing diff --git a/action.yml b/action.yml index 560a707..379607b 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,9 @@ inputs: flags: description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)' required: false + yml: + description: 'Specify the location of the .codecov.yml config file' + required: false branding: color: 'red' icon: 'umbrella' diff --git a/index.js b/index.js index 894d0d9..55787b1 100644 --- a/index.js +++ b/index.js @@ -1,56 +1,72 @@ -const core = require('@actions/core'); -const request = require('request'); -const exec = require('@actions/exec'); -const fs = require('fs') - +const core = require("@actions/core"); +const exec = require("@actions/exec"); +const request = require("request"); +const fs = require("fs"); + try { - const name = core.getInput('name'); - console.log(`Name: ${name}`); - - let token = core.getInput('token'); - console.log(`Token: ${token}`); + const name = core.getInput("name"); + const token = core.getInput("token"); + const flags = core.getInput("flags"); + const file = core.getInput("file"); + const yml = core.getInput("yml"); - const flags = core.getInput('flags'); - console.log(`Flags: ${flags}`); + request("https://codecov.io/bash", (error, response, body) => { + if (error) throw error; - const file = core.getInput('file'); - console.log(`File: ${file}`); - - request('https://codecov.io/bash', (error, response, body) => { - if (error) throw error - let myOutput = ''; - let myError = ''; - fs.writeFile('codecov.sh', body, (err) => { + fs.writeFile("codecov.sh", body, err => { if (err) throw err; + + let output = ""; + let execError = ""; const options = {}; options.listeners = { - stdout: (data) => { - myOutput += data.toString(); + stdout: data => { + output += data.toString(); }, - stderr: (data) => { - myError += data.toString(); + stderr: data => { + execError += data.toString(); } }; options.env = { - CODECOV_TOKEN: `${token}`, - GITHUB_ACTION: process.env.GITHUB_ACTION, - GITHUB_REF: process.env.GITHUB_REF, - GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY, + CODECOV_TOKEN: `${token}`, + GITHUB_ACTION: process.env.GITHUB_ACTION, + GITHUB_REF: process.env.GITHUB_REF, + GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY, GITHUB_SHA: process.env.GITHUB_SHA }; - if (file){ - exec.exec('bash', ['codecov.sh', '-f', `${file}`, '-n', `${name}`, '-F', `${flags}`], options); - }else{ - exec.exec('bash', ['codecov.sh','-n', `${name}`, '-F', `${flags}`], options); - } - + if (file) { + exec + .exec( + "bash", + ["codecov.sh", "-f", `${file}`, "-n", `${name}`, "-F", `${flags}`, '-y', `${yml}`], + options + ) + .then(() => { + unlinkFile() + }); + } else { + exec + .exec( + "bash", + ["codecov.sh", "-n", `${name}`, "-F", `${flags}`, '-y', `${yml}`], + options + ) + .then(() => { + unlinkFile() + }); + } + + const unlinkFile = () => { + fs.unlink("codecov.sh", err => { + if (err) throw err; + }); + } + }); - - }) - + }); } catch (error) { core.setFailed(error.message); -} \ No newline at end of file +} diff --git a/package.json b/package.json index a71fe04..282c9ec 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,7 @@ "dependencies": { "@actions/core": "^1.2.0", "@actions/exec": "^1.0.1", - "@actions/github": "^1.1.0", - "core-util-is": "^1.0.2", - "exec-sh": "^0.3.4", "fs": "0.0.1-security", - "path": "^0.12.7", - "request": "^2.88.0", - "temp": "^0.9.1", - "tmp": "^0.1.0" + "request": "^2.88.0" } }