Skip to content

Commit b28d038

Browse files
committed
fix: run workflow gates portably on Windows
1 parent b0485e6 commit b28d038

3 files changed

Lines changed: 58 additions & 20 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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();

mise.toml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,7 @@ run = "node tests/structure/check.mjs"
7878

7979
[tasks.workflows]
8080
description = "Compile, patch, lint, and test trusted workflow policy"
81-
run = """
82-
gh-aw compile --strict
83-
node .github/scripts/patch-gh-aw-lock.mjs
84-
if docker info >/dev/null 2>&1; then
85-
gh-aw lint
86-
else
87-
echo 'Docker unavailable; strict gh-aw compile completed (generated lint runs on Docker-capable matrix jobs).'
88-
fi
89-
find .github/workflows -name '*.yml' ! -name '*.lock.yml' -print0 | xargs -0 actionlint
90-
bun test tests/workflows
91-
if ! git diff --quiet -- .github/workflows/*.lock.yml .github/workflows/agentics-maintenance.yml; then
92-
echo 'Compiled gh-aw workflows are stale. Run mise run workflows and commit them.'
93-
git diff --stat -- .github/workflows/*.lock.yml .github/workflows/agentics-maintenance.yml
94-
exit 1
95-
fi
96-
"""
81+
run = "node .github/scripts/verify-workflows.mjs"
9782

9883
# ---- Convenience composites ------------------------------------------------
9984

tests/workflows/invariants.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ describe("Pi lockstep agentic workflows", () => {
102102
});
103103

104104
test("keeps workflow validation portable when Docker is unavailable", async () => {
105-
const source = await readFile(resolve(root, "mise.toml"), "utf8");
106-
expect(source).toContain("if docker info >/dev/null 2>&1; then");
107-
expect(source).toContain("gh-aw lint");
108-
expect(source).toContain("Docker unavailable; strict gh-aw compile completed");
105+
const mise = await readFile(resolve(root, "mise.toml"), "utf8");
106+
const runner = await readFile(
107+
resolve(root, ".github/scripts/verify-workflows.mjs"),
108+
"utf8",
109+
);
110+
expect(mise).toContain('run = "node .github/scripts/verify-workflows.mjs"');
111+
expect(runner).toContain('run("gh-aw", ["compile", "--strict"])');
112+
expect(runner).toContain('canRun("docker", ["info"])');
113+
expect(runner).toContain("Docker unavailable; strict gh-aw compile completed");
109114
});
110115

111116
test("serializes generated workflow writes before the full test suite", async () => {

0 commit comments

Comments
 (0)