refactor: 统一构建/发布脚本输出样式,更简约

- 添加 build.sh 调用脚本
- 移除装饰性分隔线和标题
- 移除进度输出,只保留必要的错误提示
- 使用 >>> 前缀标识脚本步骤
This commit is contained in:
2026-03-15 12:54:40 +08:00
parent 78063b9e07
commit a578c0b7ac
4 changed files with 45 additions and 144 deletions

View File

@@ -28,14 +28,9 @@ def check_build_dir(build_dir: str) -> None:
SystemExit: 目录不存在时退出
"""
if not os.path.exists(build_dir):
print("""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
错误: build/ 目录不存在
请先运行 build.py:
uv run python build.py
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
""")
print("错误: build/ 目录不存在")
print("请先运行 build.py:")
print(" uv run python build.py")
sys.exit(1)
@@ -50,14 +45,9 @@ def check_build_skill_md(build_skill_md_path: str) -> None:
SystemExit: 文件不存在时退出
"""
if not os.path.exists(build_skill_md_path):
print("""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
错误: build/SKILL.md 不存在
请先运行 build.py:
uv run python build.py
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
""")
print("错误: build/SKILL.md 不存在")
print("请先运行 build.py:")
print(" uv run python build.py")
sys.exit(1)
@@ -101,13 +91,8 @@ def parse_version_from_skill_md(skill_md_path: str) -> str:
# metadata 块结束
in_metadata = False
print("""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
错误: 无法从 build/SKILL.md 解析版本号
请检查 build/SKILL.md 是否包含 metadata.version 字段
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
""")
print("错误: 无法从 build/SKILL.md 解析版本号")
print("请检查 build/SKILL.md 是否包含 metadata.version 字段")
sys.exit(1)
@@ -149,21 +134,14 @@ def clone_repo(temp_dir: str) -> str:
SystemExit: clone 失败时退出
"""
repo_dir = os.path.join(temp_dir, "skills-repo")
print(f"Clone 仓库: {TARGET_REPO_URL}")
print(f" 到: {repo_dir}")
try:
run_git_command(temp_dir, ["clone", "--depth", "1", TARGET_REPO_URL, "skills-repo"])
except subprocess.CalledProcessError as e:
print(f"""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
错误: Clone 仓库失败
返回码: {e.returncode}
标准输出: {e.stdout}
错误输出: {e.stderr}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
""")
print(f"错误: Clone 仓库失败")
print(f" 返回码: {e.returncode}")
print(f" 标准输出: {e.stdout}")
print(f" 错误输出: {e.stderr}")
sys.exit(1)
return repo_dir
@@ -182,7 +160,6 @@ def clear_target_dir(repo_dir: str) -> str:
target_dir = os.path.join(repo_dir, TARGET_PATH)
if os.path.exists(target_dir):
print(f"清空目标目录: {target_dir}")
shutil.rmtree(target_dir)
os.makedirs(target_dir, exist_ok=True)
@@ -197,18 +174,14 @@ def copy_build_contents(build_dir: str, target_dir: str) -> None:
build_dir: build 源目录
target_dir: 目标目录
"""
print(f"复制 build/ 内容 -> {target_dir}")
for item in os.listdir(build_dir):
src = os.path.join(build_dir, item)
dst = os.path.join(target_dir, item)
if os.path.isdir(src):
shutil.copytree(src, dst)
print(f" 目录: {item}")
else:
shutil.copy2(src, dst)
print(f" 文件: {item}")
def git_commit_and_push(repo_dir: str, version: str) -> None:
@@ -224,23 +197,15 @@ def git_commit_and_push(repo_dir: str, version: str) -> None:
"""
commit_message = f"publish: lyxy-document-reader {version}"
print(f"Git 提交: {commit_message}")
try:
run_git_command(repo_dir, ["add", "."])
run_git_command(repo_dir, ["commit", "-m", commit_message])
print(" 推送中...")
run_git_command(repo_dir, ["push"])
except subprocess.CalledProcessError as e:
print(f"""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
错误: Git 操作失败
返回码: {e.returncode}
标准输出: {e.stdout}
错误输出: {e.stderr}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
""")
print(f"错误: Git 操作失败")
print(f" 返回码: {e.returncode}")
print(f" 标准输出: {e.stdout}")
print(f" 错误输出: {e.stderr}")
sys.exit(1)
@@ -248,10 +213,6 @@ def main() -> None:
"""
主函数:执行完整的发布流程
"""
print("=" * 60)
print("Skill 发布")
print("=" * 60)
# 路径配置
project_root = os.path.dirname(os.path.abspath(__file__))
build_dir = os.path.join(project_root, "build")
@@ -263,37 +224,20 @@ def main() -> None:
# 解析版本号
version = parse_version_from_skill_md(build_skill_md_path)
print(f"版本号: {version}")
print()
# 使用临时目录
with tempfile.TemporaryDirectory(prefix="lyxy-publish-") as temp_dir:
print(f"临时目录: {temp_dir}")
print()
# Clone 仓库
repo_dir = clone_repo(temp_dir)
print()
# 清空目标路径
target_dir = clear_target_dir(repo_dir)
print()
# 复制内容
copy_build_contents(build_dir, target_dir)
print()
# Git 提交并推送
git_commit_and_push(repo_dir, version)
print()
# 完成信息
print("=" * 60)
print("发布完成!")
print(f"版本号: {version}")
print(f"目标仓库: {TARGET_REPO_URL}")
print(f"目标路径: {TARGET_PATH}")
print("=" * 60)
if __name__ == "__main__":