From 2548473c2e73d50113cec989de2b063f8320281c Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 9 Jul 2026 22:43:38 +0200 Subject: [PATCH] fix: flush AgentRun PaC GitOps mirror on closeout --- config/platform-infra/pipelines-as-code.yaml | 3 +- .../src/platform-infra-pipelines-as-code.ts | 36 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/config/platform-infra/pipelines-as-code.yaml b/config/platform-infra/pipelines-as-code.yaml index b094402e..898cbe13 100644 --- a/config/platform-infra/pipelines-as-code.yaml +++ b/config/platform-infra/pipelines-as-code.yaml @@ -125,7 +125,7 @@ templates: concurrencyLimit: 1 params: git_read_url: http://gitea-http.devops-infra.svc.cluster.local:3000/mirrors/pikasTech-agentrun.git - git_write_url: http://gitea-http.devops-infra.svc.cluster.local:3000/mirrors/pikasTech-agentrun.git + git_write_url: http://git-mirror-write.devops-infra.svc.cluster.local:8080/pikasTech/agentrun.git source_branch: v0.2 node: "${NODE}" gitops_branch: "${nodeLower}-v0.2-gitops" @@ -196,6 +196,7 @@ templates: pipelineRunPrefix: "agentrun-${nodeLower}-v02-ci" argoNamespace: argocd argoApplication: "agentrun-${nodeLower}-v02" + closeoutGitOpsMirrorFlush: true sentinelV03: id: "sentinel-${nodeLower}-v03" repositoryRef: "sentinel-${nodeLower}-v03" diff --git a/scripts/src/platform-infra-pipelines-as-code.ts b/scripts/src/platform-infra-pipelines-as-code.ts index 7224a362..f40412e9 100644 --- a/scripts/src/platform-infra-pipelines-as-code.ts +++ b/scripts/src/platform-infra-pipelines-as-code.ts @@ -5,6 +5,7 @@ import type { UniDeskConfig } from "./config"; import { rootPath } from "./config"; import { parseNodeScopedDelegatedOptions } from "./hwlab-node/plan"; import { nodeRuntimeEnsureGitMirrorFlushed } from "./hwlab-node/status"; +import { runGitMirrorJob as runAgentRunGitMirrorJob } from "./agentrun/rest-bridge"; import type { RenderedCliResult } from "./output"; import { capture, @@ -543,7 +544,7 @@ async function closeout(config: UniDeskConfig, options: CloseoutOptions): Promis const observedSourceCommit = stringValue(latest.sourceCommit) !== "-" ? stringValue(latest.sourceCommit) : stringValue(diagnostics.sourceCommit); const sourceMatched = options.sourceCommit === null || observedSourceCommit === options.sourceCommit; const baseReady = current.ok === true && sourceMatched; - const gitOpsMirrorFlush = runCloseoutGitOpsMirrorFlush(pac, consumer, latest, baseReady, observedSourceCommit); + const gitOpsMirrorFlush = await runCloseoutGitOpsMirrorFlush(config, pac, consumer, latest, baseReady, observedSourceCommit); const gitOpsMirrorFlushReady = record(gitOpsMirrorFlush).ok !== false; const ready = baseReady && gitOpsMirrorFlushReady; return { @@ -1351,7 +1352,7 @@ function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } -function runCloseoutGitOpsMirrorFlush(pac: PacConfig, consumer: PacConsumer, latest: Record, baseReady: boolean, observedSourceCommit: string): Record { +async function runCloseoutGitOpsMirrorFlush(config: UniDeskConfig, pac: PacConfig, consumer: PacConsumer, latest: Record, baseReady: boolean, observedSourceCommit: string): Promise> { const cfg = pac.closeout.gitOpsMirrorFlush; const configSource = `${configLabel}.closeout.gitOpsMirrorFlush`; const required = cfg.enabled && consumer.closeoutGitOpsMirrorFlush; @@ -1390,6 +1391,37 @@ function runCloseoutGitOpsMirrorFlush(pac: PacConfig, consumer: PacConsumer, lat valuesPrinted: false, }; } + if (consumer.id.startsWith("agentrun-")) { + const progressLines: string[] = []; + const flush = await captureStderrLines(progressLines, () => runAgentRunGitMirrorJob(config, "flush", { + node: consumer.node, + lane: consumer.lane, + confirm: true, + dryRun: false, + wait: true, + timeoutSeconds: cfg.waitTimeoutSeconds, + })); + return { + ok: flush.ok === true, + enabled: true, + required: true, + mode: stringValue(flush.mode, flush.ok === true ? "flushed" : "failed"), + executed: flush.ok === true, + sourceCommit: observedSourceCommit, + pipelineRun, + configSource, + waitTimeoutSeconds: cfg.waitTimeoutSeconds, + maxAttempts: cfg.maxAttempts, + beforeSummary: record(record(flush.status).summary), + afterSummary: record(record(flush.status).summary), + jobName: flush.jobName ?? null, + degradedReason: flush.ok === true ? undefined : "pac-closeout-agentrun-gitops-mirror-flush-failed", + next: record(flush.next), + flush, + progressLines, + valuesPrinted: false, + }; + } const deadlineMs = Date.now() + (cfg.waitTimeoutSeconds * 1000); const scoped = parseNodeScopedDelegatedOptions("git-mirror", [ "flush",