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 to GitHub Pages # 工作流的名字,显示在 GitHub Actions 界面中 | |
| on: # 定义触发条件 | |
| push: # 当代码推送时触发 | |
| branches: [main] # 仅在 master 分支推送时触发 | |
| workflow_dispatch: # 允许手动触发工作流 | |
| permissions: # 设置工作流所需的权限 | |
| contents: read # 读取仓库内容的权限 | |
| pages: write # 写入 GitHub Pages 的权限 | |
| id-token: write # 用于 OIDC 身份验证的权限 | |
| concurrency: # 并发控制,避免重复部署 | |
| group: pages # 将同类任务归为 "pages" 组 | |
| cancel-in-progress: false # 不取消正在运行的任务 | |
| jobs: # 定义工作流中的任务 | |
| build: # 第一个任务:构建 | |
| runs-on: ubuntu-latest # 在最新的 Ubuntu 环境中运行 | |
| steps: # 构建任务的步骤 | |
| - uses: actions/checkout@v4 # 第一步:检出仓库代码 | |
| - uses: actions/setup-node@v4 # 第二步:设置 Node.js 环境 | |
| with: | |
| node-version: '24' # 使用 Node.js 24 版本 | |
| cache: npm # 缓存 npm 依赖,加快构建速度 | |
| - run: npm ci # 第三步:安装依赖(ci 更严格,保证锁文件一致) | |
| - run: npm install && npm run www:build # 第四步:运行构建命令,生成静态网站文件 | |
| - uses: actions/upload-pages-artifact@v3 # 第五步:上传构建产物 | |
| with: | |
| path: dist # 指定上传的目录(构建结果在 dist 文件夹) | |
| deploy: # 第二个任务:部署 | |
| needs: build # 依赖 build 任务,必须先完成构建 | |
| runs-on: ubuntu-latest # 在最新的 Ubuntu 环境中运行 | |
| environment: # 部署环境配置 | |
| name: github-pages # 环境名称,GitHub Pages 专用 | |
| url: ${{ steps.deployment.outputs.page_url }} # 部署完成后生成的页面 URL | |
| steps: | |
| - uses: actions/deploy-pages@v4 # 使用官方部署到 GitHub Pages 的 Action | |
| id: deployment # 给步骤一个 ID,方便引用输出结果 |