backup-cloudbase #29
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: backup-cloudbase | |
| on: | |
| schedule: | |
| # 北京时间 0:00 = UTC 16:00(前一日) | |
| - cron: '0 16 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| backup-and-build: | |
| runs-on: ubuntu-latest | |
| # 密钥配置在 Environment 里时必须声明 environment,否则 secrets.* 为空 | |
| # 见 Settings → Environments → github-pages → Environment secrets | |
| environment: github-pages | |
| concurrency: | |
| group: backup-cloudbase | |
| cancel-in-progress: false | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Pull CloudBase backup | |
| env: | |
| COMMENT_ADMIN_SECRET: ${{ secrets.COMMENT_ADMIN_SECRET }} | |
| COMMENT_ADMIN_SECRET_VAR: ${{ vars.COMMENT_ADMIN_SECRET }} | |
| CLOUDBASE_HTTP_URL: ${{ secrets.CLOUDBASE_HTTP_URL }} | |
| TENCENTCLOUD_SECRETID: ${{ secrets.TENCENTCLOUD_SECRETID }} | |
| TENCENTCLOUD_SECRETKEY: ${{ secrets.TENCENTCLOUD_SECRETKEY }} | |
| CLOUDBASE_BUILD_FETCH: '1' | |
| run: node scripts/backup-cloudbase-data.mjs | |
| - name: Rebuild pages with latest stats | |
| env: | |
| COMMENT_ADMIN_SECRET: ${{ secrets.COMMENT_ADMIN_SECRET }} | |
| COMMENT_ADMIN_SECRET_VAR: ${{ vars.COMMENT_ADMIN_SECRET }} | |
| CLOUDBASE_HTTP_URL: ${{ secrets.CLOUDBASE_HTTP_URL }} | |
| TENCENTCLOUD_SECRETID: ${{ secrets.TENCENTCLOUD_SECRETID }} | |
| TENCENTCLOUD_SECRETKEY: ${{ secrets.TENCENTCLOUD_SECRETKEY }} | |
| CLOUDBASE_BUILD_FETCH: '1' | |
| run: npm run build | |
| - name: Commit backup and rebuilt pages | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add data/cloudbase-backup sitemap.xml rss.xml robots.txt manifest.webmanifest data/posts.json data/search.json assets/og post post.html sw.js assets/dist index.html | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "backup: daily CloudBase stats and page rebuild [skip ci]" | |
| git push | |
| fi |