[patch] 修复因自动更新回归代码config.py因覆盖逻辑导致的新增代码被覆盖的逻辑

This commit is contained in:
kris 郝
2025-11-03 14:56:01 +08:00
parent 7054beebeb
commit 58868c9c18
2 changed files with 84 additions and 31 deletions

View File

@@ -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;
}

View File

@@ -45,6 +45,41 @@ WINDOW_TITLE = "AI回复连接入口-V1.0"
# 应用版本号(用于版本检查)
APP_VERSION = "1.5.67"
# 🔥 多实例运行模式开关
# - True: 测试模式多实例不保存token避免冲突
# - False: 生产模式单实例保存token自动加载
#
# 使用方法:
# 1. 修改此值MULTI_INSTANCE_MODE = False # 改为生产模式
# 2. 或设置环境变量SHUIDROP_MULTI_INSTANCE=0 # 临时切换到生产模式
MULTI_INSTANCE_MODE = True # 默认:测试模式
def is_multi_instance_mode() -> bool:
"""
检查是否为多实例模式(支持环境变量覆盖)
优先级:
1. 环境变量 SHUIDROP_MULTI_INSTANCE0=生产1=测试)
2. 配置文件 MULTI_INSTANCE_MODE
Returns:
bool: True=多实例模式False=单实例模式
"""
# 检查环境变量
env_value = os.getenv('SHUIDROP_MULTI_INSTANCE')
if env_value is not None:
# 0, false, False, no, No → 生产模式
if env_value.lower() in ('0', 'false', 'no'):
return False
# 1, true, True, yes, Yes → 测试模式
if env_value.lower() in ('1', 'true', 'yes'):
return True
# 使用配置文件值 (如果不做设置我们可以直接用编码变量进行控制是否可以允许多实例的方式运行)
return MULTI_INSTANCE_MODE
# 平台特定配置
PLATFORMS = {
"JD": {