Deploy to GitHub Pages #975
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
| # 部署前端页面到 GitHub Pages | |
| # 触发方式:1) web/ 代码变更 push 2) fetch.yml 数据更新后触发 | |
| name: Deploy to GitHub Pages | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'web/**' | |
| - '.github/workflows/deploy.yml' | |
| # 被 fetch.yml 触发 | |
| workflow_dispatch: | |
| # 允许手动触发 | |
| workflow_run: | |
| workflows: ["Fetch Trakt Data"] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| # 只有 fetch 成功时才部署(workflow_run 触发时检查) | |
| if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| # ① 检出公开仓库代码(不含数据) | |
| - name: 检出仓库 | |
| uses: actions/checkout@v4 | |
| # ② 从私有仓库拉取前端 JSON 数据 | |
| - name: 拉取私有仓库数据 | |
| run: | | |
| git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/shengdaozm/traktData.git /tmp/data-repo | |
| mkdir -p web/public/data | |
| cp -r /tmp/data-repo/web/public/data/. web/public/data/ 2>/dev/null || true | |
| echo "已拉取前端数据文件:" | |
| ls -la web/public/data/ || true | |
| if [ -z "$(ls -A web/public/data/ 2>/dev/null)" ]; then | |
| echo "⚠️ 未找到任何数据文件!请先手动触发 Fetch Trakt Data 工作流。" | |
| exit 1 | |
| fi | |
| if [ ! -f web/public/data/summary.json ]; then | |
| echo "⚠️ 缺少关键数据文件 summary.json!请检查 Fetch Trakt Data 工作流。" | |
| exit 1 | |
| fi | |
| # ③ 配置 Node.js | |
| - name: 配置 Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: web/package-lock.json | |
| # ④ 安装依赖并构建 | |
| - name: 安装依赖并构建 | |
| run: | | |
| npm install | |
| npm run build | |
| working-directory: web/ | |
| # ⑤ 上传 Pages 产物 | |
| - name: 上传 Pages 产物 | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: web/dist/ | |
| # ⑥ 部署到 GitHub Pages | |
| - name: 部署到 GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |