create a milestone badge #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Milestone Badge | |
| on: | |
| pull_request: | |
| milestone: | |
| types: [created, edited, closed, deleted] | |
| schedule: | |
| - cron: '0 6 * * *' # Daily at 6am UTC | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-badge: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout docs branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: docs | |
| fetch-depth: 1 | |
| - name: Fetch nearest milestone and generate badge | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Get the nearest open milestone sorted by due date | |
| MILESTONE=$(gh api repos/${{ github.repository }}/milestones \ | |
| --jq 'sort_by(.due_on) | map(select(.state == "open" and .due_on != null)) | first') | |
| LABEL="Next Milestone" | |
| if [ -z "$MILESTONE" ] || [ "$MILESTONE" = "null" ]; then | |
| MESSAGE="No milestone" | |
| COLOR="lightgrey" | |
| else | |
| TITLE=$(echo "$MILESTONE" | jq -r '.title') | |
| # URL-encode the title for shields.io | |
| MESSAGE=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$TITLE', safe=''))") | |
| COLOR="blue" | |
| fi | |
| mkdir -p milestone | |
| curl -s "https://img.shields.io/badge/${LABEL}-${MESSAGE}-${COLOR}" -o milestone/badge.svg | |
| - name: Commit and push | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add milestone/badge.svg | |
| git diff --cached --quiet && echo "No changes" && exit 0 | |
| git commit -m "chore: update milestone badge" | |
| git push |