From 40846dd7f43745eb883df836ea2e0065b4bd7bac Mon Sep 17 00:00:00 2001 From: haosicheng Date: Mon, 13 Oct 2025 11:39:38 +0800 Subject: [PATCH] =?UTF-8?q?[patch]=20=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91:?= =?UTF-8?q?=20=E5=9C=A8=E7=94=A8=E6=88=B7=E8=AF=AF=E8=A7=A6=E6=88=96?= =?UTF-8?q?=E5=BC=80=E4=BA=86=E5=A4=9A=E4=B8=AAGUI=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E4=B8=8D=E8=83=BD=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E5=A4=9A=E4=B8=AA=E8=BF=9E=E6=8E=A5=20?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E4=B8=80=E4=B8=AA=E8=B4=A6=E5=8F=B7=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E5=BB=BA=E7=AB=8B=E4=B8=80=E4=B8=AA=E4=B8=8E=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E8=BF=9E=E6=8E=A5=20=E5=8F=8B=E5=A5=BD?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E7=9A=84=E9=9B=86=E6=88=90review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/gui-version-release.yml | 96 +++++++++++++++++++----- 1 file changed, 78 insertions(+), 18 deletions(-) diff --git a/.gitea/workflows/gui-version-release.yml b/.gitea/workflows/gui-version-release.yml index c3699b6..8b1c6cb 100644 --- a/.gitea/workflows/gui-version-release.yml +++ b/.gitea/workflows/gui-version-release.yml @@ -396,12 +396,33 @@ jobs: git config user.name "Gitea Actions Bot"; git config user.email "bot@gitea.local"; + # Ensure we are on the correct branch (not detached HEAD) + $BRANCH = "${{ github.ref_name }}"; + $currentBranch = git rev-parse --abbrev-ref HEAD; + Write-Host "Current branch: $currentBranch"; + Write-Host "Target branch: $BRANCH"; + + if ($currentBranch -ne $BRANCH) { + Write-Host "WARNING: Not on target branch, checking out..."; + git checkout $BRANCH; + Write-Host "OK: Checked out to $BRANCH"; + } + + # Clean up any existing rebase state before starting + $rebaseExists = Test-Path ".git/rebase-merge" -Or (Test-Path ".git/rebase-apply"); + if ($rebaseExists) { + Write-Host "WARNING: Found existing rebase state, cleaning up..."; + git rebase --abort 2>$null; + Remove-Item -Path ".git/rebase-merge" -Recurse -Force -ErrorAction SilentlyContinue; + Remove-Item -Path ".git/rebase-apply" -Recurse -Force -ErrorAction SilentlyContinue; + Write-Host "OK: Rebase state cleaned"; + } + # Check for changes git add config.py version_history.json; $hasChanges = git diff --staged --quiet; if ($LASTEXITCODE -ne 0) { - $BRANCH = "${{ github.ref_name }}"; Write-Host "Detected changes in version files"; Write-Host ""; @@ -427,14 +448,6 @@ jobs: Copy-Item "version_history.json" "version_history.json.new" -Force; Write-Host "Backed up new version files"; - # Check for interrupted rebase - $rebaseInProgress = Test-Path ".git/rebase-merge" -Or (Test-Path ".git/rebase-apply"); - if ($rebaseInProgress) { - Write-Host "WARNING: Detected interrupted rebase, aborting..."; - git rebase --abort; - Write-Host "OK: Rebase aborted, starting clean"; - } - # Pull remote changes (use merge strategy to avoid rebase conflicts) git pull origin $BRANCH --no-rebase; @@ -486,29 +499,76 @@ jobs: Write-Host ""; Write-Host "Step 5.3: Pushing to remote..."; - # Push to remote (retry up to 3 times) + # Push to remote (retry up to 3 times with smart strategy) $pushSuccess = $false; for ($i = 1; $i -le 3; $i++) { Write-Host "Push attempt $i/3..."; + + # Before each attempt, ensure clean state + if ($i -gt 1) { + Write-Host "Preparing for retry $i..."; + + # Step 1: Clean up any rebase state + $rebaseCheck = Test-Path ".git/rebase-merge" -Or (Test-Path ".git/rebase-apply"); + if ($rebaseCheck) { + Write-Host "Cleaning up rebase state..."; + git rebase --abort 2>$null; + Remove-Item -Path ".git/rebase-merge" -Recurse -Force -ErrorAction SilentlyContinue; + Remove-Item -Path ".git/rebase-apply" -Recurse -Force -ErrorAction SilentlyContinue; + } + + # Step 2: Ensure on correct branch + $currentBranchCheck = git rev-parse --abbrev-ref HEAD; + if ($currentBranchCheck -ne $BRANCH) { + Write-Host "Checking out to branch $BRANCH..."; + git checkout $BRANCH; + } + + # Step 3: Fetch latest remote state + Write-Host "Fetching latest remote state..."; + git fetch origin $BRANCH; + + # Step 4: Backup our version files again + Copy-Item "config.py" "config.py.retry" -Force; + Copy-Item "version_history.json" "version_history.json.retry" -Force; + + # Step 5: Reset to remote state + Write-Host "Resetting to remote state..."; + git reset --hard origin/$BRANCH; + + # Step 6: Apply our version files + Write-Host "Applying our version files..."; + Copy-Item "config.py.retry" "config.py" -Force; + Copy-Item "version_history.json.retry" "version_history.json" -Force; + + # Step 7: Stage and commit again + git add config.py version_history.json; + git commit -m "[skip ci] Update version to v$VERSION" --no-verify; + + # Step 8: Clean up retry backup files + Remove-Item "config.py.retry" -ErrorAction SilentlyContinue; + Remove-Item "version_history.json.retry" -ErrorAction SilentlyContinue; + + Write-Host "Retry preparation complete"; + Start-Sleep -Seconds 1; + } + + # Attempt to push git push origin $BRANCH; if ($LASTEXITCODE -eq 0) { - Write-Host "OK: Push successful"; + Write-Host "OK: Push successful on attempt $i"; $pushSuccess = $true; break; } else { - Write-Host "WARNING: Push failed"; - if ($i -lt 3) { - Write-Host "Pulling again and retrying..."; - git pull --rebase origin $BRANCH; - Start-Sleep -Seconds 2; - } + Write-Host "WARNING: Push attempt $i failed"; } } if (-not $pushSuccess) { Write-Host "ERROR: Push failed after 3 attempts"; - Write-Host "This is not critical - version is already recorded in database"; + Write-Host "NOTICE: This is not critical - version is already in database and KS3"; + Write-Host "NOTICE: Git repository sync can be done manually later"; } } else { Write-Host "ERROR: Commit failed";