93 lines
2.1 KiB
JavaScript
93 lines
2.1 KiB
JavaScript
import path from "node:path";
|
|
|
|
import {
|
|
getChangedFiles,
|
|
selectSuitesForChangedFiles,
|
|
writeHarnessArtifact,
|
|
repoRoot
|
|
} from "./core.mjs";
|
|
|
|
function parseArgs(argv) {
|
|
const options = {
|
|
changedFiles: [],
|
|
from: null,
|
|
json: false,
|
|
to: null
|
|
};
|
|
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
const current = argv[index];
|
|
|
|
if (current === "--") {
|
|
continue;
|
|
}
|
|
|
|
if (current === "--json") {
|
|
options.json = true;
|
|
continue;
|
|
}
|
|
|
|
if (current === "--changed-file" || current === "--from" || current === "--to") {
|
|
const next = argv[index + 1];
|
|
|
|
if (!next) {
|
|
throw new Error(`Expected a value after ${current}.`);
|
|
}
|
|
|
|
if (current === "--changed-file") {
|
|
options.changedFiles.push(next);
|
|
} else if (current === "--from") {
|
|
options.from = next;
|
|
} else {
|
|
options.to = next;
|
|
}
|
|
|
|
index += 1;
|
|
continue;
|
|
}
|
|
|
|
throw new Error(`Unknown argument: ${current}`);
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|
|
const options = parseArgs(process.argv.slice(2));
|
|
const changedFiles = getChangedFiles(options);
|
|
const selection = selectSuitesForChangedFiles(changedFiles);
|
|
const reportPath = writeHarnessArtifact("selection", {
|
|
...selection,
|
|
selectedAt: new Date().toISOString()
|
|
});
|
|
|
|
if (options.json) {
|
|
process.stdout.write(
|
|
`${JSON.stringify({ ...selection, reportPath: path.relative(repoRoot, reportPath) }, null, 2)}\n`
|
|
);
|
|
process.exit(0);
|
|
}
|
|
|
|
process.stdout.write(`Harness selection report written to ${path.relative(repoRoot, reportPath)}\n`);
|
|
|
|
if (selection.suites.length === 0) {
|
|
process.stdout.write("No harness suites selected for the current diff.\n");
|
|
} else {
|
|
process.stdout.write("Selected harness suites:\n");
|
|
|
|
for (const suiteName of selection.suites) {
|
|
process.stdout.write(`- ${suiteName}\n`);
|
|
|
|
for (const reason of selection.reasons[suiteName] ?? []) {
|
|
process.stdout.write(` - ${reason.file}: ${reason.reason}\n`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (selection.unmatchedFiles.length > 0) {
|
|
process.stdout.write("Unmatched files:\n");
|
|
|
|
for (const filePath of selection.unmatchedFiles) {
|
|
process.stdout.write(`- ${filePath}\n`);
|
|
}
|
|
}
|