-
Notifications
You must be signed in to change notification settings - Fork 16
68 lines (54 loc) · 2.24 KB
/
Copy pathupdate-badge.yml
File metadata and controls
68 lines (54 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Sync Good First Issues Badge
on:
issues:
types: [opened, closed, labeled, unlabeled, reopened]
workflow_dispatch:
permissions:
contents: write
jobs:
update-badge:
name: Update README badge
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Count open "good first issue" issues and update badge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# ── 1. Count live open "good first issue" issues ─────────────────
COUNT=$(gh issue list \
--repo "${{ github.repository }}" \
--label "good first issue" \
--state open \
--limit 500 \
--json number \
--jq 'length')
echo "Open good first issues: $COUNT"
# ── 2. Read current badge count from README ───────────────────────
CURRENT=$(grep -oE 'Good%20First%20Issues-[0-9]+%20Open' README.md \
| grep -oE '[0-9]+' | head -1 || echo "0")
echo "Current badge count: $CURRENT"
# ── 3. Skip if already up-to-date ────────────────────────────────
if [[ "$CURRENT" == "$COUNT" ]]; then
echo "Badge already shows $COUNT — nothing to do."
exit 0
fi
# ── 4. Update the badge in README.md ─────────────────────────────
sed -i \
"s|Good%20First%20Issues-[0-9]*%20Open|Good%20First%20Issues-${COUNT}%20Open|g" \
README.md
echo "Badge updated: $CURRENT → $COUNT"
- name: Commit and push if README changed
run: |
if git diff --quiet README.md; then
echo "No changes — skipping commit."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "chore: sync Good First Issues badge [skip ci]"
git push