Skip to content

Update Badges

Update Badges #189

Workflow file for this run

name: Update Badges
on:
push:
branches: [main]
workflow_run:
workflows: [Go]
types: [completed]
branches: [main]
schedule:
# Run every 6 hours to keep badges fresh
- cron: "0 */6 * * *"
workflow_dispatch: # Allow manual trigger
permissions:
contents: read
jobs:
update-metrics:
name: Update Badge Metrics
runs-on: ubuntu-latest
# Only run if Go workflow passed (when triggered by workflow_run) or on other triggers
if: >
github.event_name != 'workflow_run' ||
github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Full history needed for commit count and age
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Generate badge metrics
env:
GH_TOKEN: ${{ secrets.GIST_TOKEN }}
run: ./scripts/generate-badges.sh
- name: Upload all badges to gist
env:
GH_TOKEN: ${{ secrets.GIST_TOKEN }}
run: |
# Upload each badge JSON file to gist
# Use --add flag which creates or updates the file
# Add delay between uploads to avoid API rate limits and 409 conflicts
for badge in .github/badges/badge-*.json; do
echo "Uploading $badge..."
for attempt in 1 2 3; do
if gh gist edit ${{ vars.BADGE_GIST_ID }} --add "$badge"; then
break
fi
echo "Attempt $attempt failed, retrying in 2s..."
sleep 2
done
sleep 1
done