Skip to content

Feature/pr code coverage #1939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/report_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Report Coverage

on:
workflow_run:
workflows: [Upload Coverage]
types: [completed]

jobs:
report:
runs-on: ubuntu-latest

permissions:
pull-requests: write

steps:
- uses: actions/checkout@v4

- name: Download Coverage Artifact
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/[email protected]
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
54 changes: 54 additions & 0 deletions .github/workflows/upload_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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: vitest-coverage
path: vitest-coverage
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ out

# Autogenerated static files
public/sitemap.xml

# nektosact github actions env for testing
.secrets
2 changes: 2 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default defineConfig({
},
},
coverage: {
reporter: ['text', 'json-summary', 'json'],
reportOnFailure: true,
reportsDirectory: './vitest-coverage',
include: [
'common/**/*.{js,ts,tsx}',
Expand Down
Loading