Deploy AIHeadline.news #481
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: Deploy AIHeadline.news | |
| on: | |
| push: | |
| branches: [main] | |
| schedule: | |
| - cron: '30 0 * * *' # 每天 UTC 00:30,即北京时间 08:30 | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| HUGO_VERSION: 0.150.0 | |
| jobs: | |
| build: | |
| name: Build site | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| submodules: false | |
| - name: Setup Pages | |
| id: pages | |
| uses: actions/configure-pages@v5 | |
| - name: Fetch latest briefing archive snapshot | |
| run: ./.github/scripts/update-source-news.sh | |
| env: | |
| SOURCE_NEWS_FETCH_RETRIES: 4 | |
| - name: Restore Hugo cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ./.cache/hugo_cache | |
| key: ${{ runner.os }}-hugo-${{ env.HUGO_VERSION }}-${{ hashFiles('hugo.toml', 'go.mod', 'go.sum', 'package*.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-hugo-${{ env.HUGO_VERSION }}- | |
| ${{ runner.os }}-hugo- | |
| - name: Setup Hugo | |
| uses: peaceiris/actions-hugo@v3 | |
| with: | |
| hugo-version: ${{ env.HUGO_VERSION }} | |
| extended: true | |
| - name: Sync content | |
| run: ./.github/scripts/sync-news.sh --mode=auto | |
| - name: Prepare build directories | |
| run: rm -rf public public-worker public-pages | |
| - name: Build site for Cloudflare Workers | |
| env: | |
| HUGO_ENVIRONMENT: production | |
| HUGO_CACHEDIR: ${{ github.workspace }}/.cache/hugo_cache | |
| run: | | |
| hugo \ | |
| --gc \ | |
| --minify \ | |
| --destination public-worker | |
| - name: Build site for GitHub Pages | |
| env: | |
| HUGO_ENVIRONMENT: production | |
| HUGO_CACHEDIR: ${{ github.workspace }}/.cache/hugo_cache | |
| run: | | |
| hugo \ | |
| --gc \ | |
| --minify \ | |
| --destination public-pages \ | |
| --baseURL "${{ steps.pages.outputs.base_url }}/" | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v4 | |
| with: | |
| path: public-pages | |
| - name: Upload Worker asset bundle | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: site-worker | |
| path: public-worker | |
| if-no-files-found: error | |
| retention-days: 1 | |
| deploy-pages: | |
| name: Deploy GitHub Pages | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deploy.outputs.page_url }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deploy | |
| uses: actions/deploy-pages@v4 | |
| deploy-worker: | |
| name: Deploy Cloudflare Worker | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: read | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| submodules: false | |
| - name: Clean default public directory | |
| run: rm -rf public | |
| - name: Download built site | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: site-worker | |
| path: public | |
| - name: Deploy to Cloudflare Workers | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| command: deploy --config wrangler.jsonc | |
| wranglerVersion: '4.38.0' |