/** * Plain-Node CLI (no pnpm) — CI cascade rollup gate for the `checks` jobs of * ci-pr.yml and ci.yml (OPS64). * * Reads the commit statuses of the head sha via the Forgejo API and fails when * any of the workflow's own job statuses is failure/error (or the cascade * never settles / the read comes back empty). Replaces the old * `all(needs...)` jq, whose matrix parent result did not aggregate shards: * Forgejo 9.0.3 reports the LAST shard's result, so `checks` could post * SUCCESS with an e2e shard red (runs 604/607/610). The `needs..results` * array of GitHub does not exist in this runner. * * The job still runs only after every cascade job finished (`needs` + * `if: always()` in the workflow), so a green verdict means the whole cascade * settled green — the commit statuses are the same source waitForChecks * trusts for the merge. * * node scripts/ci-rollup-check.mjs \ * --sha \ * --prefix "CI (PR) / " \ * --own-prefix "CI (PR) / checks" \ * [--ignore-prefix "CI / deploy"] \ * [--allow-empty] */ import { rollupVerdict } from './lib/ci-rollup-check.mjs' import { createApi } from './lib/forgejo-api.mjs' const parseArgs = (argv) => { const flags = {} for (let index = 2; index < argv.length; index += 1) { const arg = argv[index] if (arg.startsWith('--')) { const name = arg.slice(2) const next = argv[index + 1] flags[name] = typeof next === 'string' && !next.startsWith('--') ? next : true if (typeof next === 'string' && !next.startsWith('--')) index += 1 } } return flags } const flags = parseArgs(process.argv) const sha = flags.sha const prefix = flags.prefix const ownPrefix = flags['own-prefix'] const ignorePrefixes = [flags['ignore-prefix']].filter(Boolean) const allowEmpty = flags['allow-empty'] === true || flags['allow-empty'] === 'true' if (!sha || !prefix || !ownPrefix) { console.error( 'Usage: node scripts/ci-rollup-check.mjs --sha --prefix --own-prefix [--ignore-prefix ] [--allow-empty]', ) process.exit(1) } const api = createApi({}) try { const statuses = await api.listCommitStatuses(sha) const verdict = rollupVerdict(statuses, { prefix, ownPrefix, ignorePrefixes, allowEmpty }) if (!verdict.ok) { console.error(`[ci-rollup-check] ${verdict.reason}`) process.exit(1) } console.log( `[ci-rollup-check] ${allowEmpty && statuses.length === 0 ? 'sem statuses (evento sem commit status) — ok' : 'cascata verde'}`, ) process.exit(0) } catch (error) { console.error(`[ci-rollup-check] falhou: ${error instanceof Error ? error.message : error}`) process.exit(1) }