diff --git a/.gitea/workflows/version-and-release.yml b/.gitea/workflows/version-and-release.yml index e6d2e3a..d04bb9d 100644 --- a/.gitea/workflows/version-and-release.yml +++ b/.gitea/workflows/version-and-release.yml @@ -164,11 +164,25 @@ jobs: - name: Commit version bump if: steps.version.outputs.version_changed == 'true' run: | + set -e # Exit on any error + + # First, ensure we have the latest changes + echo "Fetching latest changes..." + git fetch origin main + + # Check if we're behind and need to update + LOCAL=$(git rev-parse HEAD) + REMOTE=$(git rev-parse origin/main) + + if [ "$LOCAL" != "$REMOTE" ]; then + echo "Local is behind remote, pulling changes..." + git pull origin main --no-rebase + fi + COMPONENT="${{ steps.version.outputs.component_changed }}" if [ "$COMPONENT" = "both" ]; then - git add backend/package.json backend/package-lock.json - git add frontend/package.json frontend/package-lock.json + git add backend/package.json backend/package-lock.json frontend/package.json frontend/package-lock.json git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }} (backend + frontend)" elif [ "$COMPONENT" = "backend" ]; then git add backend/package.json backend/package-lock.json @@ -189,25 +203,40 @@ jobs: # Push the changes with retry logic echo "Pushing version bump..." - MAX_RETRIES=3 - RETRY_COUNT=0 + PUSH_SUCCESS=false - while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do - if git push origin main; then - echo "Successfully pushed version bump" + for i in 1 2 3; do + echo "Push attempt $i of 3..." + + # Try to push + if git push origin main 2>&1; then + echo "Successfully pushed version bump on attempt $i" + PUSH_SUCCESS=true break else - RETRY_COUNT=$((RETRY_COUNT + 1)) - if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then - echo "Push failed, retrying in 5 seconds... (attempt $RETRY_COUNT/$MAX_RETRIES)" + echo "Push failed on attempt $i" + + if [ $i -lt 3 ]; then + echo "Waiting 5 seconds before retry..." sleep 5 - git pull --rebase origin main || git pull origin main --no-rebase - else - echo "Failed to push after $MAX_RETRIES attempts" - exit 1 + + echo "Pulling latest changes..." + git fetch origin main + + # Try rebase first, fall back to merge + if ! git rebase origin/main; then + echo "Rebase failed, trying merge..." + git rebase --abort 2>/dev/null || true + git pull origin main --no-rebase + fi fi fi done + + if [ "$PUSH_SUCCESS" = "false" ]; then + echo "ERROR: Failed to push after 3 attempts" + exit 1 + fi - name: Create Git tag if: steps.version.outputs.version_changed == 'true'