This commit is contained in:
ibrahim0814
2019-12-05 00:57:51 -08:00
parent cec654a0a7
commit 3d11715b9e
4 changed files with 196 additions and 33549 deletions

View File

@@ -7,7 +7,7 @@
## Usage ## 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 up to four 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 five additional inputs to customize the upload context.
Inside your `.github/workflows/workflow.yml` file: Inside your `.github/workflows/workflow.yml` file:
@@ -21,12 +21,13 @@ steps:
flags: unittests #optional flags: unittests #optional
name: codecov-umbrella #optional name: codecov-umbrella #optional
yml: ./codecov.yml #optional yml: ./codecov.yml #optional
fail_ci_if_error: yes #optional (default = no)
``` ```
>**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). >**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 ## Arguments
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: Codecov's Action currently supports five inputs from the user: `token`, `file`, `flags`,`name`, `yml`, and `fail_ci_if_error`. These inputs, along with their descriptions and usage contexts, are listed in the table below:
| Input | Description | Usage | | Input | Description | Usage |
| :---: | :---: | :---: | | :---: | :---: | :---: |
@@ -35,6 +36,7 @@ Codecov's Action currently supports five inputs from the user: `token`, `file`,
| `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.) | Optional | `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.) | Optional
| `name` | Custom defined name for the upload | Optional | `name` | Custom defined name for the upload | Optional
| `yml` | Path to codecov.yml config file | Optional | `yml` | Path to codecov.yml config file | Optional
| `fail_ci_if_error` | Specify whether CI pipeline should fail if there are errors related to Codecov. *Defaults to no*. | Optional
### Example `workflow.yml` with Codecov Action ### Example `workflow.yml` with Codecov Action
@@ -66,6 +68,7 @@ jobs:
flags: unittests flags: unittests
name: codecov-umbrella name: codecov-umbrella
yml: ./codecov.yml yml: ./codecov.yml
fail_ci_if_error: yes
``` ```
## Contributing ## Contributing

View File

@@ -17,6 +17,9 @@ inputs:
yml: yml:
description: 'Specify the location of the .codecov.yml config file' description: 'Specify the location of the .codecov.yml config file'
required: false required: false
fail_ci_if_error:
description: 'Specify whether or not CI build should fail is something goes wrong with Codecov'
required: false
branding: branding:
color: 'red' color: 'red'
icon: 'umbrella' icon: 'umbrella'

33625
dist/index.js vendored

File diff suppressed because one or more lines are too long

110
index.js
View File

@@ -4,12 +4,13 @@ const request = require("request");
const fs = require("fs"); const fs = require("fs");
try { try {
const name = core.getInput("name"); const name = core.getInput("name");
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 yml = core.getInput("yml"); const yml = core.getInput("yml");
const fail_ci = core.getInput("fail_ci_if_error");
fail_ci = fail_ci.toLowerCase();
request("https://codecov.io/bash", (error, response, body) => { request("https://codecov.io/bash", (error, response, body) => {
if (error) throw error; if (error) throw error;
@@ -37,34 +38,99 @@ try {
GITHUB_SHA: process.env.GITHUB_SHA GITHUB_SHA: process.env.GITHUB_SHA
}; };
if (file) { if (
exec fail_ci === "yes" ||
.exec( fail_ci === "y" ||
"bash", fail_ci === "true" ||
["codecov.sh", "-f", `${file}`, "-n", `${name}`, "-F", `${flags}`, '-y', `${yml}`], fail_ci === "t" ||
options fail_ci === "1"
) ) {
.then(() => { fail_ci = true;
unlinkFile()
});
} else { } else {
exec fail_ci = false;
.exec( }
"bash",
["codecov.sh", "-n", `${name}`, "-F", `${flags}`, '-y', `${yml}`], if (file) {
options if (fail_ci) {
) exec
.then(() => { .exec(
unlinkFile() "bash",
}); [
"codecov.sh",
"-f",
`${file}`,
"-n",
`${name}`,
"-F",
`${flags}`,
"-y",
`${yml}`,
"-Z"
],
options
)
.then(() => {
unlinkFile();
});
} else {
exec
.exec(
"bash",
[
"codecov.sh",
"-f",
`${file}`,
"-n",
`${name}`,
"-F",
`${flags}`,
"-y",
`${yml}`
],
options
)
.then(() => {
unlinkFile();
});
}
} else {
if (fail_ci) {
exec
.exec(
"bash",
[
"codecov.sh",
"-n",
`${name}`,
"-F",
`${flags}`,
"-y",
`${yml}`,
"-Z"
],
options
)
.then(() => {
unlinkFile();
});
} else {
exec
.exec(
"bash",
["codecov.sh", "-n", `${name}`, "-F", `${flags}`, "-y", `${yml}`],
options
)
.then(() => {
unlinkFile();
});
}
} }
const unlinkFile = () => { const unlinkFile = () => {
fs.unlink("codecov.sh", err => { fs.unlink("codecov.sh", err => {
if (err) throw err; if (err) throw err;
}); });
} };
}); });
}); });
} catch (error) { } catch (error) {