Skip to content

Commit aa320e7

Browse files
authored
chore: CI workflow to only upload report if CODACY_PROJECT_TOKEN is set (cloudevents#193)
GitHub will not set secrets in the environment when a pull request is submitted from a forked repository. This commit modifies the CI workflow to only send the report when the API token has been set. It also consolidates the two workflows into a single one which shares coverage data between jobs. Fixes: cloudevents#190 Signed-off-by: Lance Ball <[email protected]>
1 parent 0710166 commit aa320e7

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

.github/workflows/codacy-coverage-reporter.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/nodejs-ci-action.yml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,55 @@ on:
1111

1212
jobs:
1313
build:
14-
14+
name: Build and test
1515
runs-on: ubuntu-latest
16-
1716
strategy:
1817
matrix:
1918
node-version: [10.x, 12.x]
2019

2120
steps:
2221
- uses: actions/checkout@v2
23-
- name: Use Node.js ${{ matrix.node-version }}
22+
- name: Test on Node.js ${{ matrix.node-version }}
2423
uses: actions/setup-node@v1
2524
with:
2625
node-version: ${{ matrix.node-version }}
2726
- run: npm ci
2827
- run: npm run build --if-present
2928
- run: npm test
29+
30+
coverage:
31+
name: Code coverage
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v2
35+
- name: Generate coverage report
36+
uses: actions/setup-node@v1
37+
with:
38+
node-version: 12.x
39+
- run: npm ci
40+
- run: npm run build --if-present
41+
- run: npm run coverage
42+
- name: Upload coverage report to storage
43+
uses: actions/upload-artifact@v1
44+
with:
45+
name: coverage
46+
path: coverage/lcov.info
47+
48+
publish:
49+
name: Publish code coverage report
50+
needs: coverage
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v2
54+
- name: Download coverage report from storage
55+
uses: actions/download-artifact@v1
56+
with:
57+
name: coverage
58+
- name: Upload coverage report to codacy
59+
uses: actions/setup-node@v1
60+
with:
61+
node-version: 12.x
62+
- run: |
63+
( [[ "${CODACY_PROJECT_TOKEN}" != "" ]] && npm run coverage-publish ) || echo "Coverage report not published"
64+
env:
65+
CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"pretest": "npm run lint",
1212
"test": "mocha test/**/*.js",
1313
"coverage": "nyc --reporter=lcov --reporter=text npm run test",
14-
"precoverage-publish": "npm run coverage",
1514
"coverage-publish": "wget -qO - https://coverage.codacy.com/get.sh | bash -s report -l JavaScript -r coverage/lcov.info",
1615
"generate-docs": "jsdoc --configure .jsdoc.json --verbose",
1716
"release": "standard-version"

0 commit comments

Comments
 (0)