Skip to content

Commit 88e418b

Browse files
ci: call the shared update-badges workflow (#138)
The machinery moves to Nano-Collective/.github; the schedule and the PAT stay here. All seven package repos produced the same eight badges from files that had drifted to between 89 and 147 lines — different action pinning, different step names, different quoting, one with an extra build step. Nothing about fetching a shields.io SVG and committing it is project-specific. The shared version pins every action by SHA, derives the npm package name from package.json rather than hardcoding it, and refuses to commit a badge that is not SVG — shields.io returns an HTML error page for a bad package name, and committing that over a good badge is worse than leaving a stale one. Verified on get-md before this rollout: the workflow ran green end to end, regenerated all eight badges, and pushed the commit. Claude-Session: https://claude.ai/code/session_01PZY52ePXLjwG9TaQgq2cHT Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a177a8c commit 88e418b

1 file changed

Lines changed: 17 additions & 132 deletions

File tree

Lines changed: 17 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,28 @@
11
name: Update Status Badges
2+
3+
# Thin caller for the shared org workflow. Everything lives in
4+
# Nano-Collective/.github — change it there and every repo picks it up on its
5+
# next run.
6+
#
7+
# PAT_TOKEN is how the push gets past the branch rulesets. It is optional in the
8+
# shared workflow, but without it the push is made as github-actions[bot], which
9+
# the rulesets will refuse: adding the built-in Actions integration as a bypass
10+
# actor is rejected by GitHub with "Actor GitHub Actions integration must be
11+
# part of the ruleset source or owner organization" (tested 2026-09-07). So for
12+
# now every repo needs the secret.
13+
214
on:
315
workflow_dispatch:
416
schedule:
5-
- cron: '0 0 * * *' # Once a day at midnight UTC
17+
- cron: '0 0 * * *' # daily at midnight UTC
618
release:
719
types: [published]
820

921
permissions:
1022
contents: write
1123

1224
jobs:
13-
generate-badges:
14-
runs-on: ubuntu-latest
15-
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v7
18-
with:
19-
token: ${{ secrets.PAT_TOKEN }}
20-
21-
- name: Setup pnpm
22-
uses: pnpm/action-setup@v6.0.10
23-
24-
- name: Setup Node.js
25-
uses: actions/setup-node@v7
26-
with:
27-
node-version: '22'
28-
cache: 'pnpm'
29-
30-
- name: Install dependencies
31-
run: pnpm install --frozen-lockfile
32-
33-
- name: Run tests for latest coverage
34-
run: pnpm run test:ava:coverage || echo "Coverage test failed or not available"
35-
36-
- name: Extract coverage (if available)
37-
id: coverage
38-
run: |
39-
if [ -f "coverage/coverage-summary.json" ]; then
40-
COVERAGE=$(cat coverage/coverage-summary.json | jq -r '.total.lines.pct // "N/A"')
41-
echo "percentage=${COVERAGE}" >> $GITHUB_OUTPUT
42-
else
43-
echo "percentage=N/A" >> $GITHUB_OUTPUT
44-
fi
45-
46-
- name: Run build to check status
47-
id: build
48-
run: |
49-
if pnpm build; then
50-
echo "status=passing" >> $GITHUB_OUTPUT
51-
echo "color=brightgreen" >> $GITHUB_OUTPUT
52-
else
53-
echo "status=failing" >> $GITHUB_OUTPUT
54-
echo "color=red" >> $GITHUB_OUTPUT
55-
fi
56-
57-
- name: Generate badges
58-
run: |
59-
# Create badges directory if it doesn't exist
60-
mkdir -p badges
61-
62-
# Coverage badge (with fallback if coverage not available) - with for-the-badge style
63-
if [ "${{ steps.coverage.outputs.percentage }}" != "N/A" ]; then
64-
COVERAGE_PERCENTAGE="${{ steps.coverage.outputs.percentage }}"
65-
COVERAGE_COLOR=$(echo "${COVERAGE_PERCENTAGE}" | awk '{print ($1 >= 80) ? "brightgreen" : ($1 >= 50) ? "yellow" : "red"}')
66-
curl -s "https://img.shields.io/badge/coverage-${COVERAGE_PERCENTAGE}%25-${COVERAGE_COLOR}?style=for-the-badge" > badges/coverage.svg
67-
else
68-
curl -s "https://img.shields.io/badge/coverage-N%2FA-lightgrey?style=for-the-badge" > badges/coverage.svg
69-
fi
70-
71-
# Build status badge - with for-the-badge style and githubactions logo
72-
curl -s "https://img.shields.io/badge/build-${{ steps.build.outputs.status }}-${{ steps.build.outputs.color }}?style=for-the-badge&logo=githubactions" > badges/build.svg
73-
74-
# NPM Downloads (monthly) - with for-the-badge style and npm logo
75-
curl -s "https://img.shields.io/npm/dm/@nanocollective/prompt-scrub?style=for-the-badge&logo=npm" > badges/npm-downloads-monthly.svg
76-
77-
# NPM License - with for-the-badge style and npm logo
78-
curl -s "https://img.shields.io/npm/l/@nanocollective/prompt-scrub?style=for-the-badge" > badges/npm-license.svg
79-
80-
# GitHub Repo Size - with for-the-badge style and github logo
81-
curl -s "https://img.shields.io/github/repo-size/Nano-Collective/prompt-scrubber?style=for-the-badge&logo=github" > badges/repo-size.svg
82-
83-
# GitHub Repo Stars - with for-the-badge style and github logo
84-
curl -s "https://img.shields.io/github/stars/Nano-Collective/prompt-scrubber?style=for-the-badge&logo=github" > badges/stars.svg
85-
86-
# GitHub Forks - with for-the-badge style and github logo
87-
curl -s "https://img.shields.io/github/forks/Nano-Collective/prompt-scrubber?style=for-the-badge&logo=github" > badges/forks.svg
88-
89-
# NPM version - with for-the-badge style and npm logo
90-
curl -s "https://img.shields.io/npm/v/@nanocollective/prompt-scrub?style=for-the-badge&logo=npm" > badges/npm-version.svg
91-
92-
- name: Update README with badges
93-
run: |
94-
# Update badges in README.md
95-
if [ -f "README.md" ]; then
96-
# Create a temporary file to avoid direct modification issues
97-
cp README.md README.md.tmp
98-
99-
# Replace or add badges in the README
100-
sed -i 's|!\[Build Status\].*|![Build Status](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/build.svg)|' README.md.tmp || echo "Build badge not found, will add it"
101-
sed -i 's|!\[Coverage\].*|![Coverage](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/coverage.svg)|' README.md.tmp || echo "Coverage badge not found, will add it"
102-
sed -i 's|!\[Version\].*|![Version](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/npm-version.svg)|' README.md.tmp || echo "Version badge not found, will add it"
103-
sed -i 's|!\[Downloads\].*|![Downloads](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/npm-downloads-monthly.svg)|' README.md.tmp || echo "Downloads badge not found, will add it"
104-
sed -i 's|!\[Stars\].*|![Stars](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/stars.svg)|' README.md.tmp || echo "Stars badge not found, will add it"
105-
sed -i 's|!\[License\].*|![License](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/npm-license.svg)|' README.md.tmp || echo "License badge not found, will add it"
106-
sed -i 's|!\[Repo Size\].*|![Repo Size](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/repo-size.svg)|' README.md.tmp || echo "Repo size badge not found, will add it"
107-
sed -i 's|!\[Forks\].*|![Forks](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/forks.svg)|' README.md.tmp || echo "Forks badge not found, will add it"
108-
109-
# If badges section doesn't exist, add it after the first heading
110-
if ! grep -q "Build Status\|Coverage\|Version\|Downloads\|Stars\|License" README.md.tmp; then
111-
# Add badges after the first heading
112-
sed -i '2i \
113-
\
114-
# Status Badges \
115-
\
116-
![Build Status](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/build.svg) \
117-
![Coverage](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/coverage.svg) \
118-
![Version](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/npm-version.svg) \
119-
![Downloads](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/npm-downloads-monthly.svg) \
120-
![Stars](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/stars.svg) \
121-
![License](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/npm-license.svg) \
122-
![Repo Size](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/repo-size.svg) \
123-
![Forks](https://github.com/Nano-Collective/prompt-scrubber/raw/main/badges/forks.svg) \
124-
\
125-
' README.md.tmp
126-
fi
127-
128-
# Replace the original file
129-
mv README.md.tmp README.md
130-
fi
131-
132-
- name: Commit and push badges
133-
run: |
134-
git config --local user.email "action@github.com"
135-
git config --local user.name "GitHub Action"
136-
git add badges/ README.md
137-
# Only commit if there are staged changes
138-
if ! git diff --cached --quiet; then
139-
git commit -m "Update status badges [skip ci]" || echo "No changes to commit"
140-
git push
141-
else
142-
echo "No changes to commit"
143-
fi
25+
badges:
26+
uses: Nano-Collective/.github/.github/workflows/update-badges.yml@main
27+
secrets:
28+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}

0 commit comments

Comments
 (0)