From 83231650328f11695dfb754ca0f540516f188d27 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Sat, 2 Jan 2021 14:03:30 -0500 Subject: [PATCH] Add all the bash params --- CHANGELOG.md | 8 +++ README.md | 34 +++++++-- dist/index.js | 174 +++++++++++++++++++--------------------------- hooks/pre-commit | 1 + index.js | 174 +++++++++++++++++++--------------------------- package-lock.json | 3 +- 6 files changed, 181 insertions(+), 213 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d416f2ef5..dfb0da808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +### 1.2.0 + +#### Features +- #185 [Placeholder] + +#### Fixes +- #185 [Placeholder] + ### 1.1.1 #### Fixes diff --git a/README.md b/README.md index 4025d1308..c523faaff 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ steps: - uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos - file: ./coverage.xml # optional files: ./coverage1.xml,./coverage2.xml # optional flags: unittests # optional name: codecov-umbrella # optional @@ -36,16 +35,42 @@ Codecov's Action currently supports five inputs from the user: `token`, `file`, | Input | Description | Usage | | :---: | :---: | :---: | | `token` | Used to authorize coverage report uploads | *Required for private repos* | -| `file` | Path to the coverage report(s) | Optional | `files` | Comma-separated paths to the coverage report(s) | Optional | `directory` | Directory to search for coverage reports. | Optional | `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.). Multiple flags are separated by a comma (ui,chrome) | Optional +| | | +| `aws_curl_args` | Extra curl arguments to communicate with AWS. | Optional +| `codecov_curl_args` | Extra curl arguments to communicate with Codecov. e.g., -U "--proxy http://http-proxy" | Optional +| `commit_parent` | The commit SHA of the parent for which you are uploading coverage. If not present, the parent will be determined using the API of your repository provider. When using the repository provider's API, the parent is determined via finding the closest ancestor to the commit. | 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 | `fail_ci_if_error` | Specify if CI pipeline should fail when Codecov runs into errors during upload. *Defaults to **false*** | Optional +| `functionalities` | Toggle functionalities | Optional +| | `coveragepy` Disable python coverage | +| | `fix` Disable report fixing | +| | `gcov` Disable gcov | +| | `gcovout` Disable gcov output | +| | `html` Enable coverage for HTML files | +| | `network` Disable uploading the file network | +| | `recursesubs` Enable recurse submodules in git projects when searching for source files | | +| | `search` Disable searching for reports | +| | `xcode` Disable xcode processing | +| `gcov path_include` | Paths to include during gcov gathering (as a glob) | Optional +| `gcov_args` | extra arguments to pass to gcov | Optional +| `gcov_executable` | gcov executable to run. Defaults to 'gcov' | Optional +| `gcov_path_exclude` | Paths to ignore during gcov gathering (as a glob) | Optional +| `gcov_prefix` | Prefix filepaths to help resolve path fixing | Optional +| `gcov_root_dir` | Project root directory, also used when preparing gcov | Optional +| `move_coverage_to_trash` | Move discovered coverage reports to the trash | Optional +| `name` | Custom defined name for the upload | Optional +| `override_branch` | Specify the branch name | Optional +| `override_build` | Specify the build number | Optional +| `override_commit` | Specify the commit SHA | Optional +| `override_pr` | Specify the pull request number | Optional +| `override_tag` | Specify the git tag | Optional | `path_to_write_report` | Write upload file to path before uploading | Optional +| `root_dir` | Used when not in git/hg project to identify project root directory | Optional | `verbose` | Specify whether the Codecov output should be verbose | Optional -| `working-directory` | Directory in which to execute `codecov.sh` | Optional +| `working_directory` | Directory in which to execute `codecov.sh` | Optional | `xcode_derived_data` | Custom Derived Data Path for Coverage.profdata and gcov processing | Optional | `xcode_package` | Specify packages to build coverage. Uploader will only build these packages. This can significantly reduces time to build coverage reports. -J 'MyAppName' Will match "MyAppName" and "MyAppNameTests" -J '^ExampleApp$' Will match only "ExampleApp" not "ExampleAppTests" | Optional @@ -78,7 +103,6 @@ jobs: uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.xml files: ./coverage1.xml,./coverage2.xml directory: ./coverage/reports/ flags: unittests diff --git a/dist/index.js b/dist/index.js index 3677daaab..17a04b07b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2519,47 +2519,50 @@ const exec = __webpack_require__(986); const fs = __webpack_require__(747); const request = __webpack_require__(335); -let fail_ci; -let verbose; try { + let isTrue = (variable) => { + const lowercase = variable.toLowerCase(); + return ( + lowercase === "1" || + lowercase === "t" || + lowercase === "true" || + lowercase === "y" || + lowercase === "yes" + ); + } + + const env_vars = core.getInput("env_vars"); + const fail_ci = isTrue(core.getInput("fail_ci_if_error")); + const files = core.getInput("files"); + const flags = core.getInput("flags"); + const functionalities = core.getInput("functionalities"); const name = core.getInput("name"); + const search_dir = core.getInput("directory"); const token = core.getInput("token"); - const flags = core.getInput("flags"); - const file = core.getInput("file"); - const files = core.getInput("files"); - const env_vars = core.getInput("env_vars"); - const dir = core.getInput("directory"); + const verbose = isTrue(core.getInput("verbose")); + const working_dir = core.getInput("working_directory"); const write_path = core.getInput("path_to_write_report"); - const working_dir = core.getInput("working-directory"); const xcode_derived_data = core.getInput("xcode_derived_data"); const xcode_package = core.getInput("xcode_package"); - fail_ci = core.getInput("fail_ci_if_error").toLowerCase(); - verbose = core.getInput("verbose").toLowerCase(); - - if ( - fail_ci === "yes" || - fail_ci === "y" || - fail_ci === "true" || - fail_ci === "t" || - fail_ci === "1" - ) { - fail_ci = true; - } else { - fail_ci = false; - } - - if ( - verbose === "yes" || - verbose === "y" || - verbose === "true" || - verbose === "t" || - verbose === "1" - ) { - verbose = true; - } else { - verbose = false; - } + const commit_parent = core.getInput("commit_parent"); + const root_dir = core.getInput("root_dir"); + const clean = core.getInput("move_coverage_to_trash"); + const gcov_exclude = core.getInput("gcov_path_exclude"); + const gcov_include = core.getInput("gcov_path_include"); + const gcov_dir = core.getInput("gcov_root_dir"); + const gcov_prefix = core.getInput("gcov_prefix"); + const gcov_exec = core.getInput("gcov_executable"); + const gcov_args = core.getInput("gcov_args"); + + const override_commit = core.getInput("override_commit"); + const override_branch = core.getInput("override_branch"); + const override_pr = core.getInput("override_pr"); + const override_build = core.getInput("override_build"); + const override_tag = core.getInput("override_tag"); + + const curl_codecov_args = core.getInput("codecov_curl_args"); + const curl_aws_args = core.getInput("aws_curl_args"); request({ json: false, @@ -2574,7 +2577,10 @@ try { core.warning(`Codecov warning: ${error.message}`); } - fs.writeFile("codecov.sh", body, err => { + filepath = working_dir ? + working_dir + "/codecov.sh" : "codecov.sh" + + fs.writeFile(filepath, body, err => { if (err && fail_ci) { throw err; } else if (err) { @@ -2615,73 +2621,35 @@ try { } } - const execArgs = ["codecov.sh"]; - execArgs.push("-Q", "github-action"); - - if (file) { - execArgs.push( - "-f", `${file}` - ); - } - - if (files) { - files.split(',').forEach(f => { - execArgs.push( - "-f", `${f}` - ); - }); - } - - if (dir) { - execArgs.push( - "-s", `${dir}` - ); - } - - execArgs.push( - "-n", `${name}`, - "-F", `${flags}` - ); - - if (fail_ci) { - execArgs.push( - "-Z" - ); - } - - if (env_vars_arg.length) { - execArgs.push( - "-e", env_vars_arg.join(",") - ); - } - - if (write_path) { - execArgs.push( - "-q", `${write_path}` - ); - } - - if (verbose) { - execArgs.push( - "-v" - ); - } - - if (working_dir) { - options.cwd = working_dir; - } - - if (xcode_derived_data) { - execArgs.push( - "-D", `${xcode_derived_data}` - ); - } - - if (xcode_package) { - execArgs.push( - "-J", `${xcode_package}` - ); - } + const execArgs = [filepath]; + execArgs.push( "-n", `${name}`, "-F", `${flags}`, "-Q", "github-action" ); + + if (clean) { execArgs.push( "-c"); } + if (commit_parent) { execArgs.push( "-N", `${commit_parent}`); } + if (curl_aws_args) { execArgs.push( "-A", `${curl_aws_args}`); } + if (curl_codecov_args) { execArgs.push( "-U", `${curl_codecov_args}`); } + if (env_vars_arg.length) { execArgs.push( "-e", env_vars_arg.join(",")); } + if (fail_ci) { execArgs.push( "-Z"); } + if (files) { files.split(',').forEach(f => { execArgs.push( "-f", `${f}`); }); } + if (functionalities) { functionalities.split(',').forEach(f => { execArgs.push( "-X", `${f}`); }); } + if (gcov_args) { execArgs.push( "-a", `${gcov_args}`); } + if (gcov_dir) { execArgs.push( "-p", `${gcov_dir}`); } + if (gcov_exclude) { execArgs.push( "-g", `${gcov_exclude}`); } + if (gcov_exec) { execArgs.push( "-x", `${gcov_exec}`); } + if (gcov_include) { execArgs.push( "-G", `${gcov_include}`); } + if (gcov_prefix) { execArgs.push( "-k", `${gcov_prefix}`); } + if (override_branch) { execArgs.push( "-B", `${override_branch}`); } + if (override_build) { execArgs.push( "-b", `${override_build}`); } + if (override_commit) { execArgs.push( "-C", `${override_commit}`); } + if (override_pr) { execArgs.push( "-P", `${override_pr}`); } + if (override_tag) { execArgs.push( "-T", `${override_tag}`); } + if (root_dir) { execArgs.push( "-N", `${root_dir}`); } + if (search_dir) { execArgs.push( "-s", `${search_dir}`); } + if (verbose) { execArgs.push( "-v"); } + if (working_dir) { options.cwd = working_dir; } + if (write_path) { execArgs.push( "-q", `${write_path}`); } + if (xcode_derived_data) { execArgs.push( "-D", `${xcode_derived_data}`); } + if (xcode_package) { execArgs.push( "-J", `${xcode_package}`); } exec.exec("bash", execArgs, options) .catch(err => { @@ -2698,7 +2666,7 @@ try { }); const unlinkFile = () => { - fs.unlink("codecov.sh", err => { + fs.unlink(filepath, err => { if (err && fail_ci) { throw err; } else if (err) { diff --git a/hooks/pre-commit b/hooks/pre-commit index ea68e88de..034f5ff65 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -3,3 +3,4 @@ npm i --package-lock-only npm run build git add dist/index.js +git add package-lock.json diff --git a/index.js b/index.js index a17123377..ba4813c4a 100644 --- a/index.js +++ b/index.js @@ -3,47 +3,50 @@ const exec = require("@actions/exec"); const fs = require("fs"); const request = require('requestretry'); -let fail_ci; -let verbose; try { + let isTrue = (variable) => { + const lowercase = variable.toLowerCase(); + return ( + lowercase === "1" || + lowercase === "t" || + lowercase === "true" || + lowercase === "y" || + lowercase === "yes" + ); + } + + const env_vars = core.getInput("env_vars"); + const fail_ci = isTrue(core.getInput("fail_ci_if_error")); + const files = core.getInput("files"); + const flags = core.getInput("flags"); + const functionalities = core.getInput("functionalities"); const name = core.getInput("name"); + const search_dir = core.getInput("directory"); const token = core.getInput("token"); - const flags = core.getInput("flags"); - const file = core.getInput("file"); - const files = core.getInput("files"); - const env_vars = core.getInput("env_vars"); - const dir = core.getInput("directory"); + const verbose = isTrue(core.getInput("verbose")); + const working_dir = core.getInput("working_directory"); const write_path = core.getInput("path_to_write_report"); - const working_dir = core.getInput("working-directory"); const xcode_derived_data = core.getInput("xcode_derived_data"); const xcode_package = core.getInput("xcode_package"); - fail_ci = core.getInput("fail_ci_if_error").toLowerCase(); - verbose = core.getInput("verbose").toLowerCase(); - - if ( - fail_ci === "yes" || - fail_ci === "y" || - fail_ci === "true" || - fail_ci === "t" || - fail_ci === "1" - ) { - fail_ci = true; - } else { - fail_ci = false; - } - - if ( - verbose === "yes" || - verbose === "y" || - verbose === "true" || - verbose === "t" || - verbose === "1" - ) { - verbose = true; - } else { - verbose = false; - } + const commit_parent = core.getInput("commit_parent"); + const root_dir = core.getInput("root_dir"); + const clean = core.getInput("move_coverage_to_trash"); + const gcov_exclude = core.getInput("gcov_path_exclude"); + const gcov_include = core.getInput("gcov_path_include"); + const gcov_dir = core.getInput("gcov_root_dir"); + const gcov_prefix = core.getInput("gcov_prefix"); + const gcov_exec = core.getInput("gcov_executable"); + const gcov_args = core.getInput("gcov_args"); + + const override_commit = core.getInput("override_commit"); + const override_branch = core.getInput("override_branch"); + const override_pr = core.getInput("override_pr"); + const override_build = core.getInput("override_build"); + const override_tag = core.getInput("override_tag"); + + const curl_codecov_args = core.getInput("codecov_curl_args"); + const curl_aws_args = core.getInput("aws_curl_args"); request({ json: false, @@ -58,7 +61,10 @@ try { core.warning(`Codecov warning: ${error.message}`); } - fs.writeFile("codecov.sh", body, err => { + filepath = working_dir ? + working_dir + "/codecov.sh" : "codecov.sh" + + fs.writeFile(filepath, body, err => { if (err && fail_ci) { throw err; } else if (err) { @@ -99,73 +105,35 @@ try { } } - const execArgs = ["codecov.sh"]; - execArgs.push("-Q", "github-action"); - - if (file) { - execArgs.push( - "-f", `${file}` - ); - } - - if (files) { - files.split(',').forEach(f => { - execArgs.push( - "-f", `${f}` - ); - }); - } - - if (dir) { - execArgs.push( - "-s", `${dir}` - ); - } - - execArgs.push( - "-n", `${name}`, - "-F", `${flags}` - ); - - if (fail_ci) { - execArgs.push( - "-Z" - ); - } - - if (env_vars_arg.length) { - execArgs.push( - "-e", env_vars_arg.join(",") - ); - } - - if (write_path) { - execArgs.push( - "-q", `${write_path}` - ); - } - - if (verbose) { - execArgs.push( - "-v" - ); - } - - if (working_dir) { - options.cwd = working_dir; - } - - if (xcode_derived_data) { - execArgs.push( - "-D", `${xcode_derived_data}` - ); - } - - if (xcode_package) { - execArgs.push( - "-J", `${xcode_package}` - ); - } + const execArgs = [filepath]; + execArgs.push( "-n", `${name}`, "-F", `${flags}`, "-Q", "github-action" ); + + if (clean) { execArgs.push( "-c"); } + if (commit_parent) { execArgs.push( "-N", `${commit_parent}`); } + if (curl_aws_args) { execArgs.push( "-A", `${curl_aws_args}`); } + if (curl_codecov_args) { execArgs.push( "-U", `${curl_codecov_args}`); } + if (env_vars_arg.length) { execArgs.push( "-e", env_vars_arg.join(",")); } + if (fail_ci) { execArgs.push( "-Z"); } + if (files) { files.split(',').forEach(f => { execArgs.push( "-f", `${f}`); }); } + if (functionalities) { functionalities.split(',').forEach(f => { execArgs.push( "-X", `${f}`); }); } + if (gcov_args) { execArgs.push( "-a", `${gcov_args}`); } + if (gcov_dir) { execArgs.push( "-p", `${gcov_dir}`); } + if (gcov_exclude) { execArgs.push( "-g", `${gcov_exclude}`); } + if (gcov_exec) { execArgs.push( "-x", `${gcov_exec}`); } + if (gcov_include) { execArgs.push( "-G", `${gcov_include}`); } + if (gcov_prefix) { execArgs.push( "-k", `${gcov_prefix}`); } + if (override_branch) { execArgs.push( "-B", `${override_branch}`); } + if (override_build) { execArgs.push( "-b", `${override_build}`); } + if (override_commit) { execArgs.push( "-C", `${override_commit}`); } + if (override_pr) { execArgs.push( "-P", `${override_pr}`); } + if (override_tag) { execArgs.push( "-T", `${override_tag}`); } + if (root_dir) { execArgs.push( "-N", `${root_dir}`); } + if (search_dir) { execArgs.push( "-s", `${search_dir}`); } + if (verbose) { execArgs.push( "-v"); } + if (working_dir) { options.cwd = working_dir; } + if (write_path) { execArgs.push( "-q", `${write_path}`); } + if (xcode_derived_data) { execArgs.push( "-D", `${xcode_derived_data}`); } + if (xcode_package) { execArgs.push( "-J", `${xcode_package}`); } exec.exec("bash", execArgs, options) .catch(err => { @@ -182,7 +150,7 @@ try { }); const unlinkFile = () => { - fs.unlink("codecov.sh", err => { + fs.unlink(filepath, err => { if (err && fail_ci) { throw err; } else if (err) { diff --git a/package-lock.json b/package-lock.json index 2b6d6770d..773ae3ea5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2351,8 +2351,7 @@ "is-docker": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.1.1.tgz", - "integrity": "sha512-ZOoqiXfEwtGknTiuDEy8pN2CfE3TxMHprvNer1mXiqwkOT77Rw3YVrUQ52EqAOU3QAWDQ+bQdx7HJzrv7LS2Hw==", - "optional": true + "integrity": "sha512-ZOoqiXfEwtGknTiuDEy8pN2CfE3TxMHprvNer1mXiqwkOT77Rw3YVrUQ52EqAOU3QAWDQ+bQdx7HJzrv7LS2Hw==" }, "is-extendable": { "version": "0.1.1",