docs: 创建GitHub Pages启用操作指南 #6
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 | |
| on: | |
| push: | |
| branches: | |
| - main # 当推送到main分支时触发 | |
| workflow_dispatch: # 允许手动触发 | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # 只允许一个并发部署 | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| - name: 设置 Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: 安装依赖 | |
| run: npm install | |
| - name: 构建项目 | |
| run: npm run build | |
| env: | |
| CI: false # 忽略警告,避免构建失败 | |
| - name: 设置 Pages | |
| uses: actions/configure-pages@v4 | |
| - name: 上传构建产物 | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./build | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: 部署到 GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |