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
| # 构建 VitePress 站点并将其部署到 GitHub Pages 的工作流程 | |
| name: Deploy VitePress site to Pages | |
| on: # 定义触发条件 | |
| push: # 当代码推送到仓库时触发 | |
| branches: [main] # 仅在 main 分支推送时触发 | |
| workflow_dispatch: # 允许从 Actions 选项卡手动触发 | |
| permissions: # 设置 GITHUB_TOKEN 的权限 | |
| 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: # 构建作业的步骤序列 | |
| - name: Checkout # 步骤1:检出代码 | |
| uses: actions/checkout@v5 # 使用官方的 checkout action v5 | |
| with: | |
| fetch-depth: 0 # 获取完整的 git 历史记录 | |
| - name: Setup Node # 步骤2:设置 Node.js 环境 | |
| uses: actions/setup-node@v6 # 使用官方的 setup-node action v6 | |
| with: | |
| node-version: 24 # 指定 Node.js 版本为 24 | |
| cache: npm # 缓存 npm 依赖以加快后续构建 | |
| - name: Setup Pages # 步骤3:配置 GitHub Pages | |
| uses: actions/configure-pages@v4 # 自动注入 base path 等 Pages 配置 | |
| - name: Install dependencies # 步骤4:安装项目依赖 | |
| run: npm ci # 使用 ci 命令严格按 lock 文件安装 | |
| - name: Build with VitePress # 步骤5:构建静态站点 | |
| run: npm run www:build # 执行 vitepress build 命令 | |
| - name: Upload artifact # 步骤6:上传构建产物 | |
| uses: actions/upload-pages-artifact@v3 # 使用官方的上传 artifact action | |
| with: | |
| path: dist # 指定构建输出目录(对应 VitePress 的 outDir) | |
| deploy: # 部署作业 | |
| environment: # 部署环境配置 | |
| name: github-pages # 环境名称为 github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} # 动态获取部署后的页面 URL | |
| needs: build # 依赖 build 作业,必须先完成构建 | |
| runs-on: ubuntu-latest # 运行在最新的 Ubuntu 虚拟环境上 | |
| name: Deploy # 作业显示名称 | |
| steps: # 部署作业的步骤序列 | |
| - name: Deploy to GitHub Pages # 步骤1:部署到 GitHub Pages | |
| id: deployment # 步骤 ID,用于引用输出结果 | |
| uses: actions/deploy-pages@v4 # 使用官方的部署 action v4 |