mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 09:07:40 +00:00
* ci: run PR unit shards on free hosted ARM as 12 shards Enterprise's 1,000-job limit makes more, smaller shards free. A 12-shard cold run on ubuntu-24.04-arm measured 361s median / 412s max per shard, against ~390s / ~441s for five warm Blacksmith 8-vCPU shards. The Blacksmith-store module cache producer becomes dispatch-only since hosted shards cannot read it. * TEMP: force 12 shards on this PR (repo var is still 5); drop before merge * test: size the full-inventory routing check from FULL_SHARD_COUNT * Revert TEMP 12-shard override; the repository variable is now 12 --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
72 lines
2.6 KiB
JavaScript
72 lines
2.6 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 { FULL_SHARD_COUNT, planUnitSelection } from './ci-unit-selection.mjs'
|
|
import { readTimingBaseline, writeAssignment } from './ci-shard-assignment.mjs'
|
|
|
|
export function prepareUnitPlan(env = process.env) {
|
|
const requestedCount = env.ORCA_UNIT_FULL_SHARD_COUNT ?? String(FULL_SHARD_COUNT)
|
|
// Every consumer reads the count from the plan; sixteen bounds runner-slot use.
|
|
if (!/^([2-9]|1[0-6])$/.test(requestedCount)) {
|
|
throw new Error('ORCA_UNIT_FULL_SHARD_COUNT must be an integer from 2 to 16')
|
|
}
|
|
const fullShardCount = Number(requestedCount)
|
|
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: Array.from({ length: fullShardCount }, (_, index) => ({
|
|
index: index + 1,
|
|
count: fullShardCount
|
|
}))
|
|
}
|
|
}
|
|
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()
|
|
}
|