fix(ci): reject release metadata option typos

This commit is contained in:
Vincent Koc
2026-06-20 20:31:54 +02:00
parent d368fd620c
commit c2433d41a7
2 changed files with 31 additions and 8 deletions

View File

@@ -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);
}
}

View File

@@ -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"],
});
});
});