mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
fix(package): require docker package option values
This commit is contained in:
@@ -60,7 +60,22 @@ function resolveTimeoutMs(envName, defaultValue) {
|
||||
return Math.trunc(parsed);
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
function readOptionValue(argv, index, optionName) {
|
||||
const value = argv[index + 1];
|
||||
if (value === undefined || value === "" || value.startsWith("--")) {
|
||||
throw new Error(`${optionName} requires a value`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function readEqualsOptionValue(value, optionName) {
|
||||
if (value === "" || value.startsWith("--")) {
|
||||
throw new Error(`${optionName} requires a value`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseArgs(argv) {
|
||||
const options = {
|
||||
outputDir: "",
|
||||
outputName: "",
|
||||
@@ -70,19 +85,25 @@ function parseArgs(argv) {
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (arg === "--output-dir") {
|
||||
options.outputDir = argv[(index += 1)] ?? "";
|
||||
options.outputDir = readOptionValue(argv, index, arg);
|
||||
index += 1;
|
||||
} else if (arg?.startsWith("--output-dir=")) {
|
||||
options.outputDir = arg.slice("--output-dir=".length);
|
||||
options.outputDir = readEqualsOptionValue(arg.slice("--output-dir=".length), "--output-dir");
|
||||
} else if (arg === "--output-name") {
|
||||
options.outputName = argv[(index += 1)] ?? "";
|
||||
options.outputName = readOptionValue(argv, index, arg);
|
||||
index += 1;
|
||||
} else if (arg?.startsWith("--output-name=")) {
|
||||
options.outputName = arg.slice("--output-name=".length);
|
||||
options.outputName = readEqualsOptionValue(
|
||||
arg.slice("--output-name=".length),
|
||||
"--output-name",
|
||||
);
|
||||
} else if (arg === "--skip-build") {
|
||||
options.skipBuild = true;
|
||||
} else if (arg === "--source-dir") {
|
||||
options.sourceDir = argv[(index += 1)] ?? "";
|
||||
options.sourceDir = readOptionValue(argv, index, arg);
|
||||
index += 1;
|
||||
} else if (arg?.startsWith("--source-dir=")) {
|
||||
options.sourceDir = arg.slice("--source-dir=".length);
|
||||
options.sourceDir = readEqualsOptionValue(arg.slice("--source-dir=".length), "--source-dir");
|
||||
} else {
|
||||
throw new Error(`unknown argument: ${arg}`);
|
||||
}
|
||||
@@ -155,16 +176,13 @@ function run(command, args, cwd, options = {}) {
|
||||
};
|
||||
const terminateChild = () => {
|
||||
killChild("SIGTERM");
|
||||
forceKillTimeout = setTimeout(
|
||||
() => {
|
||||
forceKillTimeout = undefined;
|
||||
if (settled && !processGroupAlive()) {
|
||||
return;
|
||||
}
|
||||
killChild("SIGKILL");
|
||||
},
|
||||
options.killAfterMs ?? DEFAULT_TIMEOUT_KILL_AFTER_MS,
|
||||
);
|
||||
forceKillTimeout = setTimeout(() => {
|
||||
forceKillTimeout = undefined;
|
||||
if (settled && !processGroupAlive()) {
|
||||
return;
|
||||
}
|
||||
killChild("SIGKILL");
|
||||
}, options.killAfterMs ?? DEFAULT_TIMEOUT_KILL_AFTER_MS);
|
||||
forceKillTimeout.unref?.();
|
||||
};
|
||||
ACTIVE_CHILD_KILLERS.add(killChild);
|
||||
|
||||
@@ -8,6 +8,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildPackageArtifacts,
|
||||
packOpenClawPackageForDocker,
|
||||
parseArgs,
|
||||
runCommandForTest,
|
||||
} from "../../scripts/package-openclaw-for-docker.mjs";
|
||||
|
||||
@@ -69,6 +70,32 @@ async function waitForExit(
|
||||
}
|
||||
|
||||
describe("package-openclaw-for-docker", () => {
|
||||
it("parses package artifact output options", () => {
|
||||
expect(
|
||||
parseArgs([
|
||||
"--output-dir",
|
||||
".artifacts/docker",
|
||||
"--output-name=openclaw-current.tgz",
|
||||
"--source-dir",
|
||||
"/repo",
|
||||
"--skip-build",
|
||||
]),
|
||||
).toEqual({
|
||||
outputDir: ".artifacts/docker",
|
||||
outputName: "openclaw-current.tgz",
|
||||
skipBuild: true,
|
||||
sourceDir: "/repo",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects missing package artifact option values", () => {
|
||||
for (const flag of ["--output-dir", "--output-name", "--source-dir"]) {
|
||||
expect(() => parseArgs([flag])).toThrow(`${flag} requires a value`);
|
||||
expect(() => parseArgs([flag, "--skip-build"])).toThrow(`${flag} requires a value`);
|
||||
expect(() => parseArgs([`${flag}=`])).toThrow(`${flag} requires a value`);
|
||||
}
|
||||
});
|
||||
|
||||
it("uses build-all as the single bounded package artifact build step", async () => {
|
||||
const calls: Array<{
|
||||
command: string;
|
||||
|
||||
Reference in New Issue
Block a user