mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
refactor(test): split docker e2e planner
This commit is contained in:
86
scripts/docker-e2e.mjs
Normal file
86
scripts/docker-e2e.mjs
Normal file
@@ -0,0 +1,86 @@
|
||||
// Docker E2E CI helper.
|
||||
// Converts scheduler JSON into GitHub Actions outputs and compact markdown
|
||||
// summaries so the workflow does not duplicate Docker E2E planning logic.
|
||||
import fs from "node:fs";
|
||||
|
||||
function usage() {
|
||||
return [
|
||||
"Usage:",
|
||||
" node scripts/docker-e2e.mjs github-outputs <plan.json>",
|
||||
" node scripts/docker-e2e.mjs summary <summary.json> <title>",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function readJson(file) {
|
||||
return JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
}
|
||||
|
||||
function boolOutput(value) {
|
||||
return value ? "1" : "0";
|
||||
}
|
||||
|
||||
function githubOutputs(plan) {
|
||||
const needs = plan.needs ?? {};
|
||||
return [
|
||||
`credentials=${(plan.credentials ?? []).join(",")}`,
|
||||
`needs_bare_image=${boolOutput(needs.bareImage)}`,
|
||||
`needs_e2e_image=${boolOutput(needs.e2eImage)}`,
|
||||
`needs_functional_image=${boolOutput(needs.functionalImage)}`,
|
||||
`needs_live_image=${boolOutput(needs.liveImage)}`,
|
||||
`needs_package=${boolOutput(needs.package)}`,
|
||||
];
|
||||
}
|
||||
|
||||
function markdownCell(value) {
|
||||
return String(value ?? "").replaceAll("|", "\\|");
|
||||
}
|
||||
|
||||
function inlineCode(value) {
|
||||
return `\`${String(value ?? "").replaceAll("`", "\\`")}\``;
|
||||
}
|
||||
|
||||
function summaryMarkdown(summary, title) {
|
||||
const lanes = Array.isArray(summary.lanes) ? summary.lanes : [];
|
||||
const lines = [
|
||||
`### ${title}`,
|
||||
"",
|
||||
`Status: ${inlineCode(summary.status)}`,
|
||||
"",
|
||||
"| Lane | Status | Seconds | Timed out | Rerun |",
|
||||
"| --- | ---: | ---: | --- | --- |",
|
||||
];
|
||||
for (const lane of lanes) {
|
||||
const status = lane.status === 0 ? "pass" : `fail ${lane.status}`;
|
||||
lines.push(
|
||||
`| ${inlineCode(lane.name)} | ${markdownCell(status)} | ${markdownCell(lane.elapsedSeconds)} | ${lane.timedOut ? "yes" : "no"} | ${inlineCode(lane.rerunCommand)} |`,
|
||||
);
|
||||
}
|
||||
|
||||
const phases = Array.isArray(summary.phases) ? summary.phases : [];
|
||||
if (phases.length > 0) {
|
||||
lines.push("", "| Phase | Seconds | Status | Image kind |", "| --- | ---: | --- | --- |");
|
||||
for (const phase of phases) {
|
||||
lines.push(
|
||||
`| ${inlineCode(phase.name)} | ${markdownCell(phase.elapsedSeconds)} | ${markdownCell(phase.status)} | ${markdownCell(phase.imageKind)} |`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
const [command, file, ...args] = process.argv.slice(2);
|
||||
if (!command || !file) {
|
||||
throw new Error(usage());
|
||||
}
|
||||
|
||||
if (command === "github-outputs") {
|
||||
process.stdout.write(`${githubOutputs(readJson(file)).join("\n")}\n`);
|
||||
} else if (command === "summary") {
|
||||
const title = args.join(" ").trim();
|
||||
if (!title) {
|
||||
throw new Error(usage());
|
||||
}
|
||||
process.stdout.write(`${summaryMarkdown(readJson(file), title)}\n`);
|
||||
} else {
|
||||
throw new Error(`unknown command: ${command}\n${usage()}`);
|
||||
}
|
||||
Reference in New Issue
Block a user