@@ -3,22 +3,38 @@ description: Install Vite+ and the workspace dependencies from cache. |
3 | 3 | runs: |
4 | 4 | using: composite |
5 | 5 | steps: |
6 | | - # setup-vp reuses an installed exact version, so restoring its home skips the |
7 | | - # installer download on every job. |
| 6 | + # ~/.vite-plus holds vp, the Node.js runtime, and pnpm. A cache entry never |
| 7 | + # updates, so the key names all three versions; otherwise a pnpm or Node.js |
| 8 | + # bump makes every job download them from npm again. |
8 | 9 | - name: Resolve Vite+ version |
9 | 10 | id: vp |
10 | 11 | shell: bash |
11 | 12 | run: | |
12 | 13 | echo "version=$(sed -nE 's/^ vite-plus: ([0-9][^ ]*)$/\1/p' pnpm-workspace.yaml)" >> "$GITHUB_OUTPUT" |
| 14 | + echo "node=$(jq -r '.engines.node' package.json)" >> "$GITHUB_OUTPUT" |
| 15 | + echo "pnpm=$(jq -r '.packageManager' package.json)" >> "$GITHUB_OUTPUT" |
13 | 16 |
|
14 | 17 | - name: Cache Vite+ |
| 18 | + id: vp_cache |
15 | 19 | if: steps.vp.outputs.version != '' |
16 | 20 | uses: actions/cache@v6 |
17 | 21 | with: |
18 | 22 | path: ~/.vite-plus |
19 | | - key: vite-plus-home-v1-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }} |
| 23 | + key: vite-plus-home-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}-node${{ steps.vp.outputs.node }}-${{ steps.vp.outputs.pnpm }} |
| 24 | + |
| 25 | + # setup-vp always runs the installer, which fetches vp from npm even when |
| 26 | + # this exact version is installed. A cache hit already has everything, so |
| 27 | + # skip setup-vp and do its remaining work here. This keeps npm outages from |
| 28 | + # failing jobs. |
| 29 | + - name: Use cached Vite+ |
| 30 | + if: steps.vp_cache.outputs.cache-hit == 'true' |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + echo "$HOME/.vite-plus/bin" >> "$GITHUB_PATH" |
| 34 | + "$HOME/.vite-plus/bin/vp" env use "${{ steps.vp.outputs.node }}" |
20 | 35 |
|
21 | 36 | - name: Setup Vite+ |
| 37 | + if: steps.vp_cache.outputs.cache-hit != 'true' |
22 | 38 | uses: voidzero-dev/setup-vp@v1 |
23 | 39 | with: |
24 | 40 | node-version-file: package.json |
|