From ab66c1592678e9a560d70267da16481c71c24f5b Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sat, 23 Nov 2024 08:20:49 -0800 Subject: [PATCH 1/2] ci: c8 report all files in {src,tools} --- .github/workflows/after-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/after-merge.yml b/.github/workflows/after-merge.yml index 1c8747d8cee..de7c8a2d717 100644 --- a/.github/workflows/after-merge.yml +++ b/.github/workflows/after-merge.yml @@ -108,7 +108,7 @@ jobs: - name: generate coverage for all tests run: 'yarn test:c8-all || :' - name: generate coverage/html reports - run: mkdir -p coverage/tmp && yarn c8 report --reporter=html-spa --reports-dir=coverage/html --temp-directory=coverage/tmp + run: mkdir -p coverage/tmp && yarn c8 report --all --include 'packages/*/{src,tools}' --reporter=html-spa --reports-dir=coverage/html --temp-directory=coverage/tmp - uses: actions/upload-artifact@v4 with: name: coverage From 476f7a5111ea6d4635d312421cfc5d0db80bb81e Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sat, 23 Nov 2024 08:34:15 -0800 Subject: [PATCH 2/2] refactor: single script for CI code coverage --- .github/workflows/after-merge.yml | 6 ++---- COVERAGE.md | 5 +---- package.json | 1 - scripts/ci/generate-test-coverage-report.sh | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100755 scripts/ci/generate-test-coverage-report.sh diff --git a/.github/workflows/after-merge.yml b/.github/workflows/after-merge.yml index de7c8a2d717..50088971d23 100644 --- a/.github/workflows/after-merge.yml +++ b/.github/workflows/after-merge.yml @@ -105,10 +105,8 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: generate coverage for all tests - run: 'yarn test:c8-all || :' - - name: generate coverage/html reports - run: mkdir -p coverage/tmp && yarn c8 report --all --include 'packages/*/{src,tools}' --reporter=html-spa --reports-dir=coverage/html --temp-directory=coverage/tmp + - name: generate test coverage report + run: ./scripts/ci/generage-test-coverage-report.sh - uses: actions/upload-artifact@v4 with: name: coverage diff --git a/COVERAGE.md b/COVERAGE.md index 13ea60f18d5..3dcda91d4ed 100644 --- a/COVERAGE.md +++ b/COVERAGE.md @@ -12,10 +12,7 @@ source-to-source transforms (such as `@endo/bundle-source`, Coverage reports for the current main branch are published by CI to: https://agoric-sdk-coverage.netlify.app -It's made by a CI job calling `test:c8-all` in the project root. That in turn -calls `test:c8` in each package, with `$C8_OPTIONS` set to a common coverage -directory and to leave temp files so they can accumulate. The job then uses that -output in another call to c8 to generate a report. +See `scripts/ci/generate-test-coverage-report.sh` ## Per package You can create a report in any package: diff --git a/package.json b/package.json index 0c1f8ff3799..9a4ad3db134 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,6 @@ "lint": "run-s --continue-on-error lint:*", "lint:packages": "yarn lerna run --no-bail lint", "test": "yarn lerna run --no-bail test", - "test:c8-all": "rm -rf coverage/tmp && C8_OPTIONS=\"--clean=false --temp-directory=$PWD/coverage/tmp\" lerna run test:c8", "test:xs": "yarn workspaces run test:xs", "build": "yarn workspaces run build && scripts/agd-builder.sh stamp yarn-built", "postinstall": "patch-package && scripts/agd-builder.sh stamp yarn-installed", diff --git a/scripts/ci/generate-test-coverage-report.sh b/scripts/ci/generate-test-coverage-report.sh new file mode 100755 index 00000000000..032bfd86839 --- /dev/null +++ b/scripts/ci/generate-test-coverage-report.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# CI artifact export expects the files to be under `coverage` (same for /html below) +export NODE_V8_COVERAGE="$PWD/coverage/tmp" + +# clear out old coverage. c8 usually does this but we have to clean=false below so it accumulates across packages +rm -rf "$NODE_V8_COVERAGE" +mkdir -p "$NODE_V8_COVERAGE" + +# the package test:c8 commands will include this +export C8_OPTIONS="--clean=false" + +# XXX uses lerna when `yarn workspaces run` should work, but in v1 it always bails on missing script +yarn lerna run test:c8 + +# report over all src and tools files, not just the ones that were loaded during tests +yarn c8 report --all --include 'packages/*/{src,tools}' --reporter=html-spa --reports-dir=coverage/html