Skip to content

Commit 02bc8f1

Browse files
authored
feat(ci): warm Next.js builds via Turbopack persistent cache on a sticky disk (#5869)
* feat(ci): warm Next.js builds via Turbopack persistent cache on a sticky disk - enable experimental.turbopackFileSystemCacheForBuild behind NEXT_TURBOPACK_BUILD_CACHE so only the CI check build opts in; production image builds stay on the default cold path until the feature stabilizes - mount ./apps/sim/.next/cache as a Blacksmith sticky disk (cache-mount) instead of actions/cache: the turbopack cache is ~5 GB, which a sticky disk mounts in ~1s while an actions/cache round-trip would eat the win - measured locally: 105s cold compile vs 22s warm (4.8x) * chore(ci): drop the superseded actions/cache comment and restore trailing newline
1 parent 2b5a92a commit 02bc8f1

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

.github/workflows/test-build.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,17 @@ 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.
245-
- name: Restore Next.js build cache
246-
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
239+
# Turbopack's persistent build cache (NEXT_TURBOPACK_BUILD_CACHE below)
240+
# writes ~5 GB into .next/cache — a sticky disk mounts it in ~1s where an
241+
# actions/cache round-trip would eat the warm-build win. Same event/fork
242+
# namespacing as the other mounts; the GitHub fallback inside cache-mount
243+
# still uses actions/cache with a run_id-suffixed key.
244+
- name: Mount Next.js build cache
245+
uses: ./.github/actions/cache-mount
247246
with:
247+
provider: ${{ vars.CI_PROVIDER }}
248+
key: ${{ github.repository }}-nextjs-cache-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && '-fork' || '' }}
248249
path: ./apps/sim/.next/cache
249-
key: ${{ runner.os }}-nextjs-${{ hashFiles('bun.lock') }}-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }}
250-
restore-keys: |
251-
${{ runner.os }}-nextjs-${{ hashFiles('bun.lock') }}-${{ github.sha }}-
252-
${{ runner.os }}-nextjs-${{ hashFiles('bun.lock') }}-
253-
${{ runner.os }}-nextjs-
254250

255251
- name: Install dependencies
256252
run: bun install --frozen-lockfile
@@ -266,4 +262,7 @@ jobs:
266262
AWS_REGION: 'us-west-2'
267263
ENCRYPTION_KEY: '7cf672e460e430c1fba707575c2b0e2ad5a99dddf9b7b7e3b5646e630861db1c' # dummy key for CI only
268264
TURBO_CACHE_DIR: .turbo
269-
run: bunx turbo run build --filter=sim
265+
# Opt into Turbopack's persistent build cache (beta) for this CI
266+
# check build only — measured 105s cold vs 22s warm locally.
267+
NEXT_TURBOPACK_BUILD_CACHE: '1'
268+
run: bunx turbo run build --filter=sim

apps/sim/next.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ const nextConfig: NextConfig = {
144144
experimental: {
145145
optimizeCss: !isDev,
146146
turbopackFileSystemCacheForDev: false,
147+
/**
148+
* Turbopack's persistent build cache (beta) — opt-in via env so only the
149+
* CI check build uses it; production image builds stay on the default
150+
* cold-build path until the feature stabilizes.
151+
*/
152+
turbopackFileSystemCacheForBuild: process.env.NEXT_TURBOPACK_BUILD_CACHE === '1',
147153
preloadEntriesOnStart: false,
148154
optimizePackageImports: [
149155
'lodash',

0 commit comments

Comments
 (0)