diff --git a/.github/workflows/report_coverage.yml b/.github/workflows/report_coverage.yml new file mode 100644 index 000000000..0c8adf775 --- /dev/null +++ b/.github/workflows/report_coverage.yml @@ -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/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..43f778b46 --- /dev/null +++ b/.github/workflows/upload_coverage.yml @@ -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 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}',