Refresh catalog #12
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: Refresh catalog | |
| on: | |
| schedule: | |
| - cron: '0 9 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| refresh: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - run: bun install --frozen-lockfile || bun install | |
| - name: Run refresh | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: bun run refresh:catalog | |
| - name: Open PR if snapshot changed | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| if git diff --quiet data/repos.json; then | |
| echo 'No changes; nothing to do.' | |
| exit 0 | |
| fi | |
| DATE="$(date -u +%F)" | |
| BRANCH="catalog/refresh" | |
| git config user.name 'github-actions[bot]' | |
| git config user.email 'github-actions[bot]@users.noreply.github.com' | |
| # Ensure remote-tracking ref exists so --force-with-lease works on retries. | |
| git fetch origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" || true | |
| git checkout -B "$BRANCH" | |
| git add data/repos.json | |
| git commit -m "chore(catalog): refresh snapshot $DATE" | |
| git push --force-with-lease origin "$BRANCH" | |
| if ! gh pr view "$BRANCH" >/dev/null 2>&1; then | |
| gh pr create --base main --head "$BRANCH" \ | |
| --title "Refresh catalog snapshot" \ | |
| --body "Automated snapshot refresh from the GitHub API." | |
| fi | |
| gh pr merge "$BRANCH" --auto --squash |