update-catalog-cache #299
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 Releases Cache | |
| on: | |
| repository_dispatch: | |
| types: [ update-catalog-cache ] | |
| schedule: | |
| - cron: "0 2 * * *" # 02:00 AM UTC everyday | |
| workflow_dispatch: | |
| concurrency: | |
| group: cache | |
| cancel-in-progress: true | |
| jobs: | |
| update-cache: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| actions: write | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Remove older workflow runs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh run list -L400 --repo "$GITHUB_REPOSITORY" --json databaseId -q '.[].databaseId' | | |
| tail -n+10 | | |
| xargs -IID gh api "repos/$GITHUB_REPOSITORY/actions/runs/ID" -X DELETE || : | |
| - name: Fetch releases from GitHub API | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api --paginate repos/nullcpy/rvb/releases > releases_new.json | |
| # Validate: must be a non-empty JSON array | |
| COUNT=$(jq 'if type == "array" then length else 0 end' releases_new.json) | |
| if [ "$COUNT" -eq 0 ]; then | |
| echo "::error::GitHub API returned an empty releases array. Aborting to preserve existing cache." | |
| exit 1 | |
| fi | |
| echo "Fetched $COUNT releases. Updating cache." | |
| mv releases_new.json releases.json | |
| - name: Commit and push changes | |
| uses: stefanzweifel/git-auto-commit-action@v7 | |
| with: | |
| commit_message: "update releases cache" | |
| file_pattern: releases.json | |
| trigger_notify_failure: | |
| needs: [ update-cache ] | |
| if: failure() | |
| uses: ./.github/workflows/notify.yml | |
| with: | |
| workflow_name: "Update Releases Cache" | |
| secrets: inherit |