fix: target hwlab v02 pipelinerun cleanup

This commit is contained in:
Codex
2026-06-05 09:58:34 +00:00
parent 9919d86dbf
commit 096eb0cb9d
2 changed files with 41 additions and 8 deletions
+4 -2
View File
@@ -37,8 +37,10 @@ assertCondition(
hwlabHelpUsage.some((line) => line.includes("control-plane status --lane v02 --pipeline-run"))
&& hwlabHelpUsage.some((line) => line.includes("control-plane status --lane v02 --source-commit"))
&& hwlabHelpUsage.some((line) => line.includes("control-plane closeout --lane v02 --pipeline-run"))
&& hwlabHelpUsage.some((line) => line.includes("control-plane closeout --lane v02 --source-commit")),
"v0.2 control-plane help must expose targeted PipelineRun/source-commit status and closeout inspection",
&& hwlabHelpUsage.some((line) => line.includes("control-plane closeout --lane v02 --source-commit"))
&& hwlabHelpUsage.some((line) => line.includes("control-plane cleanup-runs --lane v02 --pipeline-run"))
&& hwlabHelpUsage.some((line) => line.includes("control-plane cleanup-runs --lane v02 --source-commit")),
"v0.2 control-plane help must expose targeted PipelineRun/source-commit status, closeout inspection, and cleanup",
hwlabHelpUsage,
);
assertCondition(
+37 -6
View File
@@ -360,13 +360,13 @@ function parseControlPlaneOptions(args: string[]): G14ControlPlaneOptions {
if (allowLiveDbRead && actionRaw !== "runtime-migration") throw new Error("--allow-live-db-read is only valid for control-plane runtime-migration");
const sourceCommitRaw = optionValue(args, "--source-commit");
const pipelineRunRaw = optionValue(args, "--pipeline-run");
if ((sourceCommitRaw !== undefined || pipelineRunRaw !== undefined) && actionRaw !== "status" && actionRaw !== "closeout") {
throw new Error("--source-commit and --pipeline-run are only valid for control-plane status/closeout");
if ((sourceCommitRaw !== undefined || pipelineRunRaw !== undefined) && actionRaw !== "status" && actionRaw !== "closeout" && actionRaw !== "cleanup-runs") {
throw new Error("--source-commit and --pipeline-run are only valid for control-plane status/closeout/cleanup-runs");
}
if (actionRaw === "closeout" && sourceCommitRaw === undefined && pipelineRunRaw === undefined) {
throw new Error("control-plane closeout requires --source-commit <full-sha> or --pipeline-run hwlab-v02-ci-poll-<sha>");
}
if (sourceCommitRaw !== undefined && pipelineRunRaw !== undefined) throw new Error("control-plane status/closeout accepts only one of --source-commit or --pipeline-run");
if (sourceCommitRaw !== undefined && pipelineRunRaw !== undefined) throw new Error("control-plane status/closeout/cleanup-runs accepts only one of --source-commit or --pipeline-run");
return {
action: actionRaw,
lane,
@@ -2206,9 +2206,10 @@ function listCleanupPipelineRuns(options: G14ControlPlaneOptions): Record<string
if (!isCommandSuccess(result)) {
throw new Error(`failed to list hwlab-ci PipelineRuns: ${commandErrorSummary(result)}`);
}
const targetPipelineRun = options.pipelineRun ?? (options.sourceCommit === undefined ? undefined : v02PipelineRunName(options.sourceCommit));
const prefixes = pipelinePrefixesForLane(options.lane);
const now = Date.now();
return statusText(result)
const candidates = statusText(result)
.split(/\r?\n/u)
.map((line) => line.trim())
.filter(Boolean)
@@ -2219,10 +2220,22 @@ function listCleanupPipelineRuns(options: G14ControlPlaneOptions): Record<string
return { name, createdAt, ageMinutes, status: status || null, reason: reason || null };
})
.filter((item) => item.name.length > 0 && prefixes.some((prefix) => item.name.startsWith(prefix)))
.filter((item) => targetPipelineRun === undefined || item.name === targetPipelineRun)
.filter((item) => item.status === "True" || item.status === "False")
.filter((item) => typeof item.ageMinutes === "number" && item.ageMinutes >= options.minAgeMinutes)
.sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)))
.slice(0, options.limit);
if (targetPipelineRun !== undefined && candidates.length === 0) {
return [{
name: targetPipelineRun,
createdAt: null,
ageMinutes: null,
status: null,
reason: "target-pipelinerun-not-found-or-not-terminal",
selected: false,
}];
}
return candidates;
}
function listOwnedWorkspacePvcs(pipelineRunNames: string[]): Record<string, unknown>[] {
@@ -2412,7 +2425,9 @@ function runV02RuntimeMigration(options: G14ControlPlaneOptions, sourceCommit: s
function runControlPlaneCleanup(options: G14ControlPlaneOptions): Record<string, unknown> {
const candidates = listCleanupPipelineRuns(options);
const candidateNames = candidates.map((item) => String(item.name));
const candidateNames = candidates
.filter((item) => item.selected !== false)
.map((item) => String(item.name));
const ownedPvcs = listOwnedWorkspacePvcs(candidateNames);
if (options.dryRun) {
return {
@@ -2422,12 +2437,24 @@ function runControlPlaneCleanup(options: G14ControlPlaneOptions): Record<string,
lane: options.lane,
minAgeMinutes: options.minAgeMinutes,
limit: options.limit,
sourceCommit: options.sourceCommit,
pipelineRun: options.pipelineRun,
candidates,
candidateCount: candidates.length,
selectedPipelineRuns: candidateNames,
selectedPipelineRunCount: candidateNames.length,
ownedPvcs,
ownedPvcCount: ownedPvcs.length,
mutation: false,
next: { confirm: `bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane ${options.lane} --min-age-minutes ${options.minAgeMinutes} --limit ${options.limit} --confirm` },
next: { confirm: [
"bun scripts/cli.ts hwlab g14 control-plane cleanup-runs",
`--lane ${options.lane}`,
`--min-age-minutes ${options.minAgeMinutes}`,
`--limit ${options.limit}`,
options.pipelineRun === undefined ? "" : `--pipeline-run ${options.pipelineRun}`,
options.sourceCommit === undefined ? "" : `--source-commit ${options.sourceCommit}`,
"--confirm",
].filter(Boolean).join(" ") },
};
}
const deletion = deletePipelineRuns(candidateNames, options.timeoutSeconds * 1000);
@@ -2438,6 +2465,8 @@ function runControlPlaneCleanup(options: G14ControlPlaneOptions): Record<string,
lane: options.lane,
minAgeMinutes: options.minAgeMinutes,
limit: options.limit,
sourceCommit: options.sourceCommit,
pipelineRun: options.pipelineRun,
deletedPipelineRuns: candidateNames,
deletedPipelineRunCount: candidateNames.length,
ownedPvcsBefore: ownedPvcs,
@@ -7419,6 +7448,8 @@ export function hwlabG14Help(): Record<string, unknown> {
"bun scripts/cli.ts hwlab g14 control-plane trigger-current --lane v02 --confirm --wait",
"bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --min-age-minutes 30 --limit 20 --dry-run",
"bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --min-age-minutes 30 --limit 20 --confirm",
"bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --pipeline-run hwlab-v02-ci-poll-<short-sha> --dry-run",
"bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --source-commit <full-sha> --confirm",
"bun scripts/cli.ts hwlab g14 control-plane cleanup-released-pvs --lane all --limit 20 --dry-run",
"bun scripts/cli.ts hwlab g14 control-plane cleanup-released-pvs --lane all --limit 20 --confirm",
"bun scripts/cli.ts hwlab g14 control-plane runtime-migration --lane v02 --dry-run",