Skip to content

Commit ea6469c

Browse files
Add dynamic coverage badge from main branch (#19)
Update CI to extract coverage % on main pushes and store an \�ndpoint.json\ on a \coverage-data\ branch (same pattern as [Presidio](https://github.com/microsoft/presidio)). Update README badge to use shields.io endpoint pointing to that branch. ### Changes - **ci.yml**: Added 'Update coverage badge' step that runs on push to main, extracts line coverage from \coverage-summary.json\, generates a shields.io-compatible \�ndpoint.json\ with color coding, and pushes it to the \coverage-data\ branch - **README.md**: Updated coverage badge to use \shields.io/endpoint\ reading from the \coverage-data\ branch ### Notes - No external services or secrets needed — uses the built-in \GITHUB_TOKEN\ - \contents: write\ permission scoped only to the coverage job - Badge color ranges: red (<45%) → yellow → yellowgreen → green → brightgreen (≥90%) --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b121690 commit ea6469c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ jobs:
5656
elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then COLOR="yellowgreen"
5757
elif (( $(echo "$COVERAGE >= 45" | bc -l) )); then COLOR="yellow"
5858
else COLOR="red"; fi
59-
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${COVERAGE}%\",\"color\":\"${COLOR}\"}" > endpoint.json
59+
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${COVERAGE}%\",\"color\":\"${COLOR}\"}" > /tmp/endpoint.json
6060
git config user.name "github-actions[bot]"
6161
git config user.email "github-actions[bot]@users.noreply.github.com"
62-
git fetch origin coverage-data:coverage-data 2>/dev/null || git checkout --orphan coverage-data
63-
git checkout coverage-data
62+
if git fetch origin coverage-data 2>/dev/null; then
63+
git checkout coverage-data
64+
else
65+
git checkout --orphan coverage-data
66+
git rm -rf . 2>/dev/null || true
67+
fi
68+
cp /tmp/endpoint.json endpoint.json
6469
git add endpoint.json
6570
git commit -m "Update coverage badge to ${COVERAGE}%" || true
6671
git push origin coverage-data

0 commit comments

Comments
 (0)