Merge pull request #6 from 11273/dev/11273/vitepress #23
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: | |
| # 在针对 `main` 分支的推送上运行,只有当 docs 相关文件变更时才触发 | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'docs/**' | |
| - 'package.json' | |
| - 'package-lock.json' | |
| - '.github/workflows/deploy.yml' | |
| # 允许你从 Actions 选项卡手动运行此工作流程 | |
| workflow_dispatch: | |
| # 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列 | |
| # 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成 | |
| concurrency: | |
| group: pages | |
| cancel-in-progress: false | |
| # 环境变量 | |
| env: | |
| CI: true | |
| jobs: | |
| # 构建工作 | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # VitePress 需要获取最后更新时间 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Install dependencies | |
| run: | | |
| # 使用 npm ci 确保精确的依赖安装 | |
| npm ci | |
| - name: Run type check | |
| run: npm run typecheck | |
| - name: Run linting | |
| run: npm run lint | |
| - name: Build with VitePress | |
| run: | | |
| echo "🚀 开始构建 VitePress 站点..." | |
| npm run docs:build | |
| echo "✅ 构建完成" | |
| - name: Verify build output | |
| run: | | |
| echo "📊 构建产物信息:" | |
| du -sh docs/.vitepress/dist | |
| ls -la docs/.vitepress/dist | |
| - name: Check build size | |
| run: | | |
| BUILD_SIZE=$(du -sh docs/.vitepress/dist | cut -f1) | |
| echo "📦 构建大小: $BUILD_SIZE" | |
| # 检查是否有必要的文件 | |
| if [ ! -f "docs/.vitepress/dist/index.html" ]; then | |
| echo "❌ 缺少 index.html 文件" | |
| exit 1 | |
| fi | |
| if [ ! -d "docs/.vitepress/dist/assets" ]; then | |
| echo "⚠️ 警告: 缺少 assets 目录" | |
| fi | |
| echo "✅ 构建产物验证通过" | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: docs/.vitepress/dist | |
| # 部署工作 | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| - name: Deployment Success Notification | |
| if: success() | |
| run: | | |
| echo "🎉 网站部署成功!" | |
| echo "📄 网站地址: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" | |
| echo "⏰ 部署时间: $(date)" | |
| - name: Deployment Failure Notification | |
| if: failure() | |
| run: | | |
| echo "❌ 网站部署失败!" | |
| echo "🔍 请检查构建日志和配置" |