mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-03 15:27:56 +01:00
* pregate: gstack declares remote_gate_runs, so a green Free Tests run at the pregate tree clears remote_gate (GST-1024) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes (GST-1024: refuse a paid-only selection; validate skipped) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(changelog): GST-1024 entry names all four tests Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
51 lines
3.4 KiB
TypeScript
51 lines
3.4 KiB
TypeScript
/**
|
|
* The run-evidence inputs one consumer needs (GSTA-156): the base branch's run
|
|
* profiles, this repository on GitHub, the verifier's gh- and git-backed
|
|
* dependencies, and the remote gate's inventory and skipped commands (pin-file
|
|
* commands, so they run only with --allow-repo-commands; skipped reads the
|
|
* selected files from PREGATE_FILES_FILE). Shared by `gstack-pregate
|
|
* clear` and `gstack-pregate --from-run`, so both read profiles from the
|
|
* base and nowhere else.
|
|
*/
|
|
import { spawnSync } from 'node:child_process';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
import { ghRunDeps, runInventory } from '../run-evidence';
|
|
import { wtreeFingerprint } from '../script-invocation';
|
|
import { resolveBaseBranch } from '../ship-policy';
|
|
import { normalizeRemoteUrl } from '../ship-queue-train-record';
|
|
import { REMOTE_GATE_LANE } from './checks/lanes';
|
|
import { PREGATE_CONFIG_PATH, isConfigUnavailable, loadConfigFromBase } from './config';
|
|
import type { RunCheck } from './index';
|
|
|
|
/**
|
|
* `profiled` says whether `lane` may have a run profile: an unreadable base counts as profiled, so a lane is
|
|
* recorded unverified only once the base shows it has none.
|
|
*/
|
|
export function buildRunCheck(root: string, lane: string | null, allowRepoCommands: boolean, base = resolveBaseBranch(root)): RunCheck | { error: string; profiled?: boolean } {
|
|
const loaded = loadConfigFromBase(root, base);
|
|
if (isConfigUnavailable(loaded)) return { error: `the base branch's ${PREGATE_CONFIG_PATH} is unreadable (${loaded.detail}); run profiles come only from the base`, profiled: true };
|
|
if (loaded.errors.length) return { error: `the base branch's ${PREGATE_CONFIG_PATH} is invalid: ${loaded.errors.map(e => `${e.path}: ${e.message}`).join('; ')}`, profiled: true };
|
|
const origin = spawnSync('git', ['config', '--get', 'remote.origin.url'], { cwd: root, encoding: 'utf8', timeout: 30_000 });
|
|
const repo = /^https:\/\/github\.com\/(.+)$/.exec(normalizeRemoteUrl(origin.status === 0 ? origin.stdout.trim() : ''))?.[1];
|
|
if (!repo) return { error: 'origin is not a github.com repository; run evidence is read from GitHub Actions', profiled: lane === null ? false : lane === REMOTE_GATE_LANE ? !!loaded.config.remote_gate_runs : !!loaded.config.run_profiles[lane] };
|
|
return {
|
|
repo, deps: ghRunDeps(repo, root), profiles: loaded.config.run_profiles, gateRuns: loaded.config.remote_gate_runs, now: new Date(),
|
|
inventory: (command, tree, selected) => {
|
|
if (!allowRepoCommands) return { error: 'the inventory command is a pin-file command; pass --allow-repo-commands' };
|
|
const at = () => { const fp = wtreeFingerprint({ cwd: root }); return 'tree' in fp ? fp.tree : null; };
|
|
if (at() !== tree) return { error: `the working tree is not pregate.json's tree ${tree.slice(0, 12)}; the inventory must list that tree's gate files` };
|
|
const dir = selected && fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-pregate-skipped-'));
|
|
try {
|
|
if (dir) fs.writeFileSync(path.join(dir, 'selected.txt'), selected!.map(f => `${f}\n`).join(''));
|
|
const listed = runInventory(command, root, dir ? { PREGATE_FILES_FILE: path.join(dir, 'selected.txt') } : undefined);
|
|
if (at() !== tree) return { error: `the working tree changed while ${command} ran` };
|
|
return listed;
|
|
} finally {
|
|
if (dir) fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
},
|
|
};
|
|
}
|