From 544c7d4bf42135ca30cded8911d1f9b2fe06e2b8 Mon Sep 17 00:00:00 2001 From: Billy Le Date: Thu, 14 Aug 2025 10:05:32 -0500 Subject: [PATCH 1/4] add workflow actions --- .github/workflows/code_coverage.yml | 38 +++++++++++++++++++ .github/workflows/upload_coverage.yml | 53 +++++++++++++++++++++++++++ .gitignore | 3 ++ vitest.config.mts | 2 + 4 files changed, 96 insertions(+) create mode 100644 .github/workflows/code_coverage.yml create mode 100644 .github/workflows/upload_coverage.yml diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml new file mode 100644 index 000000000..7c6bc2cf2 --- /dev/null +++ b/.github/workflows/code_coverage.yml @@ -0,0 +1,38 @@ +name: Report Coverage +on: + workflow_run: + workflows: ["Upload Coverage"] +jobs: + report: + runs-on: ubuntu-latest + + permissions: + pull-requests: write + + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Get PR number + id: PR + uses: 8BitJonny/gh-get-current-pr@3.0.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + sha: ${{ github.event.workflow_run.head_sha }} + filterOutClosed: true + filterOutDraft: true + + - name: Report Coverage + if: success() && steps.PR.outputs.number + uses: davelosert/vitest-coverage-report-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + json-summary-path: vitest-coverage/coverage-summary.json + json-final-path: vitest-coverage/coverage-final.json + pr-number: ${{ steps.PR.outputs.number }} + file-coverage-mode: changes + comment-on: pr diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml new file mode 100644 index 000000000..7d1b5ced3 --- /dev/null +++ b/.github/workflows/upload_coverage.yml @@ -0,0 +1,53 @@ +name: "Upload Coverage" +on: + pull_request: + branches: [main] + +jobs: + coverage: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + + - name: Read .nvmrc + run: echo ::set-output name=NVMRC::$(cat .nvmrc) + id: nvm + + - name: Use Node + uses: actions/setup-node@v4 + with: + always-auth: true + registry-url: https://registry.npmjs.org + node-version: '${{ steps.nvm.outputs.NVMRC }}' + + - name: Enable Yarn + run: corepack enable + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Use cached node_modules + uses: actions/cache@v4 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: yarn install --frozen-lockfile --non-interactive + + - name: 'Test' + run: npx vitest --coverage.enabled true + + - name: "Upload Coverage" + uses: actions/upload-artifact@v4 + with: + name: coverage + path: coverage diff --git a/.gitignore b/.gitignore index cabcf4ad8..51fe8cfa4 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,6 @@ out # Autogenerated static files public/sitemap.xml + +# nektosact github actions env for testing +.secrets diff --git a/vitest.config.mts b/vitest.config.mts index 6c9a8f58a..771a2df19 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -28,6 +28,8 @@ export default defineConfig({ }, }, coverage: { + reporter: ['text', 'json-summary', 'json'], + reportOnFailure: true, reportsDirectory: './vitest-coverage', include: [ 'common/**/*.{js,ts,tsx}', From 97353c1086951fa744a4e5fb2dd0cc028fc88d06 Mon Sep 17 00:00:00 2001 From: Billy Le Date: Thu, 14 Aug 2025 10:11:17 -0500 Subject: [PATCH 2/4] fix coverage path --- .github/workflows/upload_coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index 7d1b5ced3..efd883937 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -49,5 +49,5 @@ jobs: - name: "Upload Coverage" uses: actions/upload-artifact@v4 with: - name: coverage - path: coverage + name: vitest-coverage + path: vitest-coverage From 37b4ce50c92567eee9c88bb47950287cfdbd2dd3 Mon Sep 17 00:00:00 2001 From: Billy Le Date: Thu, 14 Aug 2025 10:16:04 -0500 Subject: [PATCH 3/4] renaming --- .github/workflows/{code_coverage.yml => report_coverage.yml} | 4 ++++ .github/workflows/upload_coverage.yml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) rename .github/workflows/{code_coverage.yml => report_coverage.yml} (97%) diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/report_coverage.yml similarity index 97% rename from .github/workflows/code_coverage.yml rename to .github/workflows/report_coverage.yml index 7c6bc2cf2..b5786cd4e 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/report_coverage.yml @@ -1,7 +1,11 @@ name: Report Coverage + on: workflow_run: workflows: ["Upload Coverage"] + types: + - completed + jobs: report: runs-on: ubuntu-latest diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index efd883937..a2e609aec 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -1,4 +1,4 @@ -name: "Upload Coverage" +name: Upload Coverage on: pull_request: branches: [main] From 023b0ea4e254c3166e87e75776552652fa1fbbcc Mon Sep 17 00:00:00 2001 From: Billy Le Date: Thu, 14 Aug 2025 10:32:55 -0500 Subject: [PATCH 4/4] test changes --- .github/workflows/report_coverage.yml | 8 ++++---- .github/workflows/upload_coverage.yml | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/report_coverage.yml b/.github/workflows/report_coverage.yml index b5786cd4e..0c8adf775 100644 --- a/.github/workflows/report_coverage.yml +++ b/.github/workflows/report_coverage.yml @@ -2,9 +2,8 @@ name: Report Coverage on: workflow_run: - workflows: ["Upload Coverage"] - types: - - completed + workflows: [Upload Coverage] + types: [completed] jobs: report: @@ -16,7 +15,8 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 + - name: Download Coverage Artifact + uses: actions/download-artifact@v4 with: github-token: ${{ secrets.GITHUB_TOKEN }} run-id: ${{ github.event.workflow_run.id }} diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index a2e609aec..43f778b46 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -1,4 +1,5 @@ name: Upload Coverage + on: pull_request: branches: [main]