[patch] 修复因自动更新回归代码config.py因覆盖逻辑导致的新增代码被覆盖的逻辑
This commit is contained in:
@@ -475,10 +475,8 @@ jobs:
|
||||
# Unstage to avoid merge conflicts
|
||||
git reset HEAD config.py version_history.json;
|
||||
|
||||
# Backup our version files
|
||||
Copy-Item "config.py" "config.py.new" -Force;
|
||||
Copy-Item "version_history.json" "version_history.json.new" -Force;
|
||||
Write-Host "Backed up new version files";
|
||||
# FIX: No longer backup files to avoid overwriting user code later
|
||||
Write-Host "Preparing to pull remote changes...";
|
||||
|
||||
# Pull remote changes (use merge strategy to avoid rebase conflicts)
|
||||
git pull origin $BRANCH --no-rebase;
|
||||
@@ -490,34 +488,58 @@ jobs:
|
||||
$conflicts = git diff --name-only --diff-filter=U;
|
||||
Write-Host "Conflict files: $conflicts";
|
||||
|
||||
# Manually resolve config.py conflict (use our new version)
|
||||
if (Test-Path "config.py.new") {
|
||||
Copy-Item "config.py.new" "config.py" -Force;
|
||||
# FIX: Smart conflict resolution to preserve user code
|
||||
# For config.py: use remote version (user code), then re-apply version update
|
||||
if ($conflicts -match "config.py") {
|
||||
Write-Host "Resolving config.py conflict...";
|
||||
# Use remote version (preserve user code)
|
||||
git checkout --theirs config.py;
|
||||
# Re-apply version update only
|
||||
python .gitea/scripts/gui_version_creator.py;
|
||||
git add config.py;
|
||||
Write-Host "OK: Resolved config.py conflict (using new version)";
|
||||
Write-Host "OK: Resolved config.py (preserved user code + updated version)";
|
||||
}
|
||||
|
||||
# Manually resolve version_history.json conflict (use our new version)
|
||||
if (Test-Path "version_history.json.new") {
|
||||
Copy-Item "version_history.json.new" "version_history.json" -Force;
|
||||
# For version_history.json: use CI/CD version (append record)
|
||||
if ($conflicts -match "version_history.json") {
|
||||
Write-Host "Resolving version_history.json conflict...";
|
||||
git checkout --ours version_history.json;
|
||||
git add version_history.json;
|
||||
Write-Host "OK: Resolved version_history.json conflict (using new version)";
|
||||
Write-Host "OK: Resolved version_history.json (using CI/CD version)";
|
||||
}
|
||||
|
||||
# Complete the merge
|
||||
git commit -m "[skip ci] Merge and update version to v$VERSION" --no-edit --no-verify;
|
||||
} else {
|
||||
Write-Host "OK: Pull successful, applying our changes...";
|
||||
Write-Host "OK: Pull successful";
|
||||
|
||||
# Apply our version files
|
||||
Copy-Item "config.py.new" "config.py" -Force;
|
||||
Copy-Item "version_history.json.new" "version_history.json" -Force;
|
||||
# FIX: Do not overwrite entire file to avoid losing user's new code
|
||||
# After pull, config.py already contains:
|
||||
# 1. Version update from CI/CD (gui_version_creator.py)
|
||||
# 2. User's new code (from remote repository)
|
||||
# Just add current state, no need to overwrite
|
||||
|
||||
Write-Host "Checking if version update is preserved...";
|
||||
|
||||
# Verify version number is correct
|
||||
$configContent = Get-Content "config.py" -Raw;
|
||||
if ($configContent -match 'APP_VERSION\s*=\s*"([\d.]+)"') {
|
||||
$currentVersion = $matches[1];
|
||||
Write-Host "Current APP_VERSION in config.py: $currentVersion";
|
||||
Write-Host "Expected version: $VERSION";
|
||||
|
||||
if ($currentVersion -ne $VERSION) {
|
||||
Write-Host "WARNING: Version mismatch, re-applying version update...";
|
||||
# Re-execute version update (only modify APP_VERSION line)
|
||||
python .gitea/scripts/gui_version_creator.py;
|
||||
} else {
|
||||
Write-Host "OK: Version is correct";
|
||||
}
|
||||
}
|
||||
|
||||
# Add current files (includes user code + version update)
|
||||
git add config.py version_history.json;
|
||||
}
|
||||
|
||||
# Cleanup backup files
|
||||
Remove-Item "config.py.new" -ErrorAction SilentlyContinue;
|
||||
Remove-Item "version_history.json.new" -ErrorAction SilentlyContinue;
|
||||
} else {
|
||||
Write-Host "No remote changes, proceeding with commit...";
|
||||
}
|
||||
@@ -577,27 +599,23 @@ jobs:
|
||||
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 4: Record current version number
|
||||
$currentVersionMatch = (Get-Content "config.py" -Raw) -match 'APP_VERSION\s*=\s*"([\d.]+)"';
|
||||
$targetVersion = $matches[1];
|
||||
Write-Host "Target version to apply: $targetVersion";
|
||||
|
||||
# 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 6: FIX - Re-apply version update only, do not overwrite entire file
|
||||
Write-Host "Re-applying version update only...";
|
||||
python .gitea/scripts/gui_version_creator.py;
|
||||
|
||||
# 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user