🥯🧯 ↝ [uzm1um]: Continuing a simplification plan #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Coverage Badges | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - "**" | |
| schedule: | |
| - cron: "0 5 * * *" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update_badges: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: "yarn" | |
| - name: Install dependencies | |
| run: | | |
| yarn lock:check | |
| yarn install --frozen-lockfile | |
| - name: Generate coverage badges | |
| run: | | |
| yarn test:unit --coverage | |
| node scripts/metrics/generate-coverage-badges.mjs | |
| - name: Commit badge updates | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| if git diff --quiet -- .github/badges; then | |
| echo "No badge updates" | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add .github/badges | |
| git commit -m "chore(metrics): update coverage badges" | |
| git push | |
| - name: Comment coverage on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const summary = JSON.parse(fs.readFileSync('.github/badges/metrics-summary.json', 'utf8')); | |
| const code = Number(summary?.codeCoverage?.percent ?? 0).toFixed(1); | |
| const sdd = Number(summary?.sddCoverage?.percent ?? 0).toFixed(1); | |
| const linked = summary?.sddCoverage?.linked ?? 0; | |
| const total = summary?.sddCoverage?.total ?? 0; | |
| const body = [ | |
| "## Coverage Report", | |
| "", | |
| `- Code Coverage: **${code}%**`, | |
| `- SDD Coverage: **${sdd}%** (${linked}/${total} linked tasks)`, | |
| "", | |
| "_Generated by `coverage-badges` workflow._" | |
| ].join("\\n"); | |
| const issue_number = context.issue.number; | |
| const { owner, repo } = context.repo; | |
| const marker = "<!-- coverage-badges-comment -->"; | |
| const markedBody = `${marker}\\n${body}`; | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner, | |
| repo, | |
| issue_number, | |
| per_page: 100 | |
| }); | |
| const existing = comments.find( | |
| (c) => c.user?.type === "Bot" && c.body?.includes(marker) | |
| ); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: existing.id, | |
| body: markedBody | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body: markedBody | |
| }); | |
| } |