fix: recheck hwlab v02 head before reuse
This commit is contained in:
+97
-16
@@ -672,6 +672,36 @@ function v02PipelineRunName(sourceCommit: string): string {
|
||||
return `${V02_PIPELINERUN_PREFIX}-${shortSha(sourceCommit)}`;
|
||||
}
|
||||
|
||||
export function v02ExistingPipelineRunReuseDecision(input: {
|
||||
sourceCommit: string;
|
||||
before: Record<string, unknown>;
|
||||
latestSourceCommit: string | null;
|
||||
}): Record<string, unknown> {
|
||||
const status = stringOrNull(input.before.status);
|
||||
const exists = input.before.exists === true;
|
||||
const latestSourceCommit = input.latestSourceCommit;
|
||||
const alreadyUsable = exists && (status === "True" || status === "Unknown");
|
||||
if (latestSourceCommit !== null && latestSourceCommit !== input.sourceCommit) {
|
||||
return {
|
||||
reusable: false,
|
||||
alreadyUsable,
|
||||
reason: "source-head-advanced-before-existing-pipelinerun-reuse",
|
||||
sourceCommit: input.sourceCommit,
|
||||
latestSourceCommit,
|
||||
previousPipelineRun: v02PipelineRunName(input.sourceCommit),
|
||||
latestPipelineRun: v02PipelineRunName(latestSourceCommit),
|
||||
};
|
||||
}
|
||||
return {
|
||||
reusable: exists && status !== null,
|
||||
alreadyUsable,
|
||||
reason: alreadyUsable ? "existing-pipelinerun-reused" : "existing-pipelinerun-terminal-failed",
|
||||
sourceCommit: input.sourceCommit,
|
||||
latestSourceCommit,
|
||||
previousPipelineRun: v02PipelineRunName(input.sourceCommit),
|
||||
};
|
||||
}
|
||||
|
||||
function getPipelineRunCompact(name: string): Record<string, unknown> {
|
||||
const result = g14K3s([
|
||||
"kubectl",
|
||||
@@ -2513,7 +2543,7 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
|
||||
if (options.action === "status" && options.pipelineRun !== undefined) return v02ControlPlaneStatus({ pipelineRun: options.pipelineRun, mode: "pipeline-run" });
|
||||
if (options.action === "status" && options.sourceCommit !== undefined) return v02ControlPlaneStatus({ sourceCommit: options.sourceCommit, mode: "source-commit" });
|
||||
const head = resolveV02Head();
|
||||
const sourceCommit = head.sourceCommit;
|
||||
let sourceCommit = head.sourceCommit;
|
||||
if (sourceCommit === null) {
|
||||
return { ok: false, command: `hwlab g14 control-plane ${options.action} --lane v02`, degradedReason: "v02-head-unresolved", sourceRepo: V02_CICD_REPO, workspace: V02_WORKSPACE, headProbe: compactCommandResult(head.result) };
|
||||
}
|
||||
@@ -2550,7 +2580,7 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
|
||||
: { triggerCurrent: "bun scripts/cli.ts hwlab g14 control-plane trigger-current --lane v02 --confirm" },
|
||||
};
|
||||
}
|
||||
const before = getPipelineRunCompact(v02PipelineRunName(sourceCommit));
|
||||
let before = getPipelineRunCompact(v02PipelineRunName(sourceCommit));
|
||||
if (options.dryRun) {
|
||||
const gitMirrorPreSync = preSyncV02GitMirror(sourceCommit, options);
|
||||
return {
|
||||
@@ -2572,20 +2602,71 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
|
||||
};
|
||||
}
|
||||
if (before.exists === true && before.status !== null) {
|
||||
const alreadyUsable = before.status === "True" || before.status === "Unknown";
|
||||
return {
|
||||
ok: alreadyUsable,
|
||||
command: "hwlab g14 control-plane trigger-current --lane v02",
|
||||
lane: "v02",
|
||||
mode: "confirmed-trigger",
|
||||
sourceCommit,
|
||||
pipelineRun: v02PipelineRunName(sourceCommit),
|
||||
before,
|
||||
skipped: true,
|
||||
reason: alreadyUsable ? "existing-pipelinerun-reused" : "existing-pipelinerun-terminal-failed",
|
||||
degradedReason: alreadyUsable ? undefined : "existing-pipelinerun-terminal-failed",
|
||||
latestOnlyPolicy: "same source commit is idempotent; existing PipelineRun is never deleted or recreated by default",
|
||||
};
|
||||
const latestHead = resolveV02Head();
|
||||
const reuseDecision = v02ExistingPipelineRunReuseDecision({ sourceCommit, before, latestSourceCommit: latestHead.sourceCommit });
|
||||
if (reuseDecision.reusable === true) {
|
||||
const alreadyUsable = reuseDecision.alreadyUsable === true;
|
||||
return {
|
||||
ok: alreadyUsable,
|
||||
command: "hwlab g14 control-plane trigger-current --lane v02",
|
||||
lane: "v02",
|
||||
mode: "confirmed-trigger",
|
||||
sourceCommit,
|
||||
pipelineRun: v02PipelineRunName(sourceCommit),
|
||||
before,
|
||||
skipped: true,
|
||||
reuseDecision,
|
||||
reason: reuseDecision.reason,
|
||||
degradedReason: alreadyUsable ? undefined : "existing-pipelinerun-terminal-failed",
|
||||
latestOnlyPolicy: "same source commit is idempotent; existing PipelineRun is never deleted or recreated by default; source head is rechecked before reuse",
|
||||
};
|
||||
}
|
||||
if (latestHead.sourceCommit !== null && latestHead.sourceCommit !== sourceCommit) {
|
||||
printProgressEvent("hwlab.v02.trigger.progress", {
|
||||
stage: "source-head-recheck",
|
||||
status: "advanced",
|
||||
sourceCommit,
|
||||
latestSourceCommit: latestHead.sourceCommit,
|
||||
previousPipelineRun: v02PipelineRunName(sourceCommit),
|
||||
latestPipelineRun: v02PipelineRunName(latestHead.sourceCommit),
|
||||
});
|
||||
sourceCommit = latestHead.sourceCommit;
|
||||
before = getPipelineRunCompact(v02PipelineRunName(sourceCommit));
|
||||
if (before.exists === true && before.status !== null) {
|
||||
const advancedAlreadyUsable = before.status === "True" || before.status === "Unknown";
|
||||
return {
|
||||
ok: advancedAlreadyUsable,
|
||||
command: "hwlab g14 control-plane trigger-current --lane v02",
|
||||
lane: "v02",
|
||||
mode: "confirmed-trigger",
|
||||
sourceCommit,
|
||||
pipelineRun: v02PipelineRunName(sourceCommit),
|
||||
before,
|
||||
skipped: true,
|
||||
reuseDecision: {
|
||||
...reuseDecision,
|
||||
advancedSourceCommit: sourceCommit,
|
||||
advancedPipelineRun: v02PipelineRunName(sourceCommit),
|
||||
advancedPipelineRunStatus: before.status ?? null,
|
||||
},
|
||||
reason: advancedAlreadyUsable ? "advanced-existing-pipelinerun-reused" : "advanced-existing-pipelinerun-terminal-failed",
|
||||
degradedReason: advancedAlreadyUsable ? undefined : "advanced-existing-pipelinerun-terminal-failed",
|
||||
latestOnlyPolicy: "same source commit is idempotent; existing PipelineRun is never deleted or recreated by default; source head is rechecked before reuse",
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
ok: false,
|
||||
command: "hwlab g14 control-plane trigger-current --lane v02",
|
||||
lane: "v02",
|
||||
mode: "confirmed-trigger",
|
||||
sourceCommit,
|
||||
pipelineRun: v02PipelineRunName(sourceCommit),
|
||||
before,
|
||||
reuseDecision,
|
||||
degradedReason: "existing-pipelinerun-reuse-rejected",
|
||||
};
|
||||
}
|
||||
}
|
||||
printProgressEvent("hwlab.v02.trigger.progress", { stage: "control-plane-refresh", status: "started", sourceCommit, pipelineRun: v02PipelineRunName(sourceCommit) });
|
||||
const controlPlaneRefresh = refreshV02ControlPlaneBeforeTrigger(sourceCommit, options.timeoutSeconds);
|
||||
|
||||
Reference in New Issue
Block a user