[patch] 增强版本更新日志输出

This commit is contained in:
Gitea Actions
2025-10-10 14:24:46 +08:00
parent 734dd8d1fe
commit e60c99d81e

View File

@@ -301,32 +301,58 @@ class DatabaseVersionManager:
def update_config_version(self, new_version: str): def update_config_version(self, new_version: str):
"""更新config.py中的APP_VERSION""" """更新config.py中的APP_VERSION"""
logger.info(f"正在更新config.py到版本: {new_version}")
logger.info(f"配置文件路径: {self.config_file}")
logger.info(f"配置文件绝对路径: {self.config_file.absolute()}")
logger.info(f"配置文件是否存在: {self.config_file.exists()}")
if not self.config_file.exists(): if not self.config_file.exists():
logger.warning(f"配置文件不存在: {self.config_file}") logger.error(f"配置文件不存在: {self.config_file}")
return False return False
try: try:
# 读取文件
with open(self.config_file, 'r', encoding='utf-8') as f: with open(self.config_file, 'r', encoding='utf-8') as f:
content = f.read() content = f.read()
logger.info(f"已读取config.py文件大小: {len(content)} 字节")
# 查找当前版本
import re import re
pattern = r'APP_VERSION\s*=\s*["\'][\d.]+["\']' pattern = r'APP_VERSION\s*=\s*["\'][\d.]+["\']'
replacement = f'APP_VERSION = "{new_version}"' match = re.search(pattern, content)
if re.search(pattern, content): if match:
old_version_line = match.group(0)
logger.info(f"找到当前版本行: {old_version_line}")
replacement = f'APP_VERSION = "{new_version}"'
new_content = re.sub(pattern, replacement, content) new_content = re.sub(pattern, replacement, content)
logger.info(f"准备写入新版本: {replacement}")
# 写入文件
with open(self.config_file, 'w', encoding='utf-8') as f: with open(self.config_file, 'w', encoding='utf-8') as f:
f.write(new_content) f.write(new_content)
# 验证写入
with open(self.config_file, 'r', encoding='utf-8') as f:
verify_content = f.read()
verify_match = re.search(pattern, verify_content)
if verify_match:
logger.info(f"✅ 写入验证成功: {verify_match.group(0)}")
logger.info(f"✅ 已更新 config.py: APP_VERSION = \"{new_version}\"") logger.info(f"✅ 已更新 config.py: APP_VERSION = \"{new_version}\"")
return True return True
else: else:
logger.warning("未找到APP_VERSION配置项") logger.error(f"未找到APP_VERSION配置项pattern: {pattern}")
logger.info(f"文件内容预览前200字符: {content[:200]}")
return False return False
except Exception as e: except Exception as e:
logger.error(f"更新config.py失败: {e}") logger.error(f"更新config.py失败: {e}")
import traceback
logger.error(traceback.format_exc())
return False return False
def create_version_record(self) -> dict: def create_version_record(self) -> dict: