Auto Update #98
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: Auto Update | |
| on: | |
| schedule: | |
| - cron: '0 20 * * *' # 12 PM Pacific | |
| - cron: '0 1 * * *' # 5 PM Pacific | |
| workflow_dispatch: | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| has_updates: ${{ steps.changes.outputs.found }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check for updates | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| ./.scripts/auto-update latest stable | |
| ./.scripts/auto-update testing rc | |
| - name: Check for changes | |
| id: changes | |
| run: | | |
| if git diff --quiet images.json; then | |
| echo "found=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "found=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Upload artifact | |
| if: steps.changes.outputs.found == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: images | |
| path: images.json | |
| create-pr: | |
| runs-on: ubuntu-latest | |
| needs: check | |
| if: needs.check.outputs.has_updates == 'true' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: images | |
| - name: Create Pull Request | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| hash=$(sha256sum images.json | cut -c1-16) | |
| branch="auto-update/${hash}" | |
| # Check if PR already exists for this exact update | |
| if gh pr list --head "$branch" --state open --json number --jq '.[0].number' | grep -q .; then | |
| echo "PR already exists for this update" | |
| exit 0 | |
| fi | |
| git checkout -b "$branch" | |
| git add images.json | |
| git commit -m "Update image dependencies (${hash})" | |
| git push -u origin "$branch" | |
| gh pr create \ | |
| --title "Update image dependencies (${hash})" \ | |
| --body "This PR was automatically generated by the auto-update workflow." \ | |
| --base main \ | |
| --head "$branch" | |
| gh pr merge --auto --squash "$branch" |