add(posts): 1 git #21
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: Build and Deploy to GitHub Pages | |
| on: | |
| push: | |
| branches: [ gh_pages ] | |
| pull_request: | |
| branches: [ master, gh_pages ] # PR 时只做检查,不部署 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write # 需要写入权限来部署到 GitHub Pages | |
| pages: write # 专门的 Pages 部署权限 | |
| id-token: write # OIDC 认证所需的权限 | |
| jobs: | |
| check: | |
| strategy: | |
| matrix: | |
| node: [ 20 ] # GitHub Pages 推荐 LTS 版本 | |
| runs-on: ubuntu-latest | |
| name: Astro Check for Node.js ${{ matrix.node }} | |
| steps: | |
| - name: Setup Node.js | |
| uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 | |
| with: | |
| node-version: ${{ matrix.node }} # 使用 LTS | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 | |
| with: | |
| run_install: false # Disable auto-install | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run Astro Check | |
| run: pnpm astro check | |
| deploy: | |
| if: ${{ github.event_name == 'push' && contains(' refs/heads/gh_pages ', github.ref) }} | |
| needs: check # 确保检查通过后再部署 | |
| runs-on: ubuntu-latest | |
| name: Deploy Astro Site to GitHub Pages | |
| steps: | |
| - name: Setup Node.js | |
| uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 | |
| with: | |
| node-version: 20 | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 | |
| with: | |
| run_install: false # Disable auto-install | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| # 构建生产版本 | |
| - name: Build Astro site | |
| run: | | |
| pnpm run build | |
| # 部署到 GitHub Pages | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| with: | |
| enablement: true | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: './dist' # 匹配 Astro 默认输出目录 | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |