From e89c7b7735ede8586f1afb7aa76463f573c7881d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 16:21:59 +0000 Subject: [PATCH] refactor(infra): dedupe update checkout step --- src/infra/update-runner.ts | 68 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/infra/update-runner.ts b/src/infra/update-runner.ts index 46bbf8a19fd..d0fbc43ce4c 100644 --- a/src/infra/update-runner.ts +++ b/src/infra/update-runner.ts @@ -411,6 +411,23 @@ export async function runGatewayUpdate(opts: UpdateRunnerOptions = {}): Promise< const branch = channel === "dev" ? await readBranchName(runCommand, gitRoot, timeoutMs) : null; const needsCheckoutMain = channel === "dev" && branch !== DEV_BRANCH; gitTotalSteps = channel === "dev" ? (needsCheckoutMain ? 11 : 10) : 9; + const buildGitErrorResult = (reason: string): UpdateRunResult => ({ + status: "error", + mode: "git", + root: gitRoot, + reason, + before: { sha: beforeSha, version: beforeVersion }, + steps, + durationMs: Date.now() - startedAt, + }); + const runGitCheckoutOrFail = async (name: string, argv: string[]) => { + const checkoutStep = await runStep(step(name, argv, gitRoot)); + steps.push(checkoutStep); + if (checkoutStep.exitCode !== 0) { + return buildGitErrorResult("checkout-failed"); + } + return null; + }; const statusCheck = await runStep( step( @@ -436,24 +453,15 @@ export async function runGatewayUpdate(opts: UpdateRunnerOptions = {}): Promise< if (channel === "dev") { if (needsCheckoutMain) { - const checkoutStep = await runStep( - step( - `git checkout ${DEV_BRANCH}`, - ["git", "-C", gitRoot, "checkout", DEV_BRANCH], - gitRoot, - ), - ); - steps.push(checkoutStep); - if (checkoutStep.exitCode !== 0) { - return { - status: "error", - mode: "git", - root: gitRoot, - reason: "checkout-failed", - before: { sha: beforeSha, version: beforeVersion }, - steps, - durationMs: Date.now() - startedAt, - }; + const failure = await runGitCheckoutOrFail(`git checkout ${DEV_BRANCH}`, [ + "git", + "-C", + gitRoot, + "checkout", + DEV_BRANCH, + ]); + if (failure) { + return failure; } } @@ -700,20 +708,16 @@ export async function runGatewayUpdate(opts: UpdateRunnerOptions = {}): Promise< }; } - const checkoutStep = await runStep( - step(`git checkout ${tag}`, ["git", "-C", gitRoot, "checkout", "--detach", tag], gitRoot), - ); - steps.push(checkoutStep); - if (checkoutStep.exitCode !== 0) { - return { - status: "error", - mode: "git", - root: gitRoot, - reason: "checkout-failed", - before: { sha: beforeSha, version: beforeVersion }, - steps, - durationMs: Date.now() - startedAt, - }; + const failure = await runGitCheckoutOrFail(`git checkout ${tag}`, [ + "git", + "-C", + gitRoot, + "checkout", + "--detach", + tag, + ]); + if (failure) { + return failure; } }