Daily R2 Gallery Sync #20
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: "Daily R2 Gallery Sync" | |
| on: | |
| schedule: | |
| # 每天 UTC 16:00(北京时间 00:00)检查一次 | |
| - cron: "0 16 * * *" | |
| # 也支持手动触发 | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Install AWS CLI | |
| run: pip install awscli --quiet | |
| - name: Generate gallery from R2 | |
| env: | |
| R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} | |
| R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | |
| R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
| R2_BUCKET_NAME: ${{ secrets.R2_CDN_BUCKET_NAME }} | |
| R2_PUBLIC_URL: ${{ secrets.R2_CDN_PUBLIC_URL }} | |
| AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
| AWS_DEFAULT_REGION: auto | |
| run: bash _scripts/generate-gallery-r2.sh | |
| - name: Check for changes | |
| id: diff | |
| run: | | |
| if git diff --quiet _data/gallery.yml; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "R2 照片无变化,跳过更新" | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "检测到 R2 照片更新:" | |
| git diff --stat _data/gallery.yml | |
| fi | |
| - name: Commit and push | |
| if: steps.diff.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add _data/gallery.yml | |
| git commit -m "chore: sync gallery from R2 [auto]" | |
| git push |