优化版本号获取逻辑,直接从文件读取版本号,并简化发布说明生成流程

This commit is contained in:
linyq 2025-05-19 10:18:54 +08:00
parent 6e10adfecb
commit 7a8de5e791
4 changed files with 41 additions and 23 deletions

View File

@ -72,19 +72,9 @@ jobs:
if: steps.check-version.outputs.version_changed == 'true' if: steps.check-version.outputs.version_changed == 'true'
id: get-commits id: get-commits
run: | run: |
# 尝试获取上一个标签如果没有则获取最近50个提交 # 直接获取最近10个提交
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") echo "Getting last 13 commits"
if [ -z "$LAST_TAG" ]; then COMMITS=$(git log -13 --pretty=format:"%s")
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
echo "Commits to be included in release notes:" echo "Commits to be included in release notes:"
echo "$COMMITS" echo "$COMMITS"

View File

@ -6,6 +6,19 @@ from loguru import logger
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
config_file = f"{root_dir}/config.toml" 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(): def load_config():
@ -57,7 +70,8 @@ project_description = _cfg.get(
"project_description", "project_description",
"<a href='https://github.com/linyqh/NarratoAI'>https://github.com/linyqh/NarratoAI</a>", "<a href='https://github.com/linyqh/NarratoAI'>https://github.com/linyqh/NarratoAI</a>",
) )
project_version = _cfg.get("app", {}).get("project_version") # 从文件读取版本号,而不是从配置文件中获取
project_version = get_version_from_file()
reload_debug = False reload_debug = False
imagemagick_path = app.get("imagemagick_path", "") imagemagick_path = app.get("imagemagick_path", "")

View File

@ -1 +1 @@
0.6.2.5 0.6.3

View File

@ -4,6 +4,21 @@ from loguru import logger
from typing import Dict, Any, Optional from typing import Dict, Any, Optional
from dataclasses import dataclass 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 @dataclass
class WebUIConfig: class WebUIConfig:
"""WebUI配置类""" """WebUI配置类"""
@ -16,7 +31,7 @@ class WebUIConfig:
# Azure配置 # Azure配置
azure: Dict[str, str] = None azure: Dict[str, str] = None
# 项目版本 # 项目版本
project_version: str = "0.1.0" project_version: str = get_version_from_file()
# 项目根目录 # 项目根目录
root_dir: str = None root_dir: str = None
# Gemini API Key # Gemini API Key
@ -71,13 +86,13 @@ def load_config(config_path: Optional[str] = None) -> WebUIConfig:
with open(config_path, "rb") as f: with open(config_path, "rb") as f:
config_dict = tomli.load(f) config_dict = tomli.load(f)
# 创建配置对象 # 创建配置对象,使用从文件读取的版本号
config = WebUIConfig( config = WebUIConfig(
ui=config_dict.get("ui", {}), ui=config_dict.get("ui", {}),
proxy=config_dict.get("proxy", {}), proxy=config_dict.get("proxy", {}),
app=config_dict.get("app", {}), app=config_dict.get("app", {}),
azure=config_dict.get("azure", {}), azure=config_dict.get("azure", {}),
project_version=config_dict.get("project_version", "0.1.0") # 不再从配置文件中获取project_version
) )
return config 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) os.makedirs(os.path.dirname(config_path), exist_ok=True)
# 转换为字典 # 转换为字典,不再保存版本号到配置文件
config_dict = { config_dict = {
"ui": config.ui, "ui": config.ui,
"proxy": config.proxy, "proxy": config.proxy,
"app": config.app, "app": config.app,
"azure": config.azure, "azure": config.azure
"project_version": config.project_version # 不再保存project_version到配置文件
} }
# 保存配置 # 保存配置
@ -153,8 +168,7 @@ def update_config(config_dict: Dict[str, Any]) -> bool:
config.app.update(config_dict["app"]) config.app.update(config_dict["app"])
if "azure" in config_dict: if "azure" in config_dict:
config.azure.update(config_dict["azure"]) config.azure.update(config_dict["azure"])
if "project_version" in config_dict: # 不再从配置字典更新project_version
config.project_version = config_dict["project_version"]
# 保存配置 # 保存配置
return save_config(config) return save_config(config)