11name : Deploy VitePress
22
3+ # 推到 main 即自动构建,产物作为一次性 artifact 部署到 GitHub Pages(不提交进任何分支)。
4+ # 首次使用前:仓库 Settings → Pages → Source 必须选「GitHub Actions」(非 Deploy from a branch)。
35on :
46 push :
57 branches :
68 - main
79 workflow_dispatch :
810
911permissions :
10- contents : write
12+ contents : read
13+ pages : write
14+ id-token : write # deploy-pages 经 OIDC 验证部署来源,必需
15+
16+ # 同一时间只跑一个部署,排队中的不取消,保证最新一次一定部署成功
17+ concurrency :
18+ group : pages
19+ cancel-in-progress : false
1120
1221jobs :
13- deploy :
22+ build :
1423 runs-on : ubuntu-latest
15-
1624 steps :
1725 - name : Checkout
1826 uses : actions/checkout@v4
1927 with :
20- fetch-depth : 0
21-
22- - name : Setup Node.js
23- uses : actions/setup-node@v4
24- with :
25- node-version : ' 22'
28+ fetch-depth : 0 # lastUpdated: true 需要完整 git 历史
2629
2730 - name : Setup pnpm
2831 uses : pnpm/action-setup@v4
2932 with :
3033 version : 10
3134
35+ - name : Setup Node.js
36+ uses : actions/setup-node@v4
37+ with :
38+ node-version : ' 22'
39+ cache : pnpm
40+
3241 - name : Install dependencies
3342 run : pnpm install --frozen-lockfile
3443
@@ -41,14 +50,27 @@ jobs:
4150 vitepress-build-${{ runner.os }}-
4251 vitepress-build-
4352
53+ - name : Setup Pages
54+ uses : actions/configure-pages@v5
55+
4456 - name : Build
4557 run : pnpm build
4658 env :
47- NODE_OPTIONS : --max-old-space-size=6144
59+ NODE_OPTIONS : --max-old-space-size=6144 # 分卷并行构建仍需较大堆,防 OOM
4860 BUILD_CONCURRENCY : 8
4961
50- - name : Deploy to GitHub Pages
51- uses : peaceiris/ actions-gh- pages@v4
62+ - name : Upload artifact
63+ uses : actions/upload- pages-artifact@v3
5264 with :
53- github_token : ${{ secrets.GITHUB_TOKEN }}
54- publish_dir : ./site/.vitepress/dist
65+ path : site/.vitepress/dist
66+
67+ deploy :
68+ needs : build
69+ runs-on : ubuntu-latest
70+ environment :
71+ name : github-pages
72+ url : ${{ steps.deployment.outputs.page_url }}
73+ steps :
74+ - name : Deploy to GitHub Pages
75+ id : deployment
76+ uses : actions/deploy-pages@v4
0 commit comments