From eded17adc06fe8414b7ea0732dd5cac2cd00f7e2 Mon Sep 17 00:00:00 2001 From: Nicholas Griffin Date: Mon, 6 May 2024 17:55:52 +0100 Subject: [PATCH] chore: enhance ci reports (#497) --- .github/workflows/annotate-test-reports.yml | 31 +++++++++++++++ .github/workflows/pr-coverage.yml | 42 +++++++++++++++++++++ .github/workflows/test.yml | 4 +- package.json | 2 +- test/config/cucumber.mjs | 6 +-- 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/annotate-test-reports.yml create mode 100644 .github/workflows/pr-coverage.yml diff --git a/.github/workflows/annotate-test-reports.yml b/.github/workflows/annotate-test-reports.yml new file mode 100644 index 0000000..dae5736 --- /dev/null +++ b/.github/workflows/annotate-test-reports.yml @@ -0,0 +1,31 @@ +name: Annotate CI run with test results +on: + workflow_run: + workflows: + - "Run Tests" + types: + - completed +permissions: + actions: read + contents: read + checks: write + pull-requests: write + +jobs: + annotate: + name: Annotate CI run with test results + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion != 'cancelled' }} + strategy: + fail-fast: false + matrix: + node-version: [18.x, 20.x, 22.x] + timeout-minutes: 5 + steps: + - name: Annotate CI run with test results + uses: dorny/test-reporter@v1.8.0 + with: + artifact: test-reports-${{ matrix.node-version }} + name: Test Results (${{matrix.node-version}} + path: "test-results.json" + reporter: mocha-json \ No newline at end of file diff --git a/.github/workflows/pr-coverage.yml b/.github/workflows/pr-coverage.yml new file mode 100644 index 0000000..2e0b858 --- /dev/null +++ b/.github/workflows/pr-coverage.yml @@ -0,0 +1,42 @@ +name: Comment PR Coverage +on: + pull_request: + branches: + - 'main' +permissions: + contents: read + pull-requests: write + +jobs: + coverage_report: + name: Generate coverage report + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20.x] + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + + - name: Install Node Modules + run: npm ci + + - name: Run Coverage Check + run: npm run lcov + + - name: Setup LCOV + uses: hrishikesh-kadam/setup-lcov@v1 + + - name: Report code coverage + uses: zgosalvez/github-actions-report-lcov@v3 + with: + coverage-files: coverage/lcov.info + minimum-coverage: 90 + artifact-name: code-coverage-report + github-token: ${{ secrets.GITHUB_TOKEN }} + update-comment: true \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2a776e..f9565d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,8 @@ on: - main permissions: contents: read + checks: write + pull-requests: write jobs: build: @@ -34,7 +36,7 @@ jobs: - name: Run Tests and Linting run: npm run test - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: test-reports-${{ matrix.node-version }} path: test/reports/ diff --git a/package.json b/package.json index c59ed34..c7a6718 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build": "npm run clean && npm run compile && npm run add-package-jsons", "watch": "tsc --watch", "prepublishOnly": "npm run build", - "test:unit": "mocha --recursive --full-trace --exit", + "test:unit": "mocha --recursive --full-trace --exit --reporter json > test/reports/test-results.json", "pretest:integration:init": "npm run build", "test:integration:init": "sh ./test/scripts/initIntTests.sh", "test:integration": "npm run test:integration:init && cucumber-js --config ./test/config/cucumber.mjs", diff --git a/test/config/cucumber.mjs b/test/config/cucumber.mjs index b160c04..6f3704e 100644 --- a/test/config/cucumber.mjs +++ b/test/config/cucumber.mjs @@ -1,6 +1,6 @@ export default { parallel: 0, - format: ['html:test/reports/cucumber-report.html'], - paths: ['test/features'], - forceExit: true + format: ["json:test/reports/cucumber-report.json"], + paths: ["test/features"], + forceExit: true, };