Skip to content

Commit

Permalink
Better parallel handling; flag_name support
Browse files Browse the repository at this point in the history
* use GITHUB_RUN_ID instead of SHA
  • Loading branch information
nickmerwin committed Apr 21, 2020
1 parent 78f494c commit 198c793
Show file tree
Hide file tree
Showing 529 changed files with 8,514 additions and 7,603 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.DS_Store
.idea
coverage
47 changes: 31 additions & 16 deletions README.md
Expand Up @@ -16,7 +16,8 @@ The action's step needs to run after your test suite has outputted an LCOV file.
| --------------------- | ----------- | ----------- |
| `github-token` | _required_ | Must be in form `github-token: ${{ secrets.GITHUB_TOKEN }}`; Coveralls uses this token to verify the posted coverage data on the repo and create a new check based on the results. It is built into Github Actions and does not need to be manually specified in your secrets store. [More Info](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token)|
| `path-to-lcov` | _optional_ | Default: "./coverage/lcov.info". Local path to the lcov output file produced by your test suite. An error will be thrown if the file can't be found. This is the file that will be sent to the Coveralls API. |
| `parallel` | _optional_ | Set to true for parallel (or matrix) based steps, where multiple posts to Coveralls will be performed in the check. |
| `flag-name` | _optional (unique required if parallel)_ | Job flag name, e.g. "Unit", "Functional", or "Integration". Will be shown in the Coveralls UI. |
| `parallel` | _optional_ | Set to true for parallel (or matrix) based steps, where multiple posts to Coveralls will be performed in the check. `flag-name` needs to be set and unique, e.g. `flag-name: run-${{ matrix.test_number }}` |
| `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://<host>`; 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) |
Expand Down Expand Up @@ -67,35 +68,49 @@ on: ["push", "pull_request"]
name: Test Coveralls Parallel

jobs:

build:
name: Build
test:
runs-on: ubuntu-latest
strategy:
matrix:
test_number:
- 1
- 2
steps:

- uses: actions/checkout@v1

- uses: actions/checkout@master
- name: Use Node.js 10.x
uses: actions/setup-node@v1
uses: actions/setup-node@master
with:
node-version: 10.x
version: 10.x

- name: npm install, make test-coverage
run: |
npm install
make test-coverage
- name: npm install
run: npm install

- name: Test ${{ matrix.test_number }}
run: make test-coverage-${{ matrix.test_number }}
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.test_number }}
parallel: true
path-to-lcov: ./coverage/lcov.info # optional (default value)

finish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Use Node.js 10.x
uses: actions/setup-node@master
with:
version: 10.x

- name: npm install
run: npm install

- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.github_token }}
parallel-finished: true
```

Expand Down
15 changes: 5 additions & 10 deletions lib/run.js
Expand Up @@ -34,31 +34,26 @@ function run() {
process.env.COVERALLS_SERVICE_NAME = 'github';
process.env.COVERALLS_GIT_COMMIT = process.env.GITHUB_SHA.toString();
process.env.COVERALLS_GIT_BRANCH = process.env.GITHUB_REF.toString();
process.env.COVERALLS_FLAG_NAME = process.env.COVERALLS_FLAG_NAME || core.getInput('flag-name');
const event = fs_1.default.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8');
if (process.env.COVERALLS_DEBUG) {
console.log("Event Name: " + process.env.GITHUB_EVENT_NAME);
console.log(event);
}
const sha = process.env.GITHUB_SHA.toString();
let jobId;
if (process.env.GITHUB_EVENT_NAME == 'pull_request') {
const pr = JSON.parse(event).number;
process.env.CI_PULL_REQUEST = pr;
jobId = `${sha}-PR-${pr}`;
process.env.CI_PULL_REQUEST = JSON.parse(event).number;
}
else {
jobId = sha;
}
process.env.COVERALLS_SERVICE_JOB_ID = jobId;
const endpoint = core.getInput('coveralls-endpoint');
if (endpoint != '') {
process.env.COVERALLS_ENDPOINT = endpoint;
}
const runId = process.env.GITHUB_RUN_ID;
process.env.COVERALLS_SERVICE_JOB_ID = runId;
if (core.getInput('parallel-finished') != '') {
const payload = {
"repo_token": githubToken,
"repo_name": process.env.GITHUB_REPOSITORY,
"payload": { "build_num": jobId, "status": "done" }
"payload": { "build_num": runId, "status": "done" }
};
request_1.default.post({
url: `${process.env.COVERALLS_ENDPOINT || 'https://coveralls.io'}/webhook`,
Expand Down
2 changes: 2 additions & 0 deletions lib/run.spec.js
Expand Up @@ -24,6 +24,8 @@ describe('Run', () => {
const setup = () => {
getInput = sandbox.stub(core, 'getInput');
getInput.withArgs('github-token').returns('v1.asdf');
process.env.GITHUB_RUN_NUMBER = "1234";
process.env.GITHUB_RUN_ID = "1234567";
process.env.GITHUB_SHA = "asdfasdf";
process.env.GITHUB_REF = "master";
process.env.GITHUB_EVENT_NAME = "pull_request";
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/lcov-parse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 146 additions & 7 deletions node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 198c793

Please sign in to comment.