Deploy Next.js site to Pages #1211
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 Next.js site to Pages | |
| on: | |
| # 改代码(非文章/说说)时直接部署,但不会发 Bark 通知 | |
| push: | |
| branches: ["main"] | |
| paths-ignore: | |
| - 'XHBlogs/moments/**' | |
| - 'XHBlogs/posts/**' | |
| - 'XHBlogs/chatters/**' | |
| - 'XHBlogs/public/moments/**' | |
| - 'XHBlogs/public/posts/**' | |
| - 'XHBlogs/public/chatters/**' | |
| # 文章/说说/杂谈推送后:等 auto-date 跑完再部署,且会精准发送通知 | |
| workflow_run: | |
| workflows: ["Auto Fix Frontmatter & Fill Images"] | |
| types: | |
| - completed | |
| # 手动触发仍然保留 | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| # workflow_run 时:只有成功才部署;手动/普通 push 照常跑 | |
| if: > | |
| github.event_name != 'workflow_run' || | |
| github.event.workflow_run.conclusion == 'success' | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| # workflow_run 触发时,拉最新 main(含 auto-date 刚推的提交) | |
| ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref }} | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| with: | |
| # 显式设为空,防止自动注入 /blog 子路径 | |
| static_site_generator: next | |
| - name: Install dependencies | |
| working-directory: ./XHBlogs | |
| run: npm ci || npm install | |
| - name: Build site | |
| working-directory: ./XHBlogs | |
| env: | |
| # 强制设置环境变量为空 | |
| NEXT_PUBLIC_BASE_PATH: "" | |
| run: npm run build | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./XHBlogs/out | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| # ============================== | |
| # Bark 通知(仅限 workflow_run 或手动触发才推送) | |
| # ============================== | |
| - name: Bark 推送 - 发布成功 | |
| if: success() && (github.event_name == 'workflow_run' || github.event_name == 'workflow_dispatch') | |
| run: | | |
| curl "${{ secrets.BARK_URL }}动态更新成功?title=个人博客&sound=shake&icon=https://wxidqlvk.github.io/moments/favicon/2026/08/23/1.webp" | |
| - name: Bark 推送 - 发布失败 | |
| if: failure() && !cancelled() && (github.event_name == 'workflow_run' || github.event_name == 'workflow_dispatch') | |
| run: | | |
| curl "${{ secrets.BARK_URL }}网站构建失败?title=个人博客&sound=shake&icon=https://wxidqlvk.github.io/moments/favicon/2026/08/23/1.webp" |