|
| 1 | +name: Coverage Report |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +jobs: |
| 7 | + report: |
| 8 | + name: Report |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v6 |
| 16 | + |
| 17 | + - name: Download coverage artifact |
| 18 | + uses: actions/download-artifact@v7 |
| 19 | + with: |
| 20 | + name: coverage |
| 21 | + path: coverage/ |
| 22 | + |
| 23 | + # On push to main, deploy HTML coverage report to GitHub Pages |
| 24 | + - name: Deploy coverage to GitHub Pages |
| 25 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 26 | + uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e |
| 27 | + with: |
| 28 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + publish_dir: ./coverage |
| 30 | + destination_dir: coverage |
| 31 | + |
| 32 | + # On PRs, fetch baseline coverage from GitHub Pages |
| 33 | + - name: Fetch baseline coverage from GitHub Pages |
| 34 | + if: github.event_name == 'pull_request' |
| 35 | + run: | |
| 36 | + mkdir -p coverage-base |
| 37 | + curl -fsSL https://metamask.github.io/ocap-kernel/coverage/coverage-summary.json \ |
| 38 | + -o coverage-base/coverage-summary.json || { echo "No baseline coverage found"; exit 1; } |
| 39 | +
|
| 40 | + - name: Post coverage report |
| 41 | + if: github.event_name == 'pull_request' |
| 42 | + uses: davelosert/vitest-coverage-report-action@5b6122e3a819a3be7b27fc961b7faafb3bf00e4d |
| 43 | + with: |
| 44 | + json-summary-path: coverage/coverage-summary.json |
| 45 | + json-final-path: coverage/coverage-final.json |
| 46 | + json-summary-compare-path: coverage-base/coverage-summary.json |
| 47 | + file-coverage-mode: changes |
| 48 | + |
| 49 | + - name: Post coverage report link |
| 50 | + if: github.event_name == 'pull_request' |
| 51 | + uses: actions/github-script@v8 |
| 52 | + with: |
| 53 | + script: | |
| 54 | + const marker = '<!-- coverage-report-link -->'; |
| 55 | + const body = `${marker}\n📊 [View full HTML coverage report for \`main\`](https://metamask.github.io/ocap-kernel/coverage/)`; |
| 56 | +
|
| 57 | + const { data: comments } = await github.rest.issues.listComments({ |
| 58 | + issue_number: context.issue.number, |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + }); |
| 62 | +
|
| 63 | + const existing = comments.find(c => c.body?.includes(marker)); |
| 64 | +
|
| 65 | + if (existing) { |
| 66 | + await github.rest.issues.updateComment({ |
| 67 | + comment_id: existing.id, |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + body, |
| 71 | + }); |
| 72 | + } else { |
| 73 | + await github.rest.issues.createComment({ |
| 74 | + issue_number: context.issue.number, |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + body, |
| 78 | + }); |
| 79 | + } |
0 commit comments