소스 검색

fix(mathlab): 让 deploy 脚本幂等并使用配置分支推送

Daily Deploy Bot 2 주 전
부모
커밋
1812d13639
2개의 변경된 파일15개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      skills/mathlab/config.yaml
  2. 14 4
      skills/mathlab/scripts/deploy_day.py

+ 1 - 1
skills/mathlab/config.yaml

@@ -30,7 +30,7 @@ textbooks:
 
 # Git 仓库配置
 gogs_url: "https://code.indigofloyd.space/ClawLab/mathlab.git"
-git_branch: "main"
+git_branch: "master"
 gogs_username: "OpenClaw"
 gogs_password: "OpenClaw123456"
 

+ 14 - 4
skills/mathlab/scripts/deploy_day.py

@@ -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)