Skip to content

Commit b121690

Browse files
Add dynamic coverage badge from main branch (#18)
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 6a50a5e commit b121690

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
coverage:
3030
name: Coverage
3131
runs-on: ubuntu-latest
32+
permissions:
33+
contents: write
34+
pull-requests: write
3235
steps:
3336
- uses: actions/checkout@v6
3437
- uses: actions/setup-node@v6
@@ -44,6 +47,23 @@ jobs:
4447
json-summary-path: coverage/coverage-summary.json
4548
json-final-path: coverage/coverage-final.json
4649
file-coverage-mode: all
50+
- name: Update coverage badge
51+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
52+
run: |
53+
COVERAGE=$(node -e "const c = require('./coverage/coverage-summary.json'); console.log(c.total.lines.pct)")
54+
if (( $(echo "$COVERAGE >= 90" | bc -l) )); then COLOR="brightgreen"
55+
elif (( $(echo "$COVERAGE >= 75" | bc -l) )); then COLOR="green"
56+
elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then COLOR="yellowgreen"
57+
elif (( $(echo "$COVERAGE >= 45" | bc -l) )); then COLOR="yellow"
58+
else COLOR="red"; fi
59+
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${COVERAGE}%\",\"color\":\"${COLOR}\"}" > endpoint.json
60+
git config user.name "github-actions[bot]"
61+
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
64+
git add endpoint.json
65+
git commit -m "Update coverage badge to ${COVERAGE}%" || true
66+
git push origin coverage-data
4767
4868
lint:
4969
name: Lint

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![npm version](https://img.shields.io/npm/v/termbeam.svg)](https://www.npmjs.com/package/termbeam)
66
[![CI](https://github.com/dorlugasigal/TermBeam/actions/workflows/ci.yml/badge.svg)](https://github.com/dorlugasigal/TermBeam/actions/workflows/ci.yml)
7-
[![Coverage](https://img.shields.io/badge/coverage-check%20PR-blue)](https://github.com/dorlugasigal/TermBeam/pulls)
7+
[![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/dorlugasigal/TermBeam/coverage-data/endpoint.json)](https://github.com/dorlugasigal/TermBeam/actions/workflows/ci.yml)
88
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
99

1010
TermBeam lets you access your terminal from a phone, tablet, or any browser — no SSH, no port forwarding, no config files. Run one command and scan the QR code.

0 commit comments

Comments
 (0)