Skip to content

Commit 73c7231

Browse files
authored
feat: add dynamic code coverage badge (#87)
* feat: add dynamic code coverage badge Extract line coverage percentage from npm run test:coverage output and update a shields.io endpoint badge via GitHub Gist on pushes to main. Uses schneegans/dynamic-badges-action with continue-on-error so CI is not blocked if GIST_TOKEN is not set. Badge added to README.md between Security and VS Code Marketplace badges. Gist: d01e4551b744b77e2927555e43a4b935 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca> * fix: exclude vsmarketplacebadges.dev from lychee link checks Badge SVG endpoints are prone to transient 500 errors that cause false positive link checker failures. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca> * feat: auto-update open PR branches after merge to main When a PR merges, the post-merge workflow now iterates all open PRs and runs gh pr update-branch on each. This eliminates the manual 'Update branch' click when strict status checks require branches to be up to date. Also enabled allow_update_branch on the repo via API. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca> --------- Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent 19cb091 commit 73c7231

4 files changed

Lines changed: 50 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,42 @@ jobs:
4141

4242
- name: Check code coverage
4343
if: matrix.os == 'ubuntu-latest'
44-
run: npm run test:coverage
44+
id: coverage
45+
run: |
46+
output=$(npm run test:coverage 2>&1)
47+
echo "$output"
48+
pct=$(echo "$output" | grep 'all files' | head -1 | awk -F'|' '{gsub(/[[:space:]]/, "", $2); print $2}')
49+
echo "percentage=$pct" >> "$GITHUB_OUTPUT"
50+
51+
- name: Determine badge color
52+
if: matrix.os == 'ubuntu-latest'
53+
id: color
54+
run: |
55+
pct="${{ steps.coverage.outputs.percentage }}"
56+
int_pct=${pct%.*}
57+
if [ "$int_pct" -ge 90 ]; then
58+
echo "color=brightgreen" >> "$GITHUB_OUTPUT"
59+
elif [ "$int_pct" -ge 80 ]; then
60+
echo "color=green" >> "$GITHUB_OUTPUT"
61+
elif [ "$int_pct" -ge 70 ]; then
62+
echo "color=yellowgreen" >> "$GITHUB_OUTPUT"
63+
elif [ "$int_pct" -ge 60 ]; then
64+
echo "color=yellow" >> "$GITHUB_OUTPUT"
65+
else
66+
echo "color=red" >> "$GITHUB_OUTPUT"
67+
fi
68+
69+
- name: Update coverage badge
70+
if: matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main'
71+
continue-on-error: true
72+
uses: schneegans/dynamic-badges-action@0e50b8bad39e7e1afd3e4e9c2b7dd145fad07501 # v1.8.0
73+
with:
74+
auth: ${{ secrets.GIST_TOKEN }}
75+
gistID: d01e4551b744b77e2927555e43a4b935
76+
filename: coverage.json
77+
label: coverage
78+
message: ${{ steps.coverage.outputs.percentage }}%
79+
color: ${{ steps.color.outputs.color }}
4580

4681
build:
4782
runs-on: ubuntu-latest

.github/workflows/post-merge.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
if: github.event.pull_request.merged == true
2020
permissions:
2121
actions: write
22+
contents: write
2223
steps:
2324
- name: Harden runner
2425
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
@@ -32,3 +33,13 @@ jobs:
3233
gh workflow run ci.yml --ref main --repo "${{ github.repository }}"
3334
gh workflow run security.yml --ref main --repo "${{ github.repository }}"
3435
gh workflow run scorecard.yml --ref main --repo "${{ github.repository }}"
36+
37+
- name: Auto-update open PR branches
38+
env:
39+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
gh pr list --base main --state open --json number --jq '.[].number' \
42+
--repo "${{ github.repository }}" | while read -r pr; do
43+
echo "Updating PR #$pr"
44+
gh pr update-branch "$pr" --repo "${{ github.repository }}" || true
45+
done

README.md

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

77
[![CI](https://github.com/patchloom/patchloom-vscode/actions/workflows/ci.yml/badge.svg)](https://github.com/patchloom/patchloom-vscode/actions/workflows/ci.yml)
88
[![Security](https://github.com/patchloom/patchloom-vscode/actions/workflows/security.yml/badge.svg)](https://github.com/patchloom/patchloom-vscode/actions/workflows/security.yml)
9+
[![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/SebTardif/d01e4551b744b77e2927555e43a4b935/raw/coverage.json)](https://github.com/patchloom/patchloom-vscode/actions/workflows/ci.yml)
910
[![VS Code Marketplace](https://vsmarketplacebadges.dev/version/patchloom.patchloom.svg)](https://marketplace.visualstudio.com/items?itemName=patchloom.patchloom)
1011
[![Open VSX](https://img.shields.io/open-vsx/v/patchloom/patchloom)](https://open-vsx.org/extension/patchloom/patchloom)
1112
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/patchloom/patchloom-vscode/badge)](https://securityscorecards.dev/viewer/?uri=github.com/patchloom/patchloom-vscode)

lychee.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ exclude = [
1616
"https://marketplace.visualstudio.com/items\\?itemName=patchloom\\.patchloom",
1717
"https://open-vsx.org/extension/patchloom/patchloom",
1818
"https://github.com/patchloom/patchloom-vscode/compare/patchloom-v",
19+
# Badge SVG endpoints are unreliable for link checking (transient 500s)
20+
"https://vsmarketplacebadges\\.dev/",
1921
]

0 commit comments

Comments
 (0)