diff --git a/build.py b/build.py index 600183a..008be42 100644 --- a/build.py +++ b/build.py @@ -58,27 +58,17 @@ def get_git_user_info() -> tuple[str, str]: try: name = get_git_config("user.name") except subprocess.CalledProcessError: - print(""" -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - 错误: git user.name 未设置 - - 请先配置 git 用户名: - git config --global user.name "Your Name" -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - """) + print("错误: git user.name 未设置") + print("请先配置 git 用户名:") + print(' git config --global user.name "Your Name"') sys.exit(1) try: email = get_git_config("user.email") except subprocess.CalledProcessError: - print(""" -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - 错误: git user.email 未设置 - - 请先配置 git 邮箱: - git config --global user.email "your@email.com" -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - """) + print("错误: git user.email 未设置") + print("请先配置 git 邮箱:") + print(' git config --global user.email "your@email.com"') sys.exit(1) return name, email @@ -92,10 +82,8 @@ def clean_and_create_build_dir(build_dir: str) -> None: build_dir: 构建目录路径 """ if os.path.exists(build_dir): - print(f"清理旧构建目录: {build_dir}") shutil.rmtree(build_dir) os.makedirs(build_dir) - print(f"创建构建目录: {build_dir}") def copy_skill_md(source_path: str, target_dir: str, version: str, author: str) -> None: @@ -203,8 +191,6 @@ def copy_skill_md(source_path: str, target_dir: str, version: str, author: str) with open(target_path, "w", encoding="utf-8") as f: f.write(new_content) - print(f"生成: {target_path} (version: {version}, author: {author})") - def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None: """ @@ -218,16 +204,9 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None: try: __import__("pyarmor") except ImportError: - print(""" -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - 错误: PyArmor 未安装 - - 请使用以下命令: - - uv run --with pyarmor python build.py - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - """) + print("错误: PyArmor 未安装") + print("请使用以下命令:") + print(" uv run --with pyarmor python build.py") sys.exit(1) # 临时目录 @@ -246,8 +225,6 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None: source_dir ] - print(f" 执行: {' '.join(cmd)}") - try: result = subprocess.run( cmd, @@ -256,7 +233,7 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None: text=True ) except subprocess.CalledProcessError as e: - print(f"\nPyArmor 混淆失败:") + print("错误: PyArmor 混淆失败") print(f" 返回码: {e.returncode}") print(f" 标准输出: {e.stdout}") print(f" 错误输出: {e.stderr}") @@ -294,16 +271,11 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None: # 清理临时目录 os.rmdir(temp_dir) - print(" 混淆完成") - def main() -> None: """ 主函数:执行完整的混淆打包流程 """ - print("=" * 60) - print("Skill 打包构建 (混淆模式)") - print("=" * 60) # 路径配置 project_root = os.path.dirname(os.path.abspath(__file__)) @@ -313,37 +285,19 @@ def main() -> None: # 生成版本号 version = generate_timestamp() - print(f"版本号: {version}") # 读取 git 用户信息 git_name, git_email = get_git_user_info() author = f"{git_name} <{git_email}>" - print(f"作者: {author}") - print() # 清理并创建 build 目录 clean_and_create_build_dir(build_dir) - print() # 复制 SKILL.md(动态注入元数据) copy_skill_md(skill_md_path, build_dir, version, author) - print() # 混淆代码 - print("────────────────────────────────────────") - print(" 使用 PyArmor 混淆代码 (Normal Mode)") - print("────────────────────────────────────────") obfuscate_scripts_dir(scripts_source_dir, build_dir) - print() - - # 完成信息 - print("=" * 60) - print("构建完成!") - print(f"版本号: {version}") - print(f"作者: {author}") - print("混淆模式: 已生成 .pyx 和 pyarmor_runtime") - print(f"输出目录: {build_dir}") - print("=" * 60) if __name__ == "__main__": diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..a76881a --- /dev/null +++ b/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# +# 混淆构建脚本 +# +# 使用方式: +# ./build.sh +# + +set -e + +cd "$(dirname "$0")" + +echo ">>> 构建" +uv run --with pyarmor python build.py +echo ">>> 完成" diff --git a/publish.py b/publish.py index bf8ac12..47a504b 100644 --- a/publish.py +++ b/publish.py @@ -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__": diff --git a/publish.sh b/publish.sh index c0bdb2f..9dbc4a0 100755 --- a/publish.sh +++ b/publish.sh @@ -10,21 +10,9 @@ set -e cd "$(dirname "$0")" -echo "============================================" -echo "Skill 混淆构建 + 发布" -echo "============================================" -echo - -# 1. 混淆构建 -echo "[1/2] 执行混淆构建..." +echo ">>> 构建 + 发布" +echo "[1/2] 构建..." uv run --with pyarmor python build.py -echo - -# 2. 发布 -echo "[2/2] 执行发布..." +echo "[2/2] 发布..." uv run python publish.py -echo - -echo "============================================" -echo "完成!" -echo "============================================" +echo ">>> 完成"