Skip to content

Commit

Permalink
docs: publish test coverage (#1113)
Browse files Browse the repository at this point in the history

---------

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Oct 16, 2023
1 parent f72cbd3 commit cbabc7e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
40 changes: 36 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ concurrency:
cancel-in-progress: true

env:
DIST_DIR: dist
REPORTS_DIR: reports
NODE_ACTIVE_LTS: '20' # https://nodejs.org/en/about/releases/
DIST_DIR: dist
REPORTS_DIR: "CI_reports"
TESTS_REPORTS_ARTIFACT: tests-reports

jobs:
build:
Expand Down Expand Up @@ -48,6 +49,7 @@ jobs:
name: ${{ env.DIST_DIR }}
path: ${{ env.DIST_DIR }}
if-no-files-found: error

test-standards:
name: test standards
timeout-minutes: 30
Expand All @@ -66,6 +68,7 @@ jobs:
run: npm i --loglevel=silly
- name: run tests
run: npm run test:standard

test-jest:
needs: [ 'build' ]
name: jest (node${{ matrix.node-version }} ${{ matrix.os }})
Expand Down Expand Up @@ -118,6 +121,10 @@ jobs:
--verbose
--runInBand
--logHeapUsage
--coverage
--coverageDirectory='${{ env.REPORTS_DIR }}/node${{ matrix.node-version }}_${{ matrix.os }}/coverage'
env:
JEST_JUNIT_OUTPUT_DIR: ${{ env.REPORTS_DIR }}/node${{ matrix.node-version }}_${{ matrix.os }}
- name: artifact test logs
if: ${{ failure() }}
# see https://github.com/actions/upload-artifact
Expand All @@ -127,13 +134,14 @@ jobs:
path: tests/_log
if-no-files-found: error
- name: artifact test reports
if: ${{ failure() }}
if: ${{ ! cancelled() }}
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v3
with:
name: reports-jest_node${{ matrix.node-version }}-${{ matrix.os }}
name: ${{ env.TESTS_REPORTS_ARTIFACT }}
path: ${{ env.REPORTS_DIR }}
if-no-files-found: error

dogfooding:
needs: [ 'build' ]
name: dogfooding npm ${{ matrix.npm-version }}
Expand Down Expand Up @@ -204,3 +212,27 @@ jobs:
name: dogfooding-direct_npm${{ matrix.npm-version }}
path: ${{ env.REPORTS_DIR }}
if-no-files-found: error

report-coverage:
name: Publish test coverage
needs:
- test-jest
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: fetch test artifacts
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.TESTS_REPORTS_ARTIFACT }}
path: ${{ env.REPORTS_DIR }}
- name: Run codacy-coverage-reporter
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
if: ${{ env.CODACY_PROJECT_TOKEN != '' }} ## see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-secrets
# see https://github.com/codacy/codacy-coverage-reporter-action
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ env.CODACY_PROJECT_TOKEN }}
coverage-reports: ${{ env.REPORTS_DIR }}/*/coverage/clover.xml

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![shield_npm-version]][link_npm]
[![shield_gh-workflow-test]][link_gh-workflow-test]
[![shield_coverage]][link_codacy]
[![shield_ossf-best-practices]][link_ossf-best-practices]
[![shield_license]][license_file]
[![shield_website]][link_website]
Expand Down Expand Up @@ -154,7 +155,7 @@ See the [LICENSE][license_file] file for the full license.
[shield_gh-workflow-test]: https://img.shields.io/github/actions/workflow/status/CycloneDX/cyclonedx-node-npm/nodejs.yml?branch=main&logo=GitHub&logoColor=white "tests"
[shield_ossf-best-practices]: https://img.shields.io/cii/level/6614?label=OpenSSF%20best%20practices "OpenSSF best practices"
[shield_coverage]: https://img.shields.io/codacy/coverage/16b034e5463543008e1cc0e2a3ed7005?logo=Codacy&logoColor=white "test coverage"
[shield_npm-version]: https://img.shields.io/npm/v/@cyclonedx/cyclonedx-npm?logo=npm&logoColor=white "npm"
[shield_license]: https://img.shields.io/github/license/CycloneDX/cyclonedx-node-npm?logo=open%20source%20initiative&logoColor=white "license"
[shield_website]: https://img.shields.io/badge/https://-cyclonedx.org-blue.svg "homepage"
Expand All @@ -164,6 +165,7 @@ See the [LICENSE][license_file] file for the full license.
[link_website]: https://cyclonedx.org/
[link_gh-workflow-test]: https://github.com/CycloneDX/cyclonedx-node-npm/actions/workflows/nodejs.yml?query=branch%3Amain
[link_codacy]: https://app.codacy.com/gh/CycloneDX/cyclonedx-node-npm/dashboard
[link_ossf-best-practices]: https://www.bestpractices.dev/projects/6614
[link_npm]: https://www.npmjs.com/package/@cyclonedx/cyclonedx-npm
[link_slack]: https://cyclonedx.org/slack/invite
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: [
'src/**',
'dist/**'
'dist/**' // running tests on build results, so need to have this vector
],

// The directory where Jest should output its coverage files
Expand All @@ -54,7 +54,7 @@ module.exports = {
],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',
coverageProvider: 'babel', // we use compiled data with a map - we need to use babel here.

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
Expand Down

0 comments on commit cbabc7e

Please sign in to comment.