From b3e9ec0da576591c800cc12d30dd261c9019a009 Mon Sep 17 00:00:00 2001 From: Rohan Bansal Date: Mon, 24 Feb 2025 15:39:26 +0530 Subject: [PATCH] ci: add test coverage indicator ci: split test and coverage workflows --- .github/workflows/coverage.yml | 120 +++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 11 +-- aform/package.json | 3 +- atable/package.json | 3 +- beam/package.json | 3 +- 5 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..299b06d4 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,120 @@ +name: Coverage + +on: [pull_request] + +jobs: + changes: + name: Check for changes + runs-on: ubuntu-latest + + permissions: + pull-requests: read + + outputs: + packages: ${{ steps.filter.outputs.changes }} + + steps: + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + aform: aform/** + atable: atable/** + beam: beam/** + + coverage: + name: ${{ matrix.package }} (${{ matrix.branch }}) + needs: changes + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + package: ${{ fromJSON(needs.changes.outputs.packages) }} + branch: + - ${{ github.event.pull_request.base.ref }} + - ${{ github.event.pull_request.head.ref }} + include: + - branch: ${{ github.event.pull_request.base.ref }} + artifact: development + - branch: ${{ github.event.pull_request.head.ref }} + artifact: pull-request + + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ matrix.branch }} + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache-dependency-path: '**/config/rush/pnpm-lock.yaml' + registry-url: https://registry.npmjs.org/ + + - name: Rush Install + run: node common/scripts/install-run-rush.js install + + - name: Rush Build + run: node common/scripts/install-run-rush.js rebuild --verbose + + - name: Run Tests + working-directory: ./${{ matrix.package }} + run: node ../common/scripts/install-run-rushx.js test:coverage + + - name: Upload Coverage + if: always() # upload the coverage report even if tests are failing + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.package }}-${{ matrix.artifact }} + path: ./${{ matrix.package }}/coverage + + report: + name: ${{ matrix.package }} report + needs: [changes, coverage] + runs-on: ubuntu-latest + if: always() # run the coverage report even if tests are failing + + strategy: + matrix: + package: ${{ fromJSON(needs.changes.outputs.packages) }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache-dependency-path: '**/config/rush/pnpm-lock.yaml' + registry-url: https://registry.npmjs.org/ + + - name: Rush Install + run: node common/scripts/install-run-rush.js install + + - name: Download PR Branch Coverage + uses: actions/download-artifact@v4 + with: + name: coverage-${{ matrix.package }}-pull-request + path: ${{ matrix.package }}/coverage + + - name: Download Base Branch Coverage + uses: actions/download-artifact@v4 + with: + name: coverage-${{ matrix.package }}-development + path: ${{ matrix.package }}/coverage-base + + - name: Report Coverage + uses: davelosert/vitest-coverage-report-action@v2 + with: + working-directory: ${{ matrix.package }} + file-coverage-mode: 'all' + vite-config-path: 'vite.config.ts' + json-summary-compare-path: coverage-base/coverage-summary.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7a8d8b86..050016b3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,6 +31,7 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: package: ${{ fromJSON(needs.changes.outputs.packages) }} @@ -53,12 +54,4 @@ jobs: - name: Run Tests working-directory: ./${{ matrix.package }} - run: node ../common/scripts/install-run-rushx.js test:coverage - - - name: Coverage Report - if: always() # generate the coverage report even if tests are failing - uses: davelosert/vitest-coverage-report-action@v2 - with: - working-directory: ./${{ matrix.package }} - file-coverage-mode: 'all' - vite-config-path: './vite.config.ts' + run: node ../common/scripts/install-run-rushx.js test diff --git a/aform/package.json b/aform/package.json index 052b58d5..566d9896 100644 --- a/aform/package.json +++ b/aform/package.json @@ -37,7 +37,8 @@ "docs": "api-documenter markdown -i temp -o ../docs/aform", "lint": "eslint . --ext .ts,.vue", "preview": "vite preview", - "test": "vitest", + "test": "vitest run --coverage.enabled false", + "test:watch": "vitest watch", "test:coverage": "vitest run --coverage", "test:ui": "vitest --ui" }, diff --git a/atable/package.json b/atable/package.json index b22a5d08..25d39f39 100644 --- a/atable/package.json +++ b/atable/package.json @@ -40,7 +40,8 @@ "docs": "api-documenter markdown -i temp -o ../docs/atable", "lint": "eslint . --ext .ts,.vue", "preview": "vite preview", - "test": "vitest", + "test": "vitest run --coverage.enabled false", + "test:watch": "vitest watch", "test:coverage": "vitest run --coverage", "test:ui": "vitest --ui" }, diff --git a/beam/package.json b/beam/package.json index f0b3e252..14ffd3d2 100644 --- a/beam/package.json +++ b/beam/package.json @@ -35,7 +35,8 @@ "docs": "api-documenter markdown -i temp -o ../docs/beam", "lint": "eslint . --ext .ts,.vue", "preview": "vite preview", - "test": "vitest", + "test": "vitest run --coverage.enabled false", + "test:watch": "vitest watch", "test:coverage": "vitest run --coverage", "test:ui": "vitest --ui" },