From 7cd14c8c1c61a9c9d2fe708b1251639fb9cd9f2d Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 27 Jun 2026 16:53:34 +0000 Subject: [PATCH] fix(agentrun): allow initial gitops branch publish --- scripts/src/agentrun/secrets.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/src/agentrun/secrets.ts b/scripts/src/agentrun/secrets.ts index 5dd576c2..f8f17df2 100644 --- a/scripts/src/agentrun/secrets.ts +++ b/scripts/src/agentrun/secrets.ts @@ -548,12 +548,25 @@ export function yamlLaneGitMirrorSyncShell(spec: AgentRunLaneSpec): string { "timeout 240 git --git-dir=\"$repo\" fetch origin \"+refs/heads/${source_branch}:refs/mirror-stage/heads/${source_branch}\"", "source_sha=$(git --git-dir=\"$repo\" rev-parse --verify \"refs/mirror-stage/heads/${source_branch}^{commit}\")", "git --git-dir=\"$repo\" update-ref \"refs/heads/${source_branch}\" \"$source_sha\"", - "timeout 240 git --git-dir=\"$repo\" fetch origin \"+refs/heads/${gitops_branch}:refs/mirror-stage/heads/${gitops_branch}\"", - "gitops_sha=$(git --git-dir=\"$repo\" rev-parse --verify \"refs/mirror-stage/heads/${gitops_branch}^{commit}\")", - "git --git-dir=\"$repo\" update-ref \"refs/heads/${gitops_branch}\" \"$gitops_sha\"", + "gitops_fetch_err=$(mktemp)", + "gitops_remote_missing=false", + "gitops_sha=\"\"", + "if timeout 240 git --git-dir=\"$repo\" fetch origin \"+refs/heads/${gitops_branch}:refs/mirror-stage/heads/${gitops_branch}\" 2>\"$gitops_fetch_err\"; then", + " gitops_sha=$(git --git-dir=\"$repo\" rev-parse --verify \"refs/mirror-stage/heads/${gitops_branch}^{commit}\")", + " git --git-dir=\"$repo\" update-ref \"refs/heads/${gitops_branch}\" \"$gitops_sha\"", + "else", + " gitops_fetch_exit=$?", + " if grep -qi \"couldn't find remote ref\" \"$gitops_fetch_err\"; then", + " gitops_remote_missing=true", + " gitops_sha=$(git --git-dir=\"$repo\" rev-parse --verify \"refs/heads/${gitops_branch}^{commit}\" 2>/dev/null || true)", + " else", + " cat \"$gitops_fetch_err\" >&2", + " exit \"$gitops_fetch_exit\"", + " fi", + "fi", "git --git-dir=\"$repo\" update-server-info", - "SOURCE_SHA=\"$source_sha\" GITOPS_SHA=\"$gitops_sha\" node <<'NODE'", - "console.log(JSON.stringify({ ok: true, localSource: process.env.SOURCE_SHA, localGitops: process.env.GITOPS_SHA, valuesPrinted: false }));", + "SOURCE_SHA=\"$source_sha\" GITOPS_SHA=\"$gitops_sha\" GITOPS_REMOTE_MISSING=\"$gitops_remote_missing\" node <<'NODE'", + "console.log(JSON.stringify({ ok: true, localSource: process.env.SOURCE_SHA, localGitops: process.env.GITOPS_SHA || null, gitopsRemoteMissing: process.env.GITOPS_REMOTE_MISSING === 'true', valuesPrinted: false }));", "NODE", ].join("\n"); }