|
1 | 1 | 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 | + |
2 | 14 | on: |
3 | 15 | workflow_dispatch: |
4 | 16 | schedule: |
5 | | - - cron: '0 0 * * *' # Once a day at midnight UTC |
| 17 | + - cron: '0 0 * * *' # daily at midnight UTC |
6 | 18 | release: |
7 | 19 | types: [published] |
8 | 20 |
|
9 | 21 | permissions: |
10 | 22 | contents: write |
11 | 23 |
|
12 | 24 | 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\].*||' README.md.tmp || echo "Build badge not found, will add it" |
101 | | - sed -i 's|!\[Coverage\].*||' README.md.tmp || echo "Coverage badge not found, will add it" |
102 | | - sed -i 's|!\[Version\].*||' README.md.tmp || echo "Version badge not found, will add it" |
103 | | - sed -i 's|!\[Downloads\].*||' README.md.tmp || echo "Downloads badge not found, will add it" |
104 | | - sed -i 's|!\[Stars\].*||' README.md.tmp || echo "Stars badge not found, will add it" |
105 | | - sed -i 's|!\[License\].*||' README.md.tmp || echo "License badge not found, will add it" |
106 | | - sed -i 's|!\[Repo Size\].*||' README.md.tmp || echo "Repo size badge not found, will add it" |
107 | | - sed -i 's|!\[Forks\].*||' 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 | | -  \ |
117 | | -  \ |
118 | | -  \ |
119 | | -  \ |
120 | | -  \ |
121 | | -  \ |
122 | | -  \ |
123 | | -  \ |
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