feat: add controlled AgentRun CI cleanup
This commit is contained in:
@@ -2510,7 +2510,7 @@ function listCleanupPipelineRuns(options: G14ControlPlaneOptions): Record<string
|
||||
const targetPipelineRun = options.pipelineRun ?? (options.sourceCommit === undefined ? undefined : v02PipelineRunName(options.sourceCommit));
|
||||
const prefixes = pipelinePrefixesForLane(options.lane);
|
||||
const now = Date.now();
|
||||
const candidates = statusText(result)
|
||||
const terminalRuns = statusText(result)
|
||||
.split(/\r?\n/u)
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean)
|
||||
@@ -2521,10 +2521,24 @@ 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")
|
||||
.sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)));
|
||||
const protectedLatestByPrefix = new Map<string, string>();
|
||||
for (const prefix of prefixes) {
|
||||
const latest = terminalRuns
|
||||
.filter((item) => item.name.startsWith(prefix))
|
||||
.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))[0];
|
||||
if (latest !== undefined) protectedLatestByPrefix.set(prefix, latest.name);
|
||||
}
|
||||
const candidates = terminalRuns
|
||||
.filter((item) => targetPipelineRun === undefined || item.name === targetPipelineRun)
|
||||
.filter((item) => typeof item.ageMinutes === "number" && item.ageMinutes >= options.minAgeMinutes)
|
||||
.sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)))
|
||||
.map((item) => {
|
||||
const protectedLatest = targetPipelineRun === undefined && [...protectedLatestByPrefix.values()].includes(item.name);
|
||||
return protectedLatest
|
||||
? { ...item, selected: false, selectedReason: "protected-latest-pipelinerun" }
|
||||
: item;
|
||||
})
|
||||
.slice(0, options.limit);
|
||||
if (targetPipelineRun !== undefined && candidates.length === 0) {
|
||||
return [{
|
||||
|
||||
Reference in New Issue
Block a user