diff --git a/README.md b/README.md index 399ae9b..542bb20 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ steps: flags: unittests #optional name: codecov-umbrella #optional yml: ./codecov.yml #optional - fail_ci_if_error: yes #optional (default = no) + 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). @@ -36,7 +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 | `name` | Custom defined name for the upload | 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 +| `fail_ci_if_error` | Specify if CI pipeline should fail when Codecov runs into errors during upload. *Defaults to **false***. | Optional ### Example `workflow.yml` with Codecov Action @@ -68,7 +68,7 @@ jobs: flags: unittests name: codecov-umbrella yml: ./codecov.yml - fail_ci_if_error: yes + fail_ci_if_error: true ``` ## Contributing diff --git a/index.js b/index.js index 6035a25..f73efd9 100644 --- a/index.js +++ b/index.js @@ -3,20 +3,40 @@ const exec = require("@actions/exec"); const request = require("request"); const fs = require("fs"); +let fail_ci; try { 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"); - let fail_ci = core.getInput("fail_ci_if_error"); - fail_ci = fail_ci.toLowerCase(); + fail_ci = core.getInput("fail_ci_if_error").toLowerCase(); + + if ( + fail_ci === "yes" || + fail_ci === "y" || + fail_ci === "true" || + fail_ci === "t" || + fail_ci === "1" + ) { + fail_ci = true; + } else { + fail_ci = false; + } request("https://codecov.io/bash", (error, response, body) => { - if (error) throw error; + if (error && fail_ci) { + throw error; + } else if (error) { + core.warning(error); + } fs.writeFile("codecov.sh", body, err => { - if (err) throw err; + if (err && fail_ci) { + throw err; + } else if (err) { + core.warning(err); + } let output = ""; let execError = ""; @@ -38,18 +58,6 @@ try { GITHUB_SHA: process.env.GITHUB_SHA }; - if ( - fail_ci === "yes" || - fail_ci === "y" || - fail_ci === "true" || - fail_ci === "t" || - fail_ci === "1" - ) { - fail_ci = true; - } else { - fail_ci = false; - } - if (file) { if (fail_ci) { exec @@ -138,11 +146,19 @@ try { const unlinkFile = () => { fs.unlink("codecov.sh", err => { - if (err) throw err; + if (err && fail_ci) { + throw err; + } else if (err) { + core.warning(err); + } }); }; }); }); } catch (error) { - core.setFailed(error.message); + if (fail_ci) { + core.setFailed(error.message); + } else { + core.warning(error.message); + } }