|
| 1 | +import { spawnSync } from "node:child_process"; |
| 2 | +import { readdir } from "node:fs/promises"; |
| 3 | +import { resolve } from "node:path"; |
| 4 | + |
| 5 | +const root = resolve(import.meta.dirname, "../.."); |
| 6 | +const generated = [ |
| 7 | + ".github/workflows/pi-runtime-review.lock.yml", |
| 8 | + ".github/workflows/pi-upstream-lockstep.lock.yml", |
| 9 | + ".github/workflows/agentics-maintenance.yml", |
| 10 | +]; |
| 11 | + |
| 12 | +function result(command, args, stdio = "inherit") { |
| 13 | + return spawnSync(command, args, { cwd: root, stdio, env: process.env }); |
| 14 | +} |
| 15 | + |
| 16 | +function run(command, args) { |
| 17 | + const child = result(command, args); |
| 18 | + if (child.error) throw child.error; |
| 19 | + if (child.status !== 0) process.exit(child.status ?? 1); |
| 20 | +} |
| 21 | + |
| 22 | +function canRun(command, args) { |
| 23 | + const child = result(command, args, "ignore"); |
| 24 | + return !child.error && child.status === 0; |
| 25 | +} |
| 26 | + |
| 27 | +async function conventionalWorkflows() { |
| 28 | + const directory = resolve(root, ".github/workflows"); |
| 29 | + const files = await readdir(directory); |
| 30 | + return files |
| 31 | + .filter((file) => file.endsWith(".yml") && !file.endsWith(".lock.yml")) |
| 32 | + .map((file) => `.github/workflows/${file}`); |
| 33 | +} |
| 34 | + |
| 35 | +function verifyGeneratedFiles() { |
| 36 | + if (canRun("git", ["diff", "--quiet", "--", ...generated])) return; |
| 37 | + console.error("Compiled gh-aw workflows are stale. Run mise run workflows and commit them."); |
| 38 | + run("git", ["diff", "--stat", "--", ...generated]); |
| 39 | + process.exit(1); |
| 40 | +} |
| 41 | + |
| 42 | +run("gh-aw", ["compile", "--strict"]); |
| 43 | +run(process.execPath, [".github/scripts/patch-gh-aw-lock.mjs"]); |
| 44 | +if (canRun("docker", ["info"])) run("gh-aw", ["lint"]); |
| 45 | +else console.log("Docker unavailable; strict gh-aw compile completed (generated lint runs on Docker-capable matrix jobs)."); |
| 46 | +run("actionlint", await conventionalWorkflows()); |
| 47 | +run("bun", ["test", "tests/workflows"]); |
| 48 | +verifyGeneratedFiles(); |
0 commit comments