diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index a5c1c28..38e8185 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -1,3 +1,4 @@ +# 构建 VitePress 站点并将其部署到 GitHub Pages name: Deploy GitHub Pages # 触发条件 @@ -9,44 +10,64 @@ on: branches: - main +# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列 +# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成 +concurrency: + group: pages + cancel-in-progress: false + jobs: - deploy: + # 构建工作 + build: runs-on: ubuntu-latest steps: # 拉取代码 - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 # 如果未启用 lastUpdated,则不需要 - # 缓存 node_modules - - name: Cache node_modules - uses: actions/cache@v3 - with: - path: | - ~/.npm - node_modules - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- + # - uses: pnpm/action-setup@v3 # 如果使用 pnpm,请取消注释 + # - uses: oven-sh/setup-bun@v1 # 如果使用 Bun,请取消注释 # 设置 Node.js 环境 - - name: Set up Node.js + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 22 + cache: npm # 或 pnpm / yarn + + - name: Setup Pages + uses: actions/configure-pages@v4 # 安装依赖 - name: Install dependencies - run: npm install + run: npm ci # 或 pnpm install / yarn install / bun install # 构建项目 - - name: Build - run: npm run build + - name: Build with VitePress + run: npm run docs:build # 或 pnpm docs:build / yarn docs:build / bun run docs:build - # 部署到 GitHub Pages - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./dist # 这里的 dist 是构建后的文件目录,根据实际情况修改 + path: docs/.vitepress/dist + + # 部署工作 + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: build + runs-on: ubuntu-latest + name: Deploy + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4