teqo-backup/scripts/test-affected.mjs
Francisco Ignácio Fontoura Solla 9d810d1564 ci(pr): cascade phase1→phase2 with blast-radius skips
Add scope classifiers for code/build jobs, always-on test-location
guardrails, and gate:ci parity. Default affected base is origin/main.
2026-07-31 20:57:18 -03:00

39 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
/**
* test-affected (OPS5) — decides the vitest scope for a PR diff and prints it
* as JSON on stdout: { mode, reason, base }.
*
* mode=full → run the whole suite (high-risk path / new src file)
* mode=changed → run `vitest --changed <base>`
* mode=none → nothing to run (docs-only diff); CI skips the step
*
* Base ref: $GITHUB_BASE_REF (PR target) or origin/main locally. No DB, no
* Payload — pure git + the pure core in scripts/lib/test-affected-core.mjs.
*/
import { execFileSync } from 'node:child_process'
import { classifyTestScope } from './lib/test-affected-core.mjs'
const base = `origin/${process.env.GITHUB_BASE_REF ?? 'main'}`
let mergeBase
try {
mergeBase = execFileSync('git', ['merge-base', 'HEAD', base], { encoding: 'utf8' }).trim()
} catch {
const result = { mode: 'full', reason: `no merge-base with ${base} (shallow clone?)`, base }
console.log(JSON.stringify(result))
process.exit(0)
}
const raw = execFileSync('git', ['diff', '--name-status', `${mergeBase}...HEAD`], {
encoding: 'utf8',
})
const files = raw
.split('\n')
.filter(Boolean)
.map((line) => {
const [status, path] = line.split('\t')
return { status, path }
})
console.log(JSON.stringify({ ...classifyTestScope(files), base }))