Files
orca/config/scripts/ci-unit-plan.mjs
T
Neil f8f656ca19 perf(ci): spend fewer concurrency slots per pull request (#23810)
A concurrency slot is charged per job, not per core, and the account's cap is
the scarce resource: standard runner minutes are free and unlimited on a public
repository. Two paths spent slots that bought nothing.

The unit matrix ran eight fixed shards averaging 6.5 minutes each, 3384
job-slots a day and 68% of all slot demand, while the arm pool queued 10.5
minutes at p95 — the queue was the oversharding. Five shards run the same work
in ~10.5 minutes each for three fewer slots per run.

Bun profile persistence escalated to all six platforms on `config/`,
`resources/` and `.github/` wholesale, which took 36.5% of the last 1100
commits through the full matrix where a platform-flavoured predicate takes 19%.
A pull request now qualifies one platform unless the change is platform-
flavoured, and the push to main re-qualifies all six, so an unescalated miss
surfaces minutes after merge rather than at the next cron. Missing changed-file
evidence and an unavailable dependency graph still fail closed to all six.
2026-09-29 00:13:33 -07:00

64 lines
2.1 KiB
JavaScript

import { appendFileSync, readFileSync } from 'node:fs'
import { pathToFileURL } from 'node:url'
import { runProcessSync } from './script-child-process.mjs'
import { collectUnitDependencyGraph } from './ci-unit-dependency-graph.mjs'
import { discoverUnitFiles } from './ci-unit-files.mjs'
import { FULL_SHARD_COUNT, planUnitSelection } from './ci-unit-selection.mjs'
import { readTimingBaseline, writeAssignment } from './ci-shard-assignment.mjs'
export function prepareUnitPlan(env = process.env) {
const files = discoverUnitFiles()
let plan
try {
const event = JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, 'utf8'))
if (env.GITHUB_EVENT_NAME !== 'pull_request') {
throw new Error('Full reference run')
}
const diff = runProcessSync({
program: 'git',
args: ['diff', '--name-only', '--no-renames', '-z', 'HEAD^1', 'HEAD'],
maxOutputBytes: 16 * 1024 * 1024
})
if (diff.code !== 0 || diff.timedOut) {
throw new Error('Changed paths unavailable')
}
plan = planUnitSelection({
files,
changed: diff.stdout.split('\0').filter(Boolean),
graph: collectUnitDependencyGraph(),
timings: readTimingBaseline('unit').timings,
event,
mode: env.ORCA_UNIT_SELECTION_MODE
})
} catch (error) {
plan = {
version: 1,
mode: 'shadow',
selectionAvailable: false,
reason: String(error),
files,
candidateFiles: files,
executionFiles: files,
shards: Array.from({ length: FULL_SHARD_COUNT }, (_, index) => ({
index: index + 1,
count: FULL_SHARD_COUNT
}))
}
}
writeAssignment('ci-shards/unit-selection.json', plan)
if (env.GITHUB_OUTPUT) {
appendFileSync(env.GITHUB_OUTPUT, `shards=${JSON.stringify(plan.shards)}\n`)
}
if (env.GITHUB_STEP_SUMMARY) {
appendFileSync(
env.GITHUB_STEP_SUMMARY,
`Unit selection: **${plan.mode}**; ${plan.candidateFiles.length}/${files.length} candidate files; ${plan.shards.length} execution shards. ${plan.reason}\n`
)
}
return plan
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
prepareUnitPlan()
}