feat: 支持按 Tag 打包,分支管理可添加 Tag
- 分支管理新增「分支 / Tag」类型选择,Tag 存于 config["tags"],与分支不可重名 - 每个 Tag 与分支一样拥有同名独立版本轨道,默认上架轨 - 打包页按「分支」「Tag」分组选择;任务新增 ref_type 字段记录引用类型 - Tag 打包时 fetch --tags --force 后以游离 HEAD 检出 refs/tags/<tag> - 历史记录与下载页按类型显示「分支」或「Tag」 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -291,8 +291,8 @@ def _db_update(db, task, **fields):
|
||||
db.commit()
|
||||
|
||||
|
||||
async def update_source(task_id: str, source_dir: Path, branch: str):
|
||||
"""将共享源码工作目录强制同步到指定远程分支。"""
|
||||
async def update_source(task_id: str, source_dir: Path, branch: str, ref_type: str = "branch"):
|
||||
"""将共享源码工作目录强制同步到指定远程分支或 Tag(ref_type="tag" 时 branch 为 Tag 名)。"""
|
||||
remote_url = get_git_remote_url(with_credentials=True)
|
||||
remote_url_masked = mask_git_remote_url(remote_url)
|
||||
git_env = _git_env()
|
||||
@@ -321,7 +321,8 @@ async def update_source(task_id: str, source_dir: Path, branch: str):
|
||||
if not cloned and not (source_dir / ".git").exists():
|
||||
raise Exception(f"共享源码目录不是 Git 仓库: {source_dir}")
|
||||
|
||||
await log_streamer.emit(task_id, f"同步共享源码到分支: {branch}")
|
||||
is_tag = ref_type == "tag"
|
||||
await log_streamer.emit(task_id, f"同步共享源码到{'Tag' if is_tag else '分支'}: {branch}")
|
||||
|
||||
if remote_url:
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
@@ -333,12 +334,22 @@ async def update_source(task_id: str, source_dir: Path, branch: str):
|
||||
if process.returncode != 0:
|
||||
raise Exception("git remote set-url 失败")
|
||||
|
||||
commands = [
|
||||
(("git", "fetch", "origin"), "git fetch 失败"),
|
||||
(("git", "checkout", "-B", branch, f"origin/{branch}"), f"git checkout {branch} 失败"),
|
||||
(("git", "reset", "--hard", f"origin/{branch}"), f"git reset {branch} 失败"),
|
||||
(("git", "clean", "-ffdx"), "git clean 失败"),
|
||||
]
|
||||
if is_tag:
|
||||
# Tag 检出为游离 HEAD;--force 让远端被移动过的 Tag 覆盖本地旧 Tag
|
||||
tag_ref = f"refs/tags/{branch}"
|
||||
commands = [
|
||||
(("git", "fetch", "origin", "--tags", "--force"), "git fetch 失败"),
|
||||
(("git", "checkout", "--detach", tag_ref), f"git checkout Tag {branch} 失败"),
|
||||
(("git", "reset", "--hard", tag_ref), f"git reset Tag {branch} 失败"),
|
||||
(("git", "clean", "-ffdx"), "git clean 失败"),
|
||||
]
|
||||
else:
|
||||
commands = [
|
||||
(("git", "fetch", "origin"), "git fetch 失败"),
|
||||
(("git", "checkout", "-B", branch, f"origin/{branch}"), f"git checkout {branch} 失败"),
|
||||
(("git", "reset", "--hard", f"origin/{branch}"), f"git reset {branch} 失败"),
|
||||
(("git", "clean", "-ffdx"), "git clean 失败"),
|
||||
]
|
||||
for command, error_message in commands:
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
*_GIT_NO_CREDENTIAL_HELPER, *command[1:], env=git_env,
|
||||
@@ -375,7 +386,7 @@ async def prepare_source_snapshot(task_id: str, task) -> tuple[Path, str]:
|
||||
source_dir = get_source_dir(task.branch)
|
||||
if not source_dir.exists():
|
||||
raise Exception(
|
||||
f"分支源码目录不存在: {source_dir},请先在 GIT_SOURCE_BASE 下准备分支代码,或配置 GIT_REMOTE_URL"
|
||||
f"分支源码目录不存在: {source_dir},请先在 GIT_SOURCE_BASE 下准备分支(或 Tag)代码,或配置 GIT_REMOTE_URL"
|
||||
)
|
||||
await log_streamer.emit(task_id, f"使用分支源码: {source_dir}")
|
||||
return await copy_source_code(task_id, task, source_dir), ""
|
||||
@@ -384,7 +395,8 @@ async def prepare_source_snapshot(task_id: str, task) -> tuple[Path, str]:
|
||||
await log_streamer.emit(task_id, "等待共享源码准备队列...")
|
||||
async with source_prepare_lock:
|
||||
await log_streamer.emit(task_id, "开始准备共享源码快照")
|
||||
await update_source(task_id, source_dir, task.branch)
|
||||
ref_type = "tag" if task.ref_type == "tag" else "branch"
|
||||
await update_source(task_id, source_dir, task.branch, ref_type)
|
||||
commit = await get_source_commit(source_dir)
|
||||
await log_streamer.emit(task_id, f"源码版本: {task.branch} @ {commit}")
|
||||
build_dir = await copy_source_code(task_id, task, source_dir)
|
||||
@@ -433,6 +445,7 @@ async def run_build_task(task_id: str):
|
||||
await asyncio.to_thread(_db_update, db, task, current_step="config")
|
||||
config_data = await generate_config(task_id, task, build_dir)
|
||||
config_data["SOURCE_BRANCH"] = task.branch
|
||||
config_data["SOURCE_REF_TYPE"] = "tag" if task.ref_type == "tag" else "branch"
|
||||
config_data["SOURCE_COMMIT"] = source_commit
|
||||
await asyncio.to_thread(_db_update, db, task,
|
||||
config_json=json.dumps(config_data, ensure_ascii=False))
|
||||
|
||||
Reference in New Issue
Block a user