Skip to content

Commit 673e723

Browse files
committed
chore(ci): drop the dead build-cache prune mode and document the compiler cache removal
1 parent 8f3ee6f commit 673e723

3 files changed

Lines changed: 23 additions & 132 deletions

File tree

‎.github/CI.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ Database integration uses 4-vCPU Blacksmith runners with sticky dependency disks
3636

3737
GitHub runners install dependencies directly rather than transferring Bun and `node_modules` archives. In a same-source paired comparison, those restores took 26.2 seconds before an 82-millisecond install, while a clean install took 12.42 seconds. This is one paired observation; retain the policy only while repeated CI timings support it. Blacksmith keeps its sticky dependency disks. GitHub Turbo output caches remain enabled for jobs that request them, with a commit-specific key and a task/event/fork-scoped restore prefix, so a rerun can reuse an exact entry without creating another archive. Push jobs never restore pull-request entries.
3838

39-
Trusted Blacksmith E2E builders can reuse Next's incremental compiler state when a complete Turbo build is not already cached. The compiler cache has its own mode, event, OS/architecture, resolved toolchain, lockfile and build-recipe namespace; fork PRs and GitHub fallback keep the compiler cache off. The build command always runs, and an uncertain cache probe restores state rather than skipping compilation.
40-
41-
Compiler maintenance enforces a 20 GiB regular-file working-state limit before and after compilation, preserves the mounted root, and fails closed on access or ownership errors. Dev maintenance remains separate and nonblocking. Sticky disks are optional last-good compiler snapshots, not cross-job artifact handoff or validation receipts; no freshest-snapshot or physical-storage eviction guarantee is assumed. Hosted/deployment builds remain cache-off until separately qualified. A cold E2E qualification job took 259 seconds versus 225 uncached; fresh-runner warm and changed-source jobs took 148 and 159 seconds versus 227 and 229 uncached. These paired observations do not establish a universal CI speedup or justify smaller runners. Compilation and all existing acceptance coverage remain required.
39+
E2E builds compile without Next's persistent compiler cache (`turbopackFileSystemCacheForBuild: false`; Next enables it by default). Its earlier qualification showed warm, identical-source builds at 148 seconds, but real PR compiles restoring a shared cache took 2.9-4.6 minutes plus 15-37 seconds writing the cache back, while the same builds without it compiled in 2.5 minutes with no write. A complete Turbo build output is still reused when nothing it depends on changed. `scripts/prune-turbopack-cache.mts` caps only the dev cache.
4240

4341
Closing a same-repository pull request deletes only its GitHub merge-ref caches after verifying that it remains closed or merged. The regular `pull_request` workflow skips forks and Dependabot because their tokens cannot delete caches; those entries retain GitHub's normal cache eviction. Cleanup checks out no code and never selects a branch-wide or default-branch cache. Blacksmith sticky disks retain their separate lifecycle.
4442

‎scripts/prune-turbopack-cache.mts‎

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
#!/usr/bin/env node
22
/**
3-
* Caps each app's Turbopack cache from its working directory.
3+
* Caps an app's Turbopack dev cache (`.next/dev/cache/turbopack`) from its working directory.
44
*
5-
* Dev maintenance is best effort and never blocks startup. `--build` selects
6-
* `.next/cache`, preserves its mounted root, and fails on maintenance errors;
7-
* run it only between compiler processes. Oversized state is discarded so the
8-
* next compiler starts cold. Child symlinks are neither counted nor followed.
5+
* Best effort: it never blocks `next dev` startup. Oversized state is discarded so the next start
6+
* compiles cold. Child symlinks are neither counted nor followed; a symlinked cache root is unlinked
7+
* without touching its target.
98
*
10-
* Build maintenance uses Node's bounded directory iterator and stops counting
11-
* above the cap. Dev commands keep Bun and its existing best-effort behavior.
12-
*
13-
* CI build maintenance runs with Node 24: `node scripts/prune-turbopack-cache.mts [--build] [--force] [--dry-run]`.
9+
* Usage: `bun run scripts/prune-turbopack-cache.mts [--force] [--dry-run]`.
1410
* `SIM_TURBOPACK_CACHE_MAX_GB` overrides the default 20 GiB cap.
1511
*/
1612
import { existsSync, lstatSync, statSync } from 'node:fs'
@@ -19,43 +15,26 @@ import path from 'node:path'
1915

2016
const DEFAULT_MAX_GB = 20
2117
const BYTES_PER_GB = 1024 ** 3
22-
const BUILD_CACHE = process.argv.includes('--build')
2318

24-
/**
25-
* Each app owns its cache under its working directory. Build maintenance selects
26-
* a separate root, so it cannot prune a live dev server's state.
27-
*/
28-
const CACHE_DIR = path.resolve(
29-
process.cwd(),
30-
BUILD_CACHE ? '.next/cache' : '.next/dev/cache/turbopack'
31-
)
19+
/** Each app owns its dev cache under its working directory. */
20+
const CACHE_DIR = path.resolve(process.cwd(), '.next/dev/cache/turbopack')
3221

3322
function isMissingPath(error: unknown): boolean {
3423
return error instanceof Error && 'code' in error && error.code === 'ENOENT'
3524
}
3625

3726
/** Counts regular files without following symlinks or retaining the tree in memory. */
38-
async function directorySize(dir: string, limit: number): Promise<number> {
27+
async function directorySize(dir: string): Promise<number> {
3928
let total = 0
40-
let entries: Awaited<ReturnType<typeof opendir>>
41-
try {
42-
entries = await opendir(dir, { bufferSize: 32 })
43-
} catch (error) {
44-
if (BUILD_CACHE && isMissingPath(error)) return 0
45-
throw error
46-
}
47-
for await (const entry of entries) {
29+
for await (const entry of await opendir(dir, { bufferSize: 32 })) {
4830
const entryPath = path.join(dir, entry.name)
4931
if (entry.isDirectory()) {
50-
total += await directorySize(entryPath, limit - total)
32+
total += await directorySize(entryPath)
5133
} else if (entry.isFile()) {
5234
try {
5335
total += (await stat(entryPath)).size
54-
} catch (error) {
55-
if (BUILD_CACHE && !isMissingPath(error)) throw error
56-
}
36+
} catch {}
5737
}
58-
if (total > limit) break
5938
}
6039
return total
6140
}
@@ -92,28 +71,11 @@ function parseMaxGb(): number {
9271
async function main() {
9372
const force = process.argv.includes('--force')
9473
const dryRun = process.argv.includes('--dry-run')
95-
96-
if (BUILD_CACHE) {
97-
let root: ReturnType<typeof lstatSync>
98-
try {
99-
root = lstatSync(CACHE_DIR)
100-
} catch (error) {
101-
if (isMissingPath(error)) return
102-
throw error
103-
}
104-
if (root.isSymbolicLink() || !root.isDirectory())
105-
throw new Error('Build cache root must be a directory without symlinks')
106-
} else if (!existsSync(CACHE_DIR) || !statSync(CACHE_DIR).isDirectory()) {
107-
return
108-
}
74+
if (!existsSync(CACHE_DIR) || !statSync(CACHE_DIR).isDirectory()) return
10975

11076
const maxGb = parseMaxGb()
111-
const limit = BUILD_CACHE ? maxGb * BYTES_PER_GB : Number.POSITIVE_INFINITY
112-
const bytes = force ? 0 : await directorySize(CACHE_DIR, limit)
113-
const gb = bytes / BYTES_PER_GB
114-
const sizeLabel = force
115-
? 'cache'
116-
: `${BUILD_CACHE && bytes > limit ? 'at least ' : ''}${gb.toFixed(1)} GB`
77+
const gb = force ? 0 : (await directorySize(CACHE_DIR)) / BYTES_PER_GB
78+
const sizeLabel = force ? 'cache' : `${gb.toFixed(1)} GB`
11779

11880
if (!force && gb <= maxGb) {
11981
if (dryRun) console.log(`[turbopack-cache] ${sizeLabel} (cap ${maxGb} GB) — keeping`)
@@ -127,15 +89,14 @@ async function main() {
12789
}
12890

12991
console.log(`[turbopack-cache] ${sizeLabel} is ${reason} — pruning; next start recompiles cold`)
130-
if (!BUILD_CACHE && lstatSync(CACHE_DIR).isSymbolicLink()) {
92+
if (lstatSync(CACHE_DIR).isSymbolicLink()) {
13193
await rm(CACHE_DIR, { force: true })
13294
return
13395
}
13496
await clearDirectory(CACHE_DIR)
135-
if (!BUILD_CACHE) await rmdir(CACHE_DIR)
97+
await rmdir(CACHE_DIR)
13698
}
13799

138100
main().catch((error) => {
139101
console.warn('[turbopack-cache] prune skipped:', error)
140-
if (BUILD_CACHE) process.exitCode = 1
141102
})
Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { spawnSync } from 'node:child_process'
22
import {
33
existsSync,
4-
lstatSync,
54
mkdirSync,
65
mkdtempSync,
7-
readdirSync,
86
readFileSync,
97
rmSync,
10-
statSync,
118
symlinkSync,
129
writeFileSync,
1310
} from 'node:fs'
@@ -36,7 +33,7 @@ function fixture() {
3633
}
3734

3835
function run(root: string, args: string[], maximum = '0.000001') {
39-
return spawnSync(args.includes('--build') ? 'node' : 'bun', [script, ...args], {
36+
return spawnSync('bun', [script, ...args], {
4037
cwd: root,
4138
encoding: 'utf8',
4239
timeout: 10_000,
@@ -48,58 +45,8 @@ afterEach(() => {
4845
for (const root of fixtures.splice(0)) rmSync(root, { recursive: true, force: true })
4946
})
5047

51-
describe('compiler cache maintenance through the real CLI', () => {
52-
it.each(['size', 'force'])(
53-
'clears only build contents by %s while preserving its mount',
54-
(mode) => {
55-
const { root, build, dev, outside } = fixture()
56-
const inode = statSync(build).ino
57-
const result = run(
58-
root,
59-
mode === 'force' ? ['--build', '--force'] : ['--build'],
60-
mode === 'force' ? '1' : undefined
61-
)
62-
expect(result.status, result.stderr).toBe(0)
63-
expect(existsSync(build)).toBe(true)
64-
expect(statSync(build).ino).toBe(inode)
65-
expect(readdirSync(build)).toEqual([])
66-
expect(existsSync(join(dev, 'state'))).toBe(true)
67-
expect(existsSync(join(outside, 'state'))).toBe(true)
68-
}
69-
)
70-
71-
it('retains useful build state without counting external symlink targets', () => {
72-
const { root, build, dev, outside } = fixture()
73-
const inode = statSync(build).ino
74-
const buildBytes = readFileSync(join(build, 'state'))
75-
const devBytes = readFileSync(join(dev, 'state'))
76-
const outsideBytes = readFileSync(join(outside, 'state'))
77-
expect(run(root, ['--build'], '0.000006').status).toBe(0)
78-
expect(statSync(build).ino).toBe(inode)
79-
expect(readFileSync(join(build, 'state'))).toEqual(buildBytes)
80-
expect(readFileSync(join(dev, 'state'))).toEqual(devBytes)
81-
expect(readFileSync(join(outside, 'state'))).toEqual(outsideBytes)
82-
})
83-
84-
it('does not substitute dev state when the build cache is absent', () => {
85-
const { root, build, dev } = fixture()
86-
rmSync(build, { recursive: true })
87-
expect(run(root, ['--build']).status).toBe(0)
88-
expect(existsSync(join(dev, 'state'))).toBe(true)
89-
})
90-
91-
it('rejects a non-directory ancestor instead of treating it as an absent build cache', () => {
92-
const { root, outside } = fixture()
93-
const parent = join(root, '.next')
94-
rmSync(parent, { recursive: true })
95-
writeFileSync(parent, 'unrelated parent file')
96-
const result = run(root, ['--build'])
97-
expect(result.status, result.stderr).not.toBe(0)
98-
expect(readFileSync(parent, 'utf8')).toBe('unrelated parent file')
99-
expect(existsSync(join(outside, 'state'))).toBe(true)
100-
})
101-
102-
it('keeps the existing dev command scoped to dev state', () => {
48+
describe('dev cache maintenance through the real CLI', () => {
49+
it('prunes only dev state, never the build cache or other directories', () => {
10350
const { root, build, dev, outside } = fixture()
10451
expect(run(root, []).status).toBe(0)
10552
expect(existsSync(dev)).toBe(false)
@@ -126,25 +73,10 @@ describe('compiler cache maintenance through the real CLI', () => {
12673
}
12774
)
12875

129-
it('leaves both caches intact for a build dry run', () => {
76+
it('keeps dev state on a dry run over the cap', () => {
13077
const { root, build, dev } = fixture()
131-
expect(run(root, ['--build', '--dry-run']).status).toBe(0)
132-
expect(existsSync(join(build, 'state'))).toBe(true)
78+
expect(run(root, ['--dry-run']).status).toBe(0)
13379
expect(existsSync(join(dev, 'state'))).toBe(true)
80+
expect(existsSync(join(build, 'state'))).toBe(true)
13481
})
135-
136-
it.each([true, false])(
137-
'refuses a symlink build root when target existence is %s',
138-
(targetExists) => {
139-
const { root, build, dev, outside } = fixture()
140-
rmSync(build, { recursive: true })
141-
symlinkSync(outside, build, process.platform === 'win32' ? 'junction' : 'dir')
142-
if (!targetExists) rmSync(outside, { recursive: true })
143-
const result = run(root, ['--build', '--force'])
144-
expect(result.status, result.stderr).not.toBe(0)
145-
expect(lstatSync(build).isSymbolicLink()).toBe(true)
146-
expect(existsSync(join(outside, 'state'))).toBe(targetExists)
147-
expect(existsSync(join(dev, 'state'))).toBe(true)
148-
}
149-
)
15082
})

0 commit comments

Comments
 (0)