From 076d0ad5e401fdece879299f8fb573109609cdbe Mon Sep 17 00:00:00 2001 From: Patrick Dodgen Date: Thu, 5 Feb 2026 14:37:37 -0700 Subject: [PATCH] fix: add retry logic to handle race conditions in common bump push The php-common-bump workflow was failing when main moved during execution. This adds fetch + rebase before pushing with retry logic to handle concurrent pushes to main. --- .github/workflows/php-common-bump.yaml | 39 ++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php-common-bump.yaml b/.github/workflows/php-common-bump.yaml index e7f5eb2..bc05483 100644 --- a/.github/workflows/php-common-bump.yaml +++ b/.github/workflows/php-common-bump.yaml @@ -74,6 +74,41 @@ jobs: run: | git config user.name github-actions git config user.email github-actions@github.com - git diff-index --quiet HEAD || git commit -am "${{ inputs.commit_message }} [skip actions]" - git push origin main + + # Check if there are changes to commit + if git diff-index --quiet HEAD; then + echo "No changes to commit" + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + exit 0 + fi + + git commit -am "${{ inputs.commit_message }} [skip actions]" + + # Push with retry logic to handle race conditions where main has moved + MAX_ATTEMPTS=5 + ATTEMPT=1 + while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do + echo "Push attempt $ATTEMPT of $MAX_ATTEMPTS" + + # Fetch latest and rebase before pushing + git fetch origin main + if git rebase origin/main; then + if git push origin main; then + echo "Push succeeded on attempt $ATTEMPT" + break + fi + else + echo "Rebase failed, resetting and retrying..." + git rebase --abort 2>/dev/null || true + fi + + if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then + echo "Failed to push after $MAX_ATTEMPTS attempts" + exit 1 + fi + + ATTEMPT=$((ATTEMPT + 1)) + sleep 2 + done + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT