|
|
@@ -69,6 +69,16 @@ def move_files(day: int, config: dict) -> bool:
|
|
|
def git_commit(day: int, topic: str) -> bool:
|
|
|
"""Git 提交"""
|
|
|
try:
|
|
|
+ # 检查是否已有 tag
|
|
|
+ tag_name = f"v_day{day}_{topic.replace(' ', '_')}"
|
|
|
+ result = subprocess.run(
|
|
|
+ ["git", "tag", "-l", tag_name],
|
|
|
+ capture_output=True, text=True, cwd=PROJECT_ROOT
|
|
|
+ )
|
|
|
+ if result.returncode == 0 and result.stdout.strip():
|
|
|
+ print(f"⚠️ Tag {tag_name} 已存在,跳过提交")
|
|
|
+ return True # 已部署,返回成功
|
|
|
+
|
|
|
# git add
|
|
|
result = subprocess.run(
|
|
|
["git", "add", "."],
|
|
|
@@ -90,7 +100,6 @@ def git_commit(day: int, topic: str) -> bool:
|
|
|
print(f"✅ Git commit: {commit_msg}")
|
|
|
|
|
|
# git tag
|
|
|
- tag_name = f"v_day{day}_{topic.replace(' ', '_')}"
|
|
|
result = subprocess.run(
|
|
|
["git", "tag", tag_name],
|
|
|
capture_output=True, text=True, cwd=PROJECT_ROOT
|
|
|
@@ -105,11 +114,12 @@ def git_commit(day: int, topic: str) -> bool:
|
|
|
print(f"❌ Git 操作异常:{e}")
|
|
|
return False
|
|
|
|
|
|
-def git_push() -> bool:
|
|
|
+def git_push(config: dict) -> bool:
|
|
|
"""Git 推送"""
|
|
|
try:
|
|
|
+ branch = config.get("git_branch", "master")
|
|
|
result = subprocess.run(
|
|
|
- ["git", "push", "origin", "main", "--tags"],
|
|
|
+ ["git", "push", "origin", branch, "--tags"],
|
|
|
capture_output=True, text=True, cwd=PROJECT_ROOT
|
|
|
)
|
|
|
if result.returncode != 0:
|
|
|
@@ -161,7 +171,7 @@ def main():
|
|
|
sys.exit(1)
|
|
|
|
|
|
# Git 推送
|
|
|
- if not git_push():
|
|
|
+ if not git_push(config):
|
|
|
print("❌ Git 推送失败")
|
|
|
sys.exit(1)
|
|
|
|