diff --git a/.github/workflows/build-and-deploy-ghcr.yml b/.github/workflows/build-and-deploy-ghcr.yml index 8f28732..54c8ec6 100644 --- a/.github/workflows/build-and-deploy-ghcr.yml +++ b/.github/workflows/build-and-deploy-ghcr.yml @@ -56,13 +56,24 @@ jobs: image_ref="${IMAGE_NAME}@${{ steps.build.outputs.digest }}" git clone "https://${{ secrets.GHCR_USERNAME }}:${GITOPS_TOKEN}@github.com/${GITOPS_REPO}.git" /tmp/nxtgauge-gitops cd /tmp/nxtgauge-gitops - ./scripts/set-app-release.sh "$APP_KEY" "$image_ref" - if git diff --quiet; then - echo "GitOps repo already up to date." - exit 0 - fi git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - git add apps scripts/set-app-release.sh - git commit -m "chore(gitops): deploy ${APP_KEY}@${{ github.sha }}" - git push origin HEAD:main + for attempt in 1 2 3 4 5; do + git fetch origin main + git reset --hard origin/main + ./scripts/set-app-release.sh "$APP_KEY" "$image_ref" + if git diff --quiet; then + echo "GitOps repo already up to date." + exit 0 + fi + git add apps scripts/set-app-release.sh + git commit -m "chore(gitops): deploy ${APP_KEY}@${{ github.sha }}" + if git push origin HEAD:main; then + exit 0 + fi + echo "GitOps push race on attempt ${attempt}, retrying..." + git reset --hard origin/main + sleep $((attempt * 2)) + done + echo "Failed to update GitOps after multiple attempts." + exit 1