From 279029faea5d476e7dbc2e81a7c6200f6b2947ce Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Thu, 28 May 2020 09:47:09 -0400 Subject: [PATCH 1/2] chore: CI workflow to only upload report if CODACY_PROJECT_TOKEN is set 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: https://github.com/cloudevents/sdk-javascript/issues/190 Signed-off-by: Lance Ball --- .../workflows/codacy-coverage-reporter.yml | 22 ---------- .github/workflows/nodejs-ci-action.yml | 42 +++++++++++++++++-- package.json | 1 - 3 files changed, 39 insertions(+), 26 deletions(-) delete mode 100644 .github/workflows/codacy-coverage-reporter.yml diff --git a/.github/workflows/codacy-coverage-reporter.yml b/.github/workflows/codacy-coverage-reporter.yml deleted file mode 100644 index 248fc411..00000000 --- a/.github/workflows/codacy-coverage-reporter.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Code Coverage - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Use Node.js 12.x - uses: actions/setup-node@v1 - with: - node-version: 12.x - - run: npm ci - - run: npm run build --if-present - - run: npm run coverage-publish - env: - CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}} diff --git a/.github/workflows/nodejs-ci-action.yml b/.github/workflows/nodejs-ci-action.yml index e772a1cd..4418daeb 100644 --- a/.github/workflows/nodejs-ci-action.yml +++ b/.github/workflows/nodejs-ci-action.yml @@ -11,19 +11,55 @@ on: jobs: build: - + name: Build and test runs-on: ubuntu-latest - strategy: matrix: node-version: [10.x, 12.x] steps: - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} + - name: Test on Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm run build --if-present - run: npm test + + coverage: + name: Code coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Generate coverage report + uses: actions/setup-node@v1 + with: + node-version: 12.x + - run: npm ci + - run: npm run build --if-present + - run: npm run coverage + - name: Upload coverage report to storage + uses: actions/upload-artifact@v1 + with: + name: coverage + path: coverage/lcov.info + + publish: + name: Publish code coverage report + needs: coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Download coverage report from storage + uses: actions/download-artifact@v1 + with: + name: coverage + - name: Upload coverage report to codacy + uses: actions/setup-node@v1 + with: + node-version: 12.x + - run: | + [[ "${CODACY_PROJECT_TOKEN}" != "" ]] && npm run coverage-publish + env: + CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}} diff --git a/package.json b/package.json index bc572aae..9f77a2c2 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "pretest": "npm run lint", "test": "mocha test/**/*.js", "coverage": "nyc --reporter=lcov --reporter=text npm run test", - "precoverage-publish": "npm run coverage", "coverage-publish": "wget -qO - https://coverage.codacy.com/get.sh | bash -s report -l JavaScript -r coverage/lcov.info", "generate-docs": "jsdoc --configure .jsdoc.json --verbose", "release": "standard-version" From 2a9f42fc6737557fe30f9b165597ba9dacb405b7 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Thu, 28 May 2020 10:10:29 -0400 Subject: [PATCH 2/2] fixup: return success even if report is not published Signed-off-by: Lance Ball --- .github/workflows/nodejs-ci-action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nodejs-ci-action.yml b/.github/workflows/nodejs-ci-action.yml index 4418daeb..c1de8925 100644 --- a/.github/workflows/nodejs-ci-action.yml +++ b/.github/workflows/nodejs-ci-action.yml @@ -60,6 +60,6 @@ jobs: with: node-version: 12.x - run: | - [[ "${CODACY_PROJECT_TOKEN}" != "" ]] && npm run coverage-publish + ( [[ "${CODACY_PROJECT_TOKEN}" != "" ]] && npm run coverage-publish ) || echo "Coverage report not published" env: CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}