Files
redwoodjs__local-ci/scripts/rust-smoke-parity.mjs
2026-05-24 13:56:09 +02:00

83 lines
3.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const rustBin = path.join(root, "target", "debug", "agent-ci");
const smokeWorkDir = fs.mkdtempSync(path.join(os.tmpdir(), "agent-ci-rust-smoke-"));
const smokeWorkflows = [
{ path: ".github/workflows/smoke-binary.yml" },
{ path: ".github/workflows/smoke-expressions.yml" },
{ path: ".github/workflows/smoke-matrix.yml" },
{ path: ".github/workflows/smoke-artifacts.yml" },
{ path: ".github/workflows/smoke-docker-buildx.yml" },
{ path: ".github/workflows/smoke-pause-pipe.yml" },
];
function run(command, args, options = {}) {
return spawnSync(command, args, {
cwd: options.cwd ?? root,
encoding: "utf8",
env: { ...process.env, ...options.env },
stdio: options.stdio ?? "pipe",
});
}
const build = run("cargo", ["build", "-p", "agent-ci"], { stdio: "inherit" });
if (build.status !== 0) {
process.exit(build.status ?? 1);
}
for (const workflow of smokeWorkflows) {
const workflowWorkDir = path.join(smokeWorkDir, workflow.path.replaceAll(/[^a-zA-Z0-9]+/g, "-"));
const result = run(rustBin, ["run", "--workflow", workflow.path, "--quiet", "--jobs", "2"], {
env: { AGENT_CI_WORKING_DIR: workflowWorkDir },
});
if (result.status !== 0) {
throw new Error(
`${workflow.path}: expected Rust smoke execution to succeed, got ${result.status}\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`,
);
}
if (result.stderr.includes("Rust workflow execution is not implemented yet")) {
throw new Error(
`${workflow.path}: Rust execution still reports the tracked gap\n${result.stderr}`,
);
}
console.log(`✓ ${workflow.path} executed successfully`);
}
const allRepo = path.join(smokeWorkDir, "all-mode-repo");
fs.mkdirSync(path.join(allRepo, ".github/workflows"), { recursive: true });
run("git", ["init"], { cwd: allRepo });
fs.writeFileSync(path.join(allRepo, "README.md"), "all smoke\n");
fs.writeFileSync(
path.join(allRepo, ".github/workflows/one.yml"),
"on: workflow_dispatch\njobs:\n one:\n runs-on: ubuntu-latest\n steps:\n - run: echo one\n",
);
fs.writeFileSync(
path.join(allRepo, ".github/workflows/two.yml"),
"on: workflow_dispatch\njobs:\n two:\n runs-on: ubuntu-latest\n steps:\n - run: echo two\n",
);
run("git", ["add", "."], { cwd: allRepo });
run("git", ["-c", "user.email=test@example.com", "-c", "user.name=Test", "commit", "-m", "init"], {
cwd: allRepo,
});
const allResult = spawnSync(rustBin, ["run", "--all", "--quiet", "--jobs", "2"], {
cwd: allRepo,
encoding: "utf8",
env: {
...process.env,
AGENT_CI_WORKING_DIR: path.join(smokeWorkDir, "all-mode-work"),
},
stdio: "pipe",
});
if (allResult.status !== 0) {
throw new Error(
`--all smoke: expected Rust execution to succeed, got ${allResult.status}\nstdout:\n${allResult.stdout}\nstderr:\n${allResult.stderr}`,
);
}
console.log("✓ --all smoke executed successfully");