refactor: 统一构建/发布脚本输出样式,更简约
- 添加 build.sh 调用脚本 - 移除装饰性分隔线和标题 - 移除进度输出,只保留必要的错误提示 - 使用 >>> 前缀标识脚本步骤
This commit is contained in:
66
build.py
66
build.py
@@ -58,27 +58,17 @@ def get_git_user_info() -> tuple[str, str]:
|
|||||||
try:
|
try:
|
||||||
name = get_git_config("user.name")
|
name = get_git_config("user.name")
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print("""
|
print("错误: git user.name 未设置")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print("请先配置 git 用户名:")
|
||||||
错误: git user.name 未设置
|
print(' git config --global user.name "Your Name"')
|
||||||
|
|
||||||
请先配置 git 用户名:
|
|
||||||
git config --global user.name "Your Name"
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
email = get_git_config("user.email")
|
email = get_git_config("user.email")
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print("""
|
print("错误: git user.email 未设置")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print("请先配置 git 邮箱:")
|
||||||
错误: git user.email 未设置
|
print(' git config --global user.email "your@email.com"')
|
||||||
|
|
||||||
请先配置 git 邮箱:
|
|
||||||
git config --global user.email "your@email.com"
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return name, email
|
return name, email
|
||||||
@@ -92,10 +82,8 @@ def clean_and_create_build_dir(build_dir: str) -> None:
|
|||||||
build_dir: 构建目录路径
|
build_dir: 构建目录路径
|
||||||
"""
|
"""
|
||||||
if os.path.exists(build_dir):
|
if os.path.exists(build_dir):
|
||||||
print(f"清理旧构建目录: {build_dir}")
|
|
||||||
shutil.rmtree(build_dir)
|
shutil.rmtree(build_dir)
|
||||||
os.makedirs(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:
|
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:
|
with open(target_path, "w", encoding="utf-8") as f:
|
||||||
f.write(new_content)
|
f.write(new_content)
|
||||||
|
|
||||||
print(f"生成: {target_path} (version: {version}, author: {author})")
|
|
||||||
|
|
||||||
|
|
||||||
def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
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:
|
try:
|
||||||
__import__("pyarmor")
|
__import__("pyarmor")
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("""
|
print("错误: PyArmor 未安装")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print("请使用以下命令:")
|
||||||
错误: PyArmor 未安装
|
print(" uv run --with pyarmor python build.py")
|
||||||
|
|
||||||
请使用以下命令:
|
|
||||||
|
|
||||||
uv run --with pyarmor python build.py
|
|
||||||
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# 临时目录
|
# 临时目录
|
||||||
@@ -246,8 +225,6 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
|||||||
source_dir
|
source_dir
|
||||||
]
|
]
|
||||||
|
|
||||||
print(f" 执行: {' '.join(cmd)}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
cmd,
|
cmd,
|
||||||
@@ -256,7 +233,7 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
|||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"\nPyArmor 混淆失败:")
|
print("错误: PyArmor 混淆失败")
|
||||||
print(f" 返回码: {e.returncode}")
|
print(f" 返回码: {e.returncode}")
|
||||||
print(f" 标准输出: {e.stdout}")
|
print(f" 标准输出: {e.stdout}")
|
||||||
print(f" 错误输出: {e.stderr}")
|
print(f" 错误输出: {e.stderr}")
|
||||||
@@ -294,16 +271,11 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
|||||||
# 清理临时目录
|
# 清理临时目录
|
||||||
os.rmdir(temp_dir)
|
os.rmdir(temp_dir)
|
||||||
|
|
||||||
print(" 混淆完成")
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""
|
"""
|
||||||
主函数:执行完整的混淆打包流程
|
主函数:执行完整的混淆打包流程
|
||||||
"""
|
"""
|
||||||
print("=" * 60)
|
|
||||||
print("Skill 打包构建 (混淆模式)")
|
|
||||||
print("=" * 60)
|
|
||||||
|
|
||||||
# 路径配置
|
# 路径配置
|
||||||
project_root = os.path.dirname(os.path.abspath(__file__))
|
project_root = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -313,37 +285,19 @@ def main() -> None:
|
|||||||
|
|
||||||
# 生成版本号
|
# 生成版本号
|
||||||
version = generate_timestamp()
|
version = generate_timestamp()
|
||||||
print(f"版本号: {version}")
|
|
||||||
|
|
||||||
# 读取 git 用户信息
|
# 读取 git 用户信息
|
||||||
git_name, git_email = get_git_user_info()
|
git_name, git_email = get_git_user_info()
|
||||||
author = f"{git_name} <{git_email}>"
|
author = f"{git_name} <{git_email}>"
|
||||||
print(f"作者: {author}")
|
|
||||||
print()
|
|
||||||
|
|
||||||
# 清理并创建 build 目录
|
# 清理并创建 build 目录
|
||||||
clean_and_create_build_dir(build_dir)
|
clean_and_create_build_dir(build_dir)
|
||||||
print()
|
|
||||||
|
|
||||||
# 复制 SKILL.md(动态注入元数据)
|
# 复制 SKILL.md(动态注入元数据)
|
||||||
copy_skill_md(skill_md_path, build_dir, version, author)
|
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)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
15
build.sh
Normal file
15
build.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# 混淆构建脚本
|
||||||
|
#
|
||||||
|
# 使用方式:
|
||||||
|
# ./build.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
echo ">>> 构建"
|
||||||
|
uv run --with pyarmor python build.py
|
||||||
|
echo ">>> 完成"
|
||||||
88
publish.py
88
publish.py
@@ -28,14 +28,9 @@ def check_build_dir(build_dir: str) -> None:
|
|||||||
SystemExit: 目录不存在时退出
|
SystemExit: 目录不存在时退出
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(build_dir):
|
if not os.path.exists(build_dir):
|
||||||
print("""
|
print("错误: build/ 目录不存在")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print("请先运行 build.py:")
|
||||||
错误: build/ 目录不存在
|
print(" uv run python build.py")
|
||||||
|
|
||||||
请先运行 build.py:
|
|
||||||
uv run python build.py
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@@ -50,14 +45,9 @@ def check_build_skill_md(build_skill_md_path: str) -> None:
|
|||||||
SystemExit: 文件不存在时退出
|
SystemExit: 文件不存在时退出
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(build_skill_md_path):
|
if not os.path.exists(build_skill_md_path):
|
||||||
print("""
|
print("错误: build/SKILL.md 不存在")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print("请先运行 build.py:")
|
||||||
错误: build/SKILL.md 不存在
|
print(" uv run python build.py")
|
||||||
|
|
||||||
请先运行 build.py:
|
|
||||||
uv run python build.py
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@@ -101,13 +91,8 @@ def parse_version_from_skill_md(skill_md_path: str) -> str:
|
|||||||
# metadata 块结束
|
# metadata 块结束
|
||||||
in_metadata = False
|
in_metadata = False
|
||||||
|
|
||||||
print("""
|
print("错误: 无法从 build/SKILL.md 解析版本号")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print("请检查 build/SKILL.md 是否包含 metadata.version 字段")
|
||||||
错误: 无法从 build/SKILL.md 解析版本号
|
|
||||||
|
|
||||||
请检查 build/SKILL.md 是否包含 metadata.version 字段
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@@ -149,21 +134,14 @@ def clone_repo(temp_dir: str) -> str:
|
|||||||
SystemExit: clone 失败时退出
|
SystemExit: clone 失败时退出
|
||||||
"""
|
"""
|
||||||
repo_dir = os.path.join(temp_dir, "skills-repo")
|
repo_dir = os.path.join(temp_dir, "skills-repo")
|
||||||
print(f"Clone 仓库: {TARGET_REPO_URL}")
|
|
||||||
print(f" 到: {repo_dir}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run_git_command(temp_dir, ["clone", "--depth", "1", TARGET_REPO_URL, "skills-repo"])
|
run_git_command(temp_dir, ["clone", "--depth", "1", TARGET_REPO_URL, "skills-repo"])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"""
|
print(f"错误: Clone 仓库失败")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print(f" 返回码: {e.returncode}")
|
||||||
错误: Clone 仓库失败
|
print(f" 标准输出: {e.stdout}")
|
||||||
|
print(f" 错误输出: {e.stderr}")
|
||||||
返回码: {e.returncode}
|
|
||||||
标准输出: {e.stdout}
|
|
||||||
错误输出: {e.stderr}
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return repo_dir
|
return repo_dir
|
||||||
@@ -182,7 +160,6 @@ def clear_target_dir(repo_dir: str) -> str:
|
|||||||
target_dir = os.path.join(repo_dir, TARGET_PATH)
|
target_dir = os.path.join(repo_dir, TARGET_PATH)
|
||||||
|
|
||||||
if os.path.exists(target_dir):
|
if os.path.exists(target_dir):
|
||||||
print(f"清空目标目录: {target_dir}")
|
|
||||||
shutil.rmtree(target_dir)
|
shutil.rmtree(target_dir)
|
||||||
|
|
||||||
os.makedirs(target_dir, exist_ok=True)
|
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 源目录
|
build_dir: build 源目录
|
||||||
target_dir: 目标目录
|
target_dir: 目标目录
|
||||||
"""
|
"""
|
||||||
print(f"复制 build/ 内容 -> {target_dir}")
|
|
||||||
|
|
||||||
for item in os.listdir(build_dir):
|
for item in os.listdir(build_dir):
|
||||||
src = os.path.join(build_dir, item)
|
src = os.path.join(build_dir, item)
|
||||||
dst = os.path.join(target_dir, item)
|
dst = os.path.join(target_dir, item)
|
||||||
|
|
||||||
if os.path.isdir(src):
|
if os.path.isdir(src):
|
||||||
shutil.copytree(src, dst)
|
shutil.copytree(src, dst)
|
||||||
print(f" 目录: {item}")
|
|
||||||
else:
|
else:
|
||||||
shutil.copy2(src, dst)
|
shutil.copy2(src, dst)
|
||||||
print(f" 文件: {item}")
|
|
||||||
|
|
||||||
|
|
||||||
def git_commit_and_push(repo_dir: str, version: str) -> None:
|
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}"
|
commit_message = f"publish: lyxy-document-reader {version}"
|
||||||
|
|
||||||
print(f"Git 提交: {commit_message}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run_git_command(repo_dir, ["add", "."])
|
run_git_command(repo_dir, ["add", "."])
|
||||||
run_git_command(repo_dir, ["commit", "-m", commit_message])
|
run_git_command(repo_dir, ["commit", "-m", commit_message])
|
||||||
print(" 推送中...")
|
|
||||||
run_git_command(repo_dir, ["push"])
|
run_git_command(repo_dir, ["push"])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"""
|
print(f"错误: Git 操作失败")
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
print(f" 返回码: {e.returncode}")
|
||||||
错误: Git 操作失败
|
print(f" 标准输出: {e.stdout}")
|
||||||
|
print(f" 错误输出: {e.stderr}")
|
||||||
返回码: {e.returncode}
|
|
||||||
标准输出: {e.stdout}
|
|
||||||
错误输出: {e.stderr}
|
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
""")
|
|
||||||
sys.exit(1)
|
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__))
|
project_root = os.path.dirname(os.path.abspath(__file__))
|
||||||
build_dir = os.path.join(project_root, "build")
|
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)
|
version = parse_version_from_skill_md(build_skill_md_path)
|
||||||
print(f"版本号: {version}")
|
|
||||||
print()
|
|
||||||
|
|
||||||
# 使用临时目录
|
# 使用临时目录
|
||||||
with tempfile.TemporaryDirectory(prefix="lyxy-publish-") as temp_dir:
|
with tempfile.TemporaryDirectory(prefix="lyxy-publish-") as temp_dir:
|
||||||
print(f"临时目录: {temp_dir}")
|
|
||||||
print()
|
|
||||||
|
|
||||||
# Clone 仓库
|
# Clone 仓库
|
||||||
repo_dir = clone_repo(temp_dir)
|
repo_dir = clone_repo(temp_dir)
|
||||||
print()
|
|
||||||
|
|
||||||
# 清空目标路径
|
# 清空目标路径
|
||||||
target_dir = clear_target_dir(repo_dir)
|
target_dir = clear_target_dir(repo_dir)
|
||||||
print()
|
|
||||||
|
|
||||||
# 复制内容
|
# 复制内容
|
||||||
copy_build_contents(build_dir, target_dir)
|
copy_build_contents(build_dir, target_dir)
|
||||||
print()
|
|
||||||
|
|
||||||
# Git 提交并推送
|
# Git 提交并推送
|
||||||
git_commit_and_push(repo_dir, version)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
20
publish.sh
20
publish.sh
@@ -10,21 +10,9 @@ set -e
|
|||||||
|
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
echo "============================================"
|
echo ">>> 构建 + 发布"
|
||||||
echo "Skill 混淆构建 + 发布"
|
echo "[1/2] 构建..."
|
||||||
echo "============================================"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# 1. 混淆构建
|
|
||||||
echo "[1/2] 执行混淆构建..."
|
|
||||||
uv run --with pyarmor python build.py
|
uv run --with pyarmor python build.py
|
||||||
echo
|
echo "[2/2] 发布..."
|
||||||
|
|
||||||
# 2. 发布
|
|
||||||
echo "[2/2] 执行发布..."
|
|
||||||
uv run python publish.py
|
uv run python publish.py
|
||||||
echo
|
echo ">>> 完成"
|
||||||
|
|
||||||
echo "============================================"
|
|
||||||
echo "完成!"
|
|
||||||
echo "============================================"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user