Skip to content

Commit 7c8d79f

Browse files
committed
chore: update node setup action to cache pnpm store only on main branch
1 parent f0a9ddf commit 7c8d79f

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

.github/actions/node-setup/action.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,22 @@ runs:
1515
uses: actions/setup-node@v6
1616
with:
1717
node-version: ${{ inputs.node-version }}
18-
cache: 'pnpm'
1918

19+
- name: Get pnpm store path
20+
id: pnpm-store
21+
shell: bash
22+
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
23+
24+
# Restore-keys fall back to the closest prior store even when the lockfile
25+
# hash doesn't match exactly, so PRs reuse main's store instead of
26+
# installing from scratch.
27+
- name: Restore pnpm store
28+
uses: actions/cache/restore@v4
29+
with:
30+
path: ${{ steps.pnpm-store.outputs.path }}
31+
key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
32+
restore-keys: |
33+
pnpm-store-${{ runner.os }}-
2034
2135
- name: Install dependencies
2236
shell: bash
@@ -29,3 +43,12 @@ runs:
2943
- name: Prune pnpm store
3044
shell: bash
3145
run: pnpm store prune
46+
47+
# Only main writes new cache entries — PRs restore-and-reuse but never
48+
# save, so open PRs stop each spawning their own throwaway ~700MB entry.
49+
- name: Save pnpm store
50+
if: github.ref == 'refs/heads/main'
51+
uses: actions/cache/save@v4
52+
with:
53+
path: ${{ steps.pnpm-store.outputs.path }}
54+
key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}

0 commit comments

Comments
 (0)