Merge pull request #64 from samuelcolvin/env-vars

Env vars
This commit is contained in:
Thomas Hu
2020-05-06 17:35:02 -04:00
committed by GitHub
4 changed files with 25415 additions and 24533 deletions

View File

@@ -1,13 +1,13 @@
# Codecov GitHub Action # Codecov GitHub Action
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-v1-undefined.svg?logo=github&logoColor=white&style=flat)](https://github.com/marketplace/actions/codecov) [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-v1-undefined.svg?logo=github&logoColor=white&style=flat)](https://github.com/marketplace/actions/codecov)
### Easily upload coverage reports to Codecov from GitHub Actions ### Easily upload coverage reports to Codecov from GitHub Actions
>The latest release of this Action adds support for tokenless uploads from GitHub Actions! >The latest release of this Action adds support for tokenless uploads from GitHub Actions!
## Usage ## Usage
To integrate Codecov with your Actions pipeline, specify the name of this repository with a tag number (`@v1` is recommended) as a `step` within your `workflow.yml` file. To integrate Codecov with your Actions pipeline, specify the name of this repository with a tag number (`@v1` is recommended) as a `step` within your `workflow.yml` file.
If you have a *private repository*, 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. **For public repositories, no token is needed** If you have a *private repository*, 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. **For public repositories, no token is needed**
@@ -24,11 +24,11 @@ steps:
name: codecov-umbrella # optional name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false) fail_ci_if_error: true # optional (default = false)
``` ```
>**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). Keep in mind that secrets are *not* available to forks of repositories. >**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). Keep in mind that secrets are *not* available to forks of repositories.
## Arguments ## Arguments
Codecov's Action currently supports five inputs from the user: `token`, `file`, `flags`,`name`, and `fail_ci_if_error`. 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 `fail_ci_if_error`. These inputs, along with their descriptions and usage contexts, are listed in the table below:
>**Update**: We've removed the `yml` parameter with the latest release of this action. Please put your custom codecov yaml file at the root of the repo because other locations will no longer be supported in the future. >**Update**: We've removed the `yml` parameter with the latest release of this action. Please put your custom codecov yaml file at the root of the repo because other locations will no longer be supported in the future.
@@ -37,6 +37,7 @@ Codecov's Action currently supports five inputs from the user: `token`, `file`,
| `token` | Used to authorize coverage report uploads | *Required for private repos* | | `token` | Used to authorize coverage report uploads | *Required for private repos* |
| `file` | Path to the coverage report(s) | Optional | `file` | Path to the coverage report(s) | Optional
| `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.). Multiple flags are separated by a comma (ui,chrome) | Optional | `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.). Multiple flags are separated by a comma (ui,chrome) | Optional
| `env_vars` | Environment variables to tag the upload with. Multiple env variables can be separated with commas (e.g. `OS,PYTHON`) | Optional
| `name` | Custom defined name for the upload | Optional | `name` | Custom defined name for the upload | Optional
| `fail_ci_if_error` | Specify if CI pipeline should fail when Codecov runs into errors during upload. *Defaults to **false*** | Optional | `fail_ci_if_error` | Specify if CI pipeline should fail when Codecov runs into errors during upload. *Defaults to **false*** | Optional
@@ -49,11 +50,14 @@ jobs:
run: run:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
env:
OS: ${{ matrix.os }}
PYTHON: '3.7'
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
- name: Setup Python - name: Setup Python
uses: actions/setup-python@master uses: actions/setup-python@master
with: with:
python-version: 3.7 python-version: 3.7
@@ -62,12 +66,13 @@ jobs:
pip install pytest pip install pytest
pip install pytest-cov pip install pytest-cov
pytest --cov=./ --cov-report=xml pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v1
with: with:
token: ${{ secrets.CODECOV_TOKEN }} token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml file: ./coverage.xml
flags: unittests flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella name: codecov-umbrella
fail_ci_if_error: true fail_ci_if_error: true
``` ```
@@ -75,6 +80,6 @@ jobs:
Contributions are welcome! Check out the [Contribution Guide](CONTRIBUTING.md). Contributions are welcome! Check out the [Contribution Guide](CONTRIBUTING.md).
## License ## License
The code in this project is released under the [MIT License](LICENSE). The code in this project is released under the [MIT License](LICENSE).

View File

@@ -1,26 +1,28 @@
name: 'Codecov' name: 'Codecov'
description: 'GitHub Action that uploads coverage reports for your repository to codecov.io' description: 'GitHub Action that uploads coverage reports for your repository to codecov.io'
author: 'Ibrahim Ali <@ibrahim0814> | Codecov' author: 'Ibrahim Ali <@ibrahim0814> | Codecov'
inputs: inputs:
name: name:
description: 'User defined upload name. Visible in Codecov UI' description: 'User defined upload name. Visible in Codecov UI'
required: false required: false
token: token:
description: 'Repository upload token - get it from codecov.io. Required only for private repositories' description: 'Repository upload token - get it from codecov.io. Required only for private repositories'
required: false required: false
file: file:
description: 'Path to coverage file to upload' description: 'Path to coverage file to upload'
required: false required: false
flags: flags:
description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)' description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)'
required: false required: false
env_vars:
description: 'Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)'
required: false
fail_ci_if_error: fail_ci_if_error:
description: 'Specify whether or not CI build should fail if Codecov runs into an error during upload' description: 'Specify whether or not CI build should fail if Codecov runs into an error during upload'
required: false required: false
branding: branding:
color: 'red' color: 'red'
icon: 'umbrella' icon: 'umbrella'
runs: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'

49894
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -9,6 +9,8 @@ try {
const token = core.getInput("token"); const token = core.getInput("token");
const flags = core.getInput("flags"); const flags = core.getInput("flags");
const file = core.getInput("file"); const file = core.getInput("file");
const env_vars = core.getInput("env_vars");
fail_ci = core.getInput("fail_ci_if_error").toLowerCase(); fail_ci = core.getInput("fail_ci_if_error").toLowerCase();
if ( if (
@@ -62,6 +64,15 @@ try {
options.env.CODECOV_TOKEN = token options.env.CODECOV_TOKEN = token
} }
const env_vars_arg = []
for (let env_var of env_vars.split(",")) {
let env_var_clean = env_var.trim();
if (env_var_clean) {
options.env[env_var_clean] = process.env[env_var_clean];
env_vars_arg.push(env_var_clean)
}
}
const execArgs = ["codecov.sh"]; const execArgs = ["codecov.sh"];
if (file) { if (file) {
execArgs.push( execArgs.push(
@@ -80,6 +91,12 @@ try {
); );
} }
if (env_vars_arg.length) {
execArgs.push(
"-e", env_vars_arg.join(",")
);
}
exec.exec("bash", execArgs, options) exec.exec("bash", execArgs, options)
.catch(err => { .catch(err => {
if (fail_ci) { if (fail_ci) {
@@ -92,7 +109,7 @@ try {
}) })
.then(() => { .then(() => {
unlinkFile(); unlinkFile();
});; });
const unlinkFile = () => { const unlinkFile = () => {
fs.unlink("codecov.sh", err => { fs.unlink("codecov.sh", err => {