From 0b8c29d7496dc61e8100f7302fb619d071993e29 Mon Sep 17 00:00:00 2001 From: "Cratis Stagehand (AI)" Date: Sat, 29 Aug 2026 06:56:22 +0000 Subject: [PATCH] Add a push helper that retries after losing a race to another job The dependency update jobs commit straight to main from several jobs at once, so a push rejected with "cannot lock ref 'refs/heads/main'" means another job simply moved the branch first. Rebase onto the new remote head and try again rather than treating it as a failure. --- .github/scripts/push-with-retry.sh | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 .github/scripts/push-with-retry.sh diff --git a/.github/scripts/push-with-retry.sh b/.github/scripts/push-with-retry.sh new file mode 100755 index 00000000..c2fce4fc --- /dev/null +++ b/.github/scripts/push-with-retry.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Push the current branch, recovering from a push that lost a race. +# +# The dependency update jobs commit straight to main from several jobs at once, +# so a rejected push is an expected outcome rather than a failure: another job +# simply moved the branch first. Rebase the local commits onto the new remote +# head and try again. + +set -euo pipefail + +attempts=${PUSH_RETRY_ATTEMPTS:-5} + +for ((attempt = 1; attempt <= attempts; attempt++)); do + if git push; then + echo "Pushed on attempt ${attempt} of ${attempts}" + exit 0 + fi + + if [ "${attempt}" -eq "${attempts}" ]; then + break + fi + + echo "Push attempt ${attempt} of ${attempts} was rejected - another job moved the branch. Rebasing onto the latest remote head and retrying..." + sleep "$((attempt * 5))" + + if ! git pull --rebase; then + git rebase --abort || true + echo "::error::Could not rebase onto the latest remote head" + exit 1 + fi +done + +echo "::error::Failed to push after ${attempts} attempts" +exit 1