Files
orca/config/scripts/ci-unit-plan.mjs
T
NeilandCopilot ac91ff6b05 perf(ci): start full unit shards before advisory selection analysis (#37699)
Emit the full matrix without dependency installation or graph discovery; retain independent full test discovery and selected-draft provenance. Reuse existing draft plans, and disable unpublished transform writes on warm misses. Automatic cache production was removed after review because the near-quota cache store has no budgeted retention plan. Full required PR CI passed on 658ea5275c.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-02 23:32:32 -08:00

66 lines
2.2 KiB
JavaScript

import { appendFileSync } from 'node:fs'
import { pathToFileURL } from 'node:url'
import { runProcessSync } from '@orca/process-host'
import { collectUnitDependencyGraph } from './ci-unit-dependency-graph.mjs'
import { discoverUnitFiles } from './ci-unit-files.mjs'
import { planUnitSelection } from './ci-unit-selection.mjs'
import { fullUnitMatrix } from './ci-unit-matrix.mjs'
import { readTimingBaseline, writeAssignment } from './ci-shard-assignment.mjs'
export function prepareUnitPlan(env = process.env) {
const shards = fullUnitMatrix(env.ORCA_UNIT_FULL_SHARD_COUNT)
const fullShardCount = shards.length
const files = discoverUnitFiles()
let plan
try {
// From the workflow, not the payload file: background steps can read it mid-rewrite.
const event = { pull_request: { draft: env.ORCA_PULL_REQUEST_DRAFT === 'true' } }
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,
fullShardCount
})
} catch (error) {
plan = {
version: 1,
mode: 'shadow',
selectionAvailable: false,
reason: String(error),
files,
candidateFiles: files,
executionFiles: files,
shards
}
}
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()
}