11name : Update Milestone Badge
22
33on :
4- pull_request :
54 milestone :
65 types : [created, edited, closed, deleted]
76 schedule :
8- - cron : ' 0 6 * * *' # Daily at 6am UTC
7+ - cron : ' 0 6 * * *'
98 workflow_dispatch :
109
1110permissions :
@@ -25,23 +24,23 @@ jobs:
2524 env :
2625 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2726 run : |
28- # Get the nearest open milestone sorted by due date
29- MILESTONE=$(gh api repos/${{ github.repository }}/milestones \
30- --jq 'sort_by(.due_on) | map(select(.state == "open" and .due_on != null)) | first')
31-
32- LABEL="Next Milestone"
33- if [ -z "$MILESTONE" ] || [ "$MILESTONE" = "null" ]; then
34- MESSAGE="No milestone"
35- COLOR=" lightgrey"
27+ set -euo pipefail
28+
29+ # Fetch open milestones with due dates, pick the nearest one
30+ TITLE=$(gh api repos/${{ github.repository }}/milestones \
31+ --jq '[.[] | select(.state == "open" and .due_on != null)] | sort_by(.due_on) | .[0].title // empty')
32+
33+ if [ -z "$TITLE" ]; then
34+ URL="https://img.shields.io/badge/Roadmap-No%20milestone- lightgrey"
3635 else
37- TITLE=$(echo "$MILESTONE" | jq -r '.title')
38- # URL-encode the title for shields.io
39- MESSAGE=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$TITLE', safe=''))")
40- COLOR="blue"
36+ # URL-encode the title using jq
37+ ENCODED=$(echo -n "$TITLE" | jq -sRr @uri)
38+ URL="https://img.shields.io/badge/Roadmap-${ENCODED}-blue"
4139 fi
4240
4341 mkdir -p milestone
44- curl -s "https://img.shields.io/badge/${LABEL}-${MESSAGE}-${COLOR}" -o milestone/badge.svg
42+ curl -sfL "$URL" -o milestone/badge.svg
43+ echo "Badge generated for: ${TITLE:-No milestone}"
4544
4645 - name : Commit and push
4746 run : |
0 commit comments