Skip to content

Commit 8a1e7e7

Browse files
committed
chore: replace coverage badge with job summary and commit status
Remove the committed SVG badge in favor of a GitHub Actions job summary and commit status check, eliminating merge conflicts on PRs.
1 parent 36c42fa commit 8a1e7e7

6 files changed

Lines changed: 76 additions & 69 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: read
11+
statuses: write
1112

1213
jobs:
1314
check-pr-labels:
@@ -70,3 +71,23 @@ jobs:
7071

7172
- name: Check for clean working directory
7273
run: npm run check:clean
74+
75+
- name: Generate coverage summary
76+
id: coverage
77+
run: |
78+
COVERAGE=$(npx tsx src/scripts/coverage-summary.ts)
79+
echo "pct=$COVERAGE" >> "$GITHUB_OUTPUT"
80+
81+
- name: Set coverage status
82+
uses: actions/github-script@v7
83+
with:
84+
script: |
85+
const pct = '${{ steps.coverage.outputs.pct }}';
86+
await github.rest.repos.createCommitStatus({
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
sha: context.sha,
90+
state: 'success',
91+
description: `${pct}%`,
92+
context: 'Coverage',
93+
});

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
![CI](https://github.com/release-drafter/release-drafter/actions/workflows/ci.yml/badge.svg)
88
![CodeQL](https://github.com/release-drafter/release-drafter/actions/workflows/codeql-analysis.yml/badge.svg)
9-
![Coverage](./badges/coverage.svg)
109

1110
## Usage
1211

badges/coverage.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
"build": "vite build",
2828
"test": "vitest",
2929
"test:run": "vitest run",
30-
"coverage": "npx tsx src/scripts/generate-coverage-badge.ts",
30+
"coverage": "npx tsx src/scripts/coverage-summary.ts",
3131
"tsc:check": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
3232
"format:write": "biome format --write .",
3333
"format:check": "biome format .",
3434
"lint": "biome lint .",
3535
"check": "biome check --write .",
3636
"codegen": "graphql-codegen -c src/scripts/graphql.codegen-config.ts -v",
3737
"schemas": "npx tsx src/scripts/json-schema.ts",
38-
"all": "npm run check && npm run tsc:check && npm run test:run && npm run coverage && npm run schemas && npm run build",
38+
"all": "npm run check && npm run tsc:check && npm run test:run && npm run schemas && npm run build",
3939
"check:clean": "npx tsx src/scripts/check-clean.ts",
4040
"preversion": "npm run all && npm run check:clean",
4141
"version": "git add package.json package-lock.json",

src/scripts/coverage-summary.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { appendFileSync, readFileSync } from 'node:fs'
2+
import { resolve } from 'node:path'
3+
4+
type CoverageSummary = {
5+
total?: {
6+
statements?: { pct?: number; total?: number; covered?: number }
7+
branches?: { pct?: number; total?: number; covered?: number }
8+
functions?: { pct?: number; total?: number; covered?: number }
9+
lines?: { pct?: number; total?: number; covered?: number }
10+
}
11+
}
12+
13+
const coverageSummaryPath = resolve(
14+
import.meta.dirname,
15+
'../..',
16+
'coverage',
17+
'coverage-summary.json',
18+
)
19+
20+
const coverageSummaryContent = readFileSync(coverageSummaryPath, {
21+
encoding: 'utf-8',
22+
})
23+
const coverageSummary = JSON.parse(coverageSummaryContent) as CoverageSummary
24+
25+
const total = coverageSummary.total
26+
if (!total?.statements?.pct && total?.statements?.pct !== 0) {
27+
throw new Error('Unable to read coverage data from coverage-summary.json')
28+
}
29+
30+
const pct = total.statements.pct
31+
32+
// Print coverage percentage for CI to capture
33+
console.log(pct.toFixed(2))
34+
35+
// Write GitHub Actions job summary if running in CI
36+
const summaryFile = process.env.GITHUB_STEP_SUMMARY
37+
if (summaryFile) {
38+
const emoji = pct >= 90 ? '🟢' : pct >= 80 ? '🟡' : pct >= 70 ? '🟠' : '🔴'
39+
40+
const summary = [
41+
`## ${emoji} Code Coverage: ${pct.toFixed(2)}%`,
42+
'',
43+
'| Metric | Coverage | Covered | Total |',
44+
'| --- | --- | --- | --- |',
45+
`| Statements | ${total.statements.pct?.toFixed(2)}% | ${total.statements.covered} | ${total.statements.total} |`,
46+
`| Branches | ${total.branches?.pct?.toFixed(2)}% | ${total.branches?.covered} | ${total.branches?.total} |`,
47+
`| Functions | ${total.functions?.pct?.toFixed(2)}% | ${total.functions?.covered} | ${total.functions?.total} |`,
48+
`| Lines | ${total.lines?.pct?.toFixed(2)}% | ${total.lines?.covered} | ${total.lines?.total} |`,
49+
'',
50+
].join('\n')
51+
52+
appendFileSync(summaryFile, summary)
53+
}

src/scripts/generate-coverage-badge.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)