1- # 构建 VitePress 站点并将其部署到 GitHub Pages 的示例工作流程
2- #
31name : Deploy VitePress site to Pages
42
53on :
6- # 在针对 `main` 分支的推送上运行。如果你
7- # 使用 `master` 分支作为默认分支,请将其更改为 `master`
84 push :
95 branches : [main]
106
139
1410# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
1511permissions :
16- contents : read
12+ contents : write
1713 pages : write
1814 id-token : write
1915
@@ -24,42 +20,44 @@ concurrency:
2420 cancel-in-progress : false
2521
2622jobs :
27- # 构建工作
28- build :
23+ build-and-deploy :
2924 runs-on : ubuntu-latest
3025 steps :
3126 - name : Checkout
32- uses : actions/checkout@v4
27+ uses : actions/checkout@v3
3328 with :
34- fetch-depth : 0 # 如果未启用 lastUpdated,则不需要
35- - uses : pnpm/action-setup@v3 # 如果使用 pnpm,请取消此区域注释
36- # with:
37- # version: 9
29+ fetch-depth : 0
30+ - uses : pnpm/action-setup@v2
31+ with :
32+ version : 8
3833 - name : Setup Node
39- uses : actions/setup-node@v4
34+ uses : actions/setup-node@v3
4035 with :
4136 node-version : 18
42- cache : pnpm # 或 pnpm / yarn
43- - name : Setup Pages
44- uses : actions/configure-pages@v4
45- - name : Install dependencies
46- run : pnpm install # 或 pnpm install / yarn install / bun install
47- - name : Build with VitePress
48- run : pnpm run docs:build # 或 pnpm docs:build / yarn docs:build / bun run docs:build
49- - name : Upload artifact
50- uses : actions/upload-pages-artifact@v3
37+ cache : pnpm
38+
39+ # 缓存 VitePress 构建产物
40+ - name : Cache VitePress
41+ uses : actions/cache@v3
5142 with :
52- path : docs/.vitepress/dist
43+ path : |
44+ docs/.vitepress/cache
45+ docs/.vitepress/.temp
46+ key : vitepress-cache-${{ hashFiles('docs/**/*.md') }}-${{ hashFiles('docs/.vitepress/config.ts') }}
47+ restore-keys : |
48+ vitepress-cache-
5349
54- # 部署工作
55- deploy :
56- environment :
57- name : github-pages
58- url : ${{ steps.deployment.outputs.page_url }}
59- needs : build
60- runs-on : ubuntu-latest
61- name : Deploy
62- steps :
50+ - name : Setup Pages
51+ uses : actions/configure-pages@v3
52+ - name : Install dependencies
53+ run : pnpm install
54+ - name : Build
55+ run : |
56+ pnpm run docs:build
57+ touch docs/.vitepress/dist/.nojekyll
6358 - name : Deploy to GitHub Pages
64- id : deployment
65- uses : actions/deploy-pages@v4
59+ uses : JamesIves/github-pages-deploy-action@v4
60+ with :
61+ folder : docs/.vitepress/dist
62+ branch : gh-pages
63+ clean : true
0 commit comments