From 7a8de5e79175ff7a7a633f43418f427badc4af53 Mon Sep 17 00:00:00 2001 From: linyq Date: Mon, 19 May 2025 10:18:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E4=BB=8E=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E5=B9=B6=E7=AE=80=E5=8C=96=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E7=94=9F=E6=88=90=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto-release-generator.yml | 16 ++--------- app/config/config.py | 16 ++++++++++- project_version | 2 +- webui/config/settings.py | 30 ++++++++++++++------ 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.github/workflows/auto-release-generator.yml b/.github/workflows/auto-release-generator.yml index 73cf030..1fc81e6 100644 --- a/.github/workflows/auto-release-generator.yml +++ b/.github/workflows/auto-release-generator.yml @@ -72,19 +72,9 @@ jobs: if: steps.check-version.outputs.version_changed == 'true' id: get-commits run: | - # 尝试获取上一个标签,如果没有则获取最近50个提交 - LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") - if [ -z "$LAST_TAG" ]; then - echo "No previous tags found, getting last 50 commits" - COMMITS=$(git log -50 --pretty=format:"%s") - else - echo "Previous tag found: $LAST_TAG" - COMMITS=$(git log $LAST_TAG..HEAD --pretty=format:"%s") - # 如果没有提交,获取最近的10个提交 - if [ -z "$COMMITS" ]; then - COMMITS=$(git log -10 --pretty=format:"%s") - fi - fi + # 直接获取最近10个提交 + echo "Getting last 13 commits" + COMMITS=$(git log -13 --pretty=format:"%s") echo "Commits to be included in release notes:" echo "$COMMITS" diff --git a/app/config/config.py b/app/config/config.py index f98a081..4b2b0b4 100644 --- a/app/config/config.py +++ b/app/config/config.py @@ -6,6 +6,19 @@ from loguru import logger root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) config_file = f"{root_dir}/config.toml" +version_file = f"{root_dir}/project_version" + + +def get_version_from_file(): + """从project_version文件中读取版本号""" + try: + if os.path.isfile(version_file): + with open(version_file, "r", encoding="utf-8") as f: + return f.read().strip() + return "0.1.0" # 默认版本号 + except Exception as e: + logger.error(f"读取版本号文件失败: {str(e)}") + return "0.1.0" # 默认版本号 def load_config(): @@ -57,7 +70,8 @@ project_description = _cfg.get( "project_description", "https://github.com/linyqh/NarratoAI", ) -project_version = _cfg.get("app", {}).get("project_version") +# 从文件读取版本号,而不是从配置文件中获取 +project_version = get_version_from_file() reload_debug = False imagemagick_path = app.get("imagemagick_path", "") diff --git a/project_version b/project_version index d895844..a0a1517 100644 --- a/project_version +++ b/project_version @@ -1 +1 @@ -0.6.2.5 \ No newline at end of file +0.6.3 \ No newline at end of file diff --git a/webui/config/settings.py b/webui/config/settings.py index a4b3ada..449f7a7 100644 --- a/webui/config/settings.py +++ b/webui/config/settings.py @@ -4,6 +4,21 @@ from loguru import logger from typing import Dict, Any, Optional from dataclasses import dataclass +def get_version_from_file(): + """从project_version文件中读取版本号""" + try: + version_file = os.path.join( + os.path.dirname(os.path.dirname(os.path.dirname(__file__))), + "project_version" + ) + if os.path.isfile(version_file): + with open(version_file, "r", encoding="utf-8") as f: + return f.read().strip() + return "0.1.0" # 默认版本号 + except Exception as e: + logger.error(f"读取版本号文件失败: {str(e)}") + return "0.1.0" # 默认版本号 + @dataclass class WebUIConfig: """WebUI配置类""" @@ -16,7 +31,7 @@ class WebUIConfig: # Azure配置 azure: Dict[str, str] = None # 项目版本 - project_version: str = "0.1.0" + project_version: str = get_version_from_file() # 项目根目录 root_dir: str = None # Gemini API Key @@ -71,13 +86,13 @@ def load_config(config_path: Optional[str] = None) -> WebUIConfig: with open(config_path, "rb") as f: config_dict = tomli.load(f) - # 创建配置对象 + # 创建配置对象,使用从文件读取的版本号 config = WebUIConfig( ui=config_dict.get("ui", {}), proxy=config_dict.get("proxy", {}), app=config_dict.get("app", {}), azure=config_dict.get("azure", {}), - project_version=config_dict.get("project_version", "0.1.0") + # 不再从配置文件中获取project_version ) return config @@ -105,13 +120,13 @@ def save_config(config: WebUIConfig, config_path: Optional[str] = None) -> bool: # 确保目录存在 os.makedirs(os.path.dirname(config_path), exist_ok=True) - # 转换为字典 + # 转换为字典,不再保存版本号到配置文件 config_dict = { "ui": config.ui, "proxy": config.proxy, "app": config.app, - "azure": config.azure, - "project_version": config.project_version + "azure": config.azure + # 不再保存project_version到配置文件 } # 保存配置 @@ -153,8 +168,7 @@ def update_config(config_dict: Dict[str, Any]) -> bool: config.app.update(config_dict["app"]) if "azure" in config_dict: config.azure.update(config_dict["azure"]) - if "project_version" in config_dict: - config.project_version = config_dict["project_version"] + # 不再从配置字典更新project_version # 保存配置 return save_config(config)