From c7875102c5196a9ef3038c2d5e0ee313fbb2782a Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 20 Jul 2025 22:28:05 +0200 Subject: [PATCH] fix: improve version bump workflow with better conflict resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added pre-fetch and check before committing to ensure we're up-to-date - Improved retry logic with clearer output and better error handling - Added explicit fetch before each retry attempt - Use for-loop instead of while for clearer retry counting - Better fallback from rebase to merge on conflicts - Added set -e to fail fast on errors - More verbose logging for debugging This should resolve the persistent "non-fast-forward" errors by: 1. Checking if we're behind before even committing 2. Pulling changes if needed 3. Retrying with proper synchronization 4. Providing clear debug output 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .gitea/workflows/version-and-release.yml | 57 ++++++++++++++++++------ 1 file changed, 43 insertions(+), 14 deletions(-) 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'