mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* ci: run only the affected portable tests on pull requests Pull-request CI now runs static checks, the build and the portable tests a change affects, selected from test imports (through test-only helpers), same-stem and directory-scanning tests, leaf-owner boundary tests and tests that name a changed path. Shared boundaries, untraced inputs, empty selections and selections above 150 files fall back to the complete fast suite. Main pushes, schedules, releases and ci:full keep the complete suite. The portable report verifies the exact selected inventory and the CI required gate accepts a selected plan only for a fast pull request with code changes. * ci: own leaf-adapter tests by name and keep subset summaries diagnostic
80 lines
2.6 KiB
JavaScript
80 lines
2.6 KiB
JavaScript
import { spawn } from "node:child_process";
|
|
import { resolve } from "node:path";
|
|
|
|
import {
|
|
BUILT_TEST_PROJECTS,
|
|
SOURCE_TEST_PROJECTS,
|
|
} from "../lib/test-projects.mjs";
|
|
import { parseTestSelection, testShards } from "./test-selection.mjs";
|
|
|
|
const [group, ...arguments_] = process.argv.slice(2);
|
|
// The group owns project and file selection; callers can request reporters
|
|
// or (for project groups) shards.
|
|
if (
|
|
arguments_.some((argument) => /^--(?:project|exclude)(?:=|$)/u.test(argument))
|
|
)
|
|
throw new Error("Test groups cannot override their project inventory");
|
|
let runner;
|
|
let environment = process.env;
|
|
if (group === "selected") {
|
|
// `selected <k/n>` runs group k of the plan's selected test files, by exact
|
|
// identity, in whichever projects own them.
|
|
const [shard, ...rest] = arguments_;
|
|
const plan = parseTestSelection(process.env.CI_TEST_SELECTION ?? "");
|
|
if (plan.mode !== "selected" || !testShards("fast", plan).includes(shard))
|
|
throw new Error(`No selected test group ${shard ?? ""} in this plan`);
|
|
if (rest.some((argument) => /^--shard(?:=|$)/u.test(argument)))
|
|
throw new Error("Selected test groups are already sharded");
|
|
const index = Number(shard.split("/")[0]) - 1;
|
|
runner = [
|
|
resolve("scripts/run-exact-tests.mjs"),
|
|
"run",
|
|
...rest,
|
|
...plan.groups[index],
|
|
];
|
|
// Each group writes its own blob report for the merge.
|
|
environment = { ...process.env, VITEST_BLOB_LABEL: `selected-${index + 1}` };
|
|
} else {
|
|
const projects = {
|
|
source: SOURCE_TEST_PROJECTS,
|
|
built: BUILT_TEST_PROJECTS,
|
|
}[group];
|
|
if (!projects) throw new Error("Expected source, built or selected tests");
|
|
runner = [
|
|
resolve("node_modules/vitest/vitest.mjs"),
|
|
"run",
|
|
...projects.flatMap(({ name }) => ["--project", name]),
|
|
...arguments_,
|
|
];
|
|
}
|
|
const child = spawn(
|
|
process.execPath,
|
|
[
|
|
// Reuse the development runner's POSIX process-group owner. Windows
|
|
// source tests must remain usable without the built native Job Object.
|
|
...(process.platform === "win32"
|
|
? []
|
|
: [resolve("scripts/run-exclusive.mjs"), "--unlocked", process.execPath]),
|
|
...runner,
|
|
],
|
|
{ stdio: "inherit", env: environment },
|
|
);
|
|
let shutdownSignal;
|
|
for (const signal of ["SIGINT", "SIGTERM"])
|
|
process.on(signal, () => {
|
|
shutdownSignal ??= signal;
|
|
child.kill(signal);
|
|
});
|
|
child.once("error", (error) => {
|
|
console.error(error.message);
|
|
process.exitCode = 1;
|
|
});
|
|
child.once("close", (code) => {
|
|
process.exitCode =
|
|
shutdownSignal === "SIGINT"
|
|
? 130
|
|
: shutdownSignal === "SIGTERM"
|
|
? 143
|
|
: (code ?? 1);
|
|
});
|