Skip to content

Commit 7575a95

Browse files
authored
ci: cache Vite Task output for docs builds (#2006)
## Summary - Keep the root `docs:build` script as `pnpm -C docs build`. - Move the cacheable docs build inside `docs/`: `docs` now runs installer asset copying first, then delegates `vitepress build` to the cacheable Vite Task `build:site`. - Configure `build:site` in `docs/vite.config.ts` with automatic input tracking, necessary generated-file exclusions, and explicit `.vitepress/dist/**` output tracking. - Add Vite Task cache restore/save steps to `deploy-docs.yml` and `deploy-docs-preview.yml` using `docs/node_modules/.vite/task-cache`. - Keep Netlify on `pnpm build:netlify`, which runs `vitepress build` directly without `vp`. - Use the released Vite+ package through `setup-vp` now that the task-cache behavior is available in v0.2.2. ## Time Saved **The cache-hit verification run reported `23.14s saved` for replaying `vitepress build`.** - Cache restored: ~13 MB (`13,374,673 B`). - Restore/download/extract overhead: ~0.41s. - Net saving after restore overhead: ~22.73s. - Save/upload overhead for the new PR-scoped key: ~0.69s. - **Net saving including download & upload overhead: ~22.04s.** ## Cache Verification | Scenario | Run | Result | | --- | --- | --- | | Relevant docs task config change | [Deploy Docs Preview run 28558655161, job 84671537096](https://github.com/voidzero-dev/vite-plus/actions/runs/28558655161/job/84671537096) | Restored the previous PR cache, then `vitepress build` missed with `cache miss: output configuration changed, executing`; saved a new PR cache key for `96913ac2`. | | Irrelevant workflow-only change | [Deploy Docs Preview run 28559033970, job 84672667814](https://github.com/voidzero-dev/vite-plus/actions/runs/28559033970/job/84672667814) | Restored the PR cache from `96913ac2`, then `vitepress build` hit with `cache hit, replaying`; saved a new PR cache key for `0bfe9c6e`. This verification commit was later dropped from branch history. | | Rewritten current PR head | [Deploy Docs Preview run 28559971286, job 84675438841](https://github.com/voidzero-dev/vite-plus/actions/runs/28559971286/job/84675438841) | Restored the prior PR cache, replayed `vitepress build`, and saved the current PR-head cache key for `893293ac`. | ## Validation - Verified the relevant-change push misses and updates the PR cache. - Verified an irrelevant change restores the previous PR cache and hits `vitepress build`. - Verified the post-rewrite PR head still restores the prior PR cache and hits `vitepress build`. - Latest PR checks are green: 12 passed, 16 skipped, 2 neutral, 0 pending, 0 failed. ## Notes The generated input exclusions remain necessary because VitePress reads and writes generated `.vitepress` and `node_modules/.vite-temp` files during the cacheable build. Explicit `output` is included so cached builds restore `.vitepress/dist` reliably.
1 parent 4f7fd0b commit 7575a95

5 files changed

Lines changed: 55 additions & 2 deletions

File tree

.github/workflows/deploy-docs-preview.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,27 @@ jobs:
3737
working-directory: docs
3838
cache-dependency-path: docs/pnpm-lock.yaml
3939

40+
- name: Restore docs Vite Task cache
41+
id: vite-task-cache
42+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
43+
with:
44+
path: docs/node_modules/.vite/task-cache
45+
key: vite-task-docs-${{ runner.os }}-${{ runner.arch }}-pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }}
46+
# Prefer this PR's newest cache, then fall back to main for new PRs.
47+
restore-keys: |
48+
vite-task-docs-${{ runner.os }}-${{ runner.arch }}-pr-${{ github.event.pull_request.number }}-
49+
vite-task-docs-${{ runner.os }}-${{ runner.arch }}-main-
50+
4051
- run: vp run build
4152
working-directory: docs
4253

54+
- name: Save docs Vite Task cache
55+
if: success() && steps.vite-task-cache.outputs.cache-hit != 'true'
56+
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
57+
with:
58+
path: docs/node_modules/.vite/task-cache
59+
key: ${{ steps.vite-task-cache.outputs.cache-primary-key }}
60+
4361
- run: vpx void deploy --dir docs/.vitepress/dist
4462
env:
4563
VOID_TOKEN: ${{ secrets.VOID_TOKEN }}

.github/workflows/deploy-docs.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,26 @@ jobs:
3737
working-directory: docs
3838
cache-dependency-path: docs/pnpm-lock.yaml
3939

40+
- name: Restore docs Vite Task cache
41+
id: vite-task-cache
42+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
43+
with:
44+
path: docs/node_modules/.vite/task-cache
45+
key: vite-task-docs-${{ runner.os }}-${{ runner.arch }}-main-${{ github.sha }}
46+
# Restore the latest main cache; Vite Task fingerprints decide reuse.
47+
restore-keys: |
48+
vite-task-docs-${{ runner.os }}-${{ runner.arch }}-main-
49+
4050
- run: vp run build
4151
working-directory: docs
4252

53+
- name: Save docs Vite Task cache
54+
if: success() && steps.vite-task-cache.outputs.cache-hit != 'true'
55+
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
56+
with:
57+
path: docs/node_modules/.vite/task-cache
58+
key: ${{ steps.vite-task-cache.outputs.cache-primary-key }}
59+
4360
- run: vpx void deploy --dir docs/.vitepress/dist
4461
env:
4562
VOID_TOKEN: ${{ secrets.VOID_TOKEN }}

docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "module",
55
"scripts": {
66
"dev": "vitepress dev",
7-
"build": "cp ../packages/cli/install.sh ../packages/cli/install.ps1 public/ && vitepress build",
7+
"build": "cp ../packages/cli/install.sh ../packages/cli/install.ps1 public/ && vp run build:site",
8+
"build:netlify": "cp ../packages/cli/install.sh ../packages/cli/install.ps1 public/ && vitepress build",
89
"preview": "vitepress preview",
910
"update-trusted-stack-stats": "node .vitepress/theme/data/fetch-trusted-stack-stats.ts"
1011
},

docs/vite.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default {
2+
run: {
3+
tasks: {
4+
'build:site': {
5+
command: 'vitepress build',
6+
input: [
7+
{ auto: true },
8+
'!.vitepress/.temp/**',
9+
'!.vitepress/dist/**',
10+
'!node_modules',
11+
'!node_modules/.vite-temp/**',
12+
],
13+
output: ['.vitepress/dist/**'],
14+
},
15+
},
16+
},
17+
};

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build]
22
base = "docs/"
3-
command = "pnpm build"
3+
command = "pnpm build:netlify"
44
publish = ".vitepress/dist"
55

66
# Windows installer redirect

0 commit comments

Comments
 (0)