Skip to content

Commit 456eff6

Browse files
committed
fix(ci): key node_modules sticky disk on the lockfile hash
1 parent 17d7779 commit 456eff6

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

.github/workflows/test-build.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ jobs:
3131
# namespace on top: untrusted fork runs must never share a cache with
3232
# push runs (whose caches feed production image builds) or with trusted
3333
# internal-PR runs.
34+
#
35+
# node_modules ALSO keys on the lockfile hash, the other two deliberately
36+
# do not. A sticky disk is a persistent mutable volume, so every branch
37+
# sharing one key shares one node_modules tree, and `bun install
38+
# --frozen-lockfile` installs what the lockfile needs without pruning what
39+
# it no longer references. Branches cut before a dependency bump therefore
40+
# wrote their older copies onto the shared disk and every other branch
41+
# inherited them — that is how builds on next 16.2.11 ended up loading a
42+
# stale @next/swc 16.2.6 that appears nowhere in bun.lock. Hashing the
43+
# lockfile gives each distinct dependency set its own disk, so a tree can
44+
# never mix versions from two different lockfiles.
45+
#
46+
# The bun download cache is content-addressed by package+version and the
47+
# Turbo cache is keyed by task hash, so both are safe to share across
48+
# lockfiles — and sharing them is what keeps a fresh node_modules disk
49+
# cheap to populate.
3450
- name: Mount Bun cache
3551
uses: ./.github/actions/cache-mount
3652
with:
@@ -42,7 +58,7 @@ jobs:
4258
uses: ./.github/actions/cache-mount
4359
with:
4460
provider: ${{ vars.CI_PROVIDER }}
45-
key: ${{ github.repository }}-node-modules-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}
61+
key: ${{ github.repository }}-node-modules-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}-${{ hashFiles('bun.lock') }}
4662
path: ./node_modules
4763

4864
- name: Mount Turbo cache
@@ -193,8 +209,10 @@ jobs:
193209
# Next.js production build, in parallel with lint + tests. Sticky disks are
194210
# cloned from the last committed snapshot per job and committed last-writer-
195211
# wins, so concurrent mounts are safe. The bun/node_modules disks are shared
196-
# with test-build (identical content from the same lockfile — LWW loss is
197-
# harmless), but the Turbo cache gets its own key: with a shared key, only
212+
# with test-build — and because the node_modules key now includes the lockfile
213+
# hash, the two jobs only ever share a disk when they really do resolve the
214+
# same dependency tree, so the LWW loss really is harmless. The Turbo cache
215+
# gets its own key: with a shared key, only
198216
# the last committer's new entries survive each run, so the test and build
199217
# Turbo entries would evict each other nondeterministically.
200218
# Same next build as the app image, so it needs a large runner. Peak RSS
@@ -236,7 +254,7 @@ jobs:
236254
uses: ./.github/actions/cache-mount
237255
with:
238256
provider: ${{ vars.CI_PROVIDER }}
239-
key: ${{ github.repository }}-node-modules-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}
257+
key: ${{ github.repository }}-node-modules-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}-${{ hashFiles('bun.lock') }}
240258
path: ./node_modules
241259

242260
- name: Mount Turbo cache

0 commit comments

Comments
 (0)