Files
orca/.github/scripts/check-required-pr-context.mjs
T
Neil 83dcc7dcb7 [CI] Reuse costly test setup and report an explicit full result (#29228)
* ci: publish an explicit result from the PR aggregate

* test(codex): preserve review text across OSC terminators

* perf(ci): reuse worker fixtures and validated launcher output

* fix(test): use typed orchestration database access

* fix(ci): exclude test fixtures from focus ratchet
2026-10-15 16:27:26 -07:00

37 lines
1.5 KiB
JavaScript

import { readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
export function verifyRequiredPrContext(parseYaml) {
const directory = '.github/workflows'
const providers = readdirSync(directory)
.filter((file) => /\.ya?ml$/.test(file))
.flatMap((file) => {
const workflow = parseYaml(readFileSync(join(directory, file), 'utf8'))
return Object.entries(workflow.jobs)
.filter(([id, job]) => (job.name ?? id) === 'PR checks passed')
.map(([id, job]) => ({ owner: `${file}:${id}`, job }))
})
const owners = providers.map((provider) => provider.owner)
if (providers.length !== 1 || owners[0] !== 'pr.yml:verify') {
throw new Error(`Required PR context must belong only to pr.yml:verify; found ${owners}`)
}
const gate = providers[0].job
const condition = gate.if?.replace(/^\$\{\{\s*|\s*\}\}$/g, '').trim()
if (condition !== '!cancelled()') {
throw new Error('Required PR aggregate must run unless the workflow is cancelled.')
}
if (gate['continue-on-error'] || gate.steps?.some((step) => step['continue-on-error'])) {
throw new Error('Required PR aggregate must not ignore failures.')
}
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const yaml = globalThis.Bun?.YAML
if (!yaml) {
throw new Error('Run workflow context validation with the pinned Bun runtime.')
}
verifyRequiredPrContext(yaml.parse)
console.log('Required PR check context verified.')
}