Skip to content

Commit 49d3804

Browse files
authored
fix(ci): save the Next.js build cache every run instead of freezing it at the lockfile key (#5859)
* fix(ci): save the Next.js build cache every run instead of freezing it at the lockfile key The cache key was only runner.os + bun.lock hash, and GitHub caches are immutable per key: the first run after a lockfile change saved the cache once, then every later run hit the primary key and skipped the save ('Cache hit occurred on the primary key ... not saving cache'), so builds compiled against a cache stale since the last lockfile bump. Suffix the key with the commit SHA so each run saves its refreshed cache, and restore via prefix match to the most recent entry. * fix(ci): make the Next.js cache key unique per run attempt so reruns can save too
1 parent 3215a12 commit 49d3804

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

.github/workflows/test-build.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,20 @@ jobs:
236236
key: ${{ github.repository }}-turbo-cache-build-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}
237237
path: ./.turbo
238238

239+
# Keyed per commit so EVERY run saves its refreshed cache — a key without
240+
# a unique suffix is written once and then frozen (GitHub caches are
241+
# immutable per key; a primary-key hit skips the save), which left builds
242+
# compiling against a cache stale since the last lockfile change. The
243+
# restore-keys prefix match picks the most recently saved cache for this
244+
# lockfile, falling back across lockfile changes.
239245
- name: Restore Next.js build cache
240246
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
241247
with:
242248
path: ./apps/sim/.next/cache
243-
key: ${{ runner.os }}-nextjs-${{ hashFiles('bun.lock') }}
249+
key: ${{ runner.os }}-nextjs-${{ hashFiles('bun.lock') }}-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }}
244250
restore-keys: |
251+
${{ runner.os }}-nextjs-${{ hashFiles('bun.lock') }}-${{ github.sha }}-
252+
${{ runner.os }}-nextjs-${{ hashFiles('bun.lock') }}-
245253
${{ runner.os }}-nextjs-
246254
247255
- name: Install dependencies

0 commit comments

Comments
 (0)