From 1301fde38c3a6889d9933cf58293c52d6972869a Mon Sep 17 00:00:00 2001 From: Algin Maduro <1469047+mad-it@users.noreply.github.com> Date: Tue, 6 Jul 2021 21:04:34 +0200 Subject: [PATCH] feat: add addition override parameters (#86) --- README.md | 2 ++ action.yml | 6 ++++++ lib/run.js | 10 +++++++++- src/run.ts | 13 ++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a615cdf..daba6925 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ The action's step needs to run after your test suite has outputted an LCOV file. | `parallel-finished` | _optional_ | Set to true in the last job, after the other parallel jobs steps have completed, this will send a webhook to Coveralls to set the build complete. | | `coveralls-endpoint` | _optional_ | Hostname and protocol: `https://`; Specifies a [Coveralls Enterprise](https://enterprise.coveralls.io/) hostname. | | `base-path` | _optional_ | Path to the root folder of the project the coverage was collected in. Should be used in monorepos so that coveralls can process the LCOV correctly (e.g. packages/my-project) | +| `git-branch` | _optional_ | Default: GITHUB_REF environment variable. Override the branch name. | +| `git-commit` | _optional_ | Default: GITHUB_SHA environment variable. Override the commit sha. | ### Outputs: diff --git a/action.yml b/action.yml index 4fb11868..70a4be75 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,12 @@ inputs: base-path: description: 'The root folder of the project that originally ran the tests' required: false + git-branch: + description: 'Override the branch name' + required: false + git-commit: + description: 'Override the commit sha' + required: false outputs: coveralls-api-result: description: 'Result status of Coveralls API post.' diff --git a/lib/run.js b/lib/run.js index b6e44f3a..7cd26a75 100644 --- a/lib/run.js +++ b/lib/run.js @@ -40,7 +40,15 @@ function run() { console.log("Event Name: " + process.env.GITHUB_EVENT_NAME); console.log(event); } - if (process.env.GITHUB_EVENT_NAME == 'pull_request') { + const gitCommit = core.getInput('git-commit'); + const gitBranch = core.getInput('git-branch'); + if (gitCommit && gitCommit != '') { + process.env.COVERALLS_GIT_COMMIT = gitCommit; + } + if (gitBranch && gitBranch != '') { + process.env.COVERALLS_GIT_BRANCH = gitBranch; + } + if (process.env.GITHUB_EVENT_NAME == 'pull_request' || process.env.GITHUB_EVENT_NAME == 'pull_request_target') { process.env.CI_PULL_REQUEST = JSON.parse(event).number; } const endpoint = core.getInput('coveralls-endpoint'); diff --git a/src/run.ts b/src/run.ts index fe2273fa..2821806a 100644 --- a/src/run.ts +++ b/src/run.ts @@ -35,7 +35,18 @@ export async function run() { console.log(event); } - if (process.env.GITHUB_EVENT_NAME == 'pull_request') { + const gitCommit = core.getInput('git-commit'); + const gitBranch = core.getInput('git-branch'); + + if (gitCommit && gitCommit != '') { + process.env.COVERALLS_GIT_COMMIT = gitCommit; + } + + if (gitBranch && gitBranch != '') { + process.env.COVERALLS_GIT_BRANCH = gitBranch; + } + + if (process.env.GITHUB_EVENT_NAME == 'pull_request' || process.env.GITHUB_EVENT_NAME == 'pull_request_target') { process.env.CI_PULL_REQUEST = JSON.parse(event).number; }