mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 11:02:26 +00:00
fix(ci): reject release metadata option typos
This commit is contained in:
@@ -29,23 +29,28 @@ function readRefOptionValue(argv, index, optionName) {
|
||||
}
|
||||
|
||||
export function parseArgs(argv) {
|
||||
const separatorIndex = argv.indexOf("--");
|
||||
const flagArgv = separatorIndex === -1 ? argv : argv.slice(0, separatorIndex);
|
||||
const explicitPaths =
|
||||
separatorIndex === -1 ? [] : argv.slice(separatorIndex + 1).map(normalizePath);
|
||||
const args = { staged: false, base: "origin/main", head: "HEAD", paths: [] };
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (arg === "--") {
|
||||
continue;
|
||||
} else if (arg === "--staged") {
|
||||
for (let index = 0; index < flagArgv.length; index += 1) {
|
||||
const arg = flagArgv[index];
|
||||
if (arg === "--staged") {
|
||||
args.staged = true;
|
||||
} else if (arg === "--base") {
|
||||
args.base = readRefOptionValue(argv, index, arg);
|
||||
args.base = readRefOptionValue(flagArgv, index, arg);
|
||||
index += 1;
|
||||
} else if (arg === "--head") {
|
||||
args.head = readRefOptionValue(argv, index, arg);
|
||||
args.head = readRefOptionValue(flagArgv, index, arg);
|
||||
index += 1;
|
||||
} else if (arg.startsWith("-")) {
|
||||
throw new Error(`Unknown option: ${arg}`);
|
||||
} else {
|
||||
args.paths.push(normalizePath(arg));
|
||||
}
|
||||
}
|
||||
args.paths.push(...explicitPaths);
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -164,5 +169,10 @@ export function main(argv = process.argv.slice(2)) {
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(import.meta.filename)) {
|
||||
main();
|
||||
try {
|
||||
main();
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,17 @@ describe("check-release-metadata-only", () => {
|
||||
expect(() => parseArgs(["--head"])).toThrow("Expected --head <ref>.");
|
||||
expect(() => parseArgs(["--base", ""])).toThrow("Expected --base <ref>.");
|
||||
});
|
||||
|
||||
it("rejects unknown options before treating args as paths", () => {
|
||||
expect(() => parseArgs(["--stgaed"])).toThrow("Unknown option: --stgaed");
|
||||
});
|
||||
|
||||
it("preserves option-shaped paths after the separator", () => {
|
||||
expect(parseArgs(["--staged", "--", "--head"])).toEqual({
|
||||
staged: true,
|
||||
base: "origin/main",
|
||||
head: "HEAD",
|
||||
paths: ["--head"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user