download-badges #53
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: download-badges | |
| # Sum per-plugin .zip downloads across all GitHub Releases and publish shields.io endpoint JSON files | |
| # to the `badges` branch (raw.githubusercontent.com/.../badges/downloads/<plugin>.json), which the | |
| # per-plugin README badges point at. A separate branch keeps the daily commit off main so CI is not | |
| # re-triggered. Runs twice a day; download_count only moves when someone downloads, so more often is noise. | |
| on: | |
| schedule: | |
| - cron: '43 6,18 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 | |
| with: | |
| node-version: 22 | |
| - name: Aggregate downloads | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: node scripts/download-badges.mjs out | |
| - name: Publish to the badges branch | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| if git ls-remote --exit-code --heads origin badges >/dev/null 2>&1; then | |
| git fetch origin badges:badges | |
| git checkout badges | |
| else | |
| git checkout --orphan badges | |
| git rm -rf . >/dev/null 2>&1 || true | |
| fi | |
| mkdir -p downloads | |
| cp out/*.json downloads/ | |
| git add downloads | |
| if git diff --cached --quiet; then | |
| echo "No download-count change; nothing to commit." | |
| exit 0 | |
| fi | |
| git commit -m "Update download badges ($(date -u +%Y-%m-%d))" | |
| git push origin badges |