Files
HW-Debug-Tools/SerialMate/src/package_release.py
T
hulk d133906d32 feat: 新增 SerialMate 串口调试助手 v0.1.0
- 协议帧构成令牌序列可定制(包头/板ID/LEN口径/5种CRC x 3种覆盖), 默认兼容 DLPilot 光机协议
2026-09-27 18:52:54 +08:00

62 lines
2.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
组装 SerialMate 发布包: exe + README → 一个 zip(解压即用)
================================================
把主 README 复制进 release/ 后, 与单文件 exe 一起压成 zip —— 两者内容一致。
zip 解压后根目录为 SerialMate/:
SerialMate.exe 主程序(先运行 build_exe.py 打包)
README.md 使用说明
用法:
python package_release.py 版本号自动取最近 git tag(SerialMate-v*)
python package_release.py 0.1.0 手动指定版本号
产物: release/SerialMate-v<版本>-win64.zip(zip 不入库, 上传到 Gitea Release)
"""
import os
import shutil
import subprocess
import sys
import zipfile
SRC = os.path.dirname(os.path.abspath(__file__))
BASE = os.path.dirname(SRC)
RELEASE = os.path.join(BASE, 'release')
def detect_version():
"""从最近的 SerialMate-v* tag 推断版本号, 无 tag 则报错提示手动指定"""
try:
out = subprocess.check_output(
['git', 'describe', '--tags', '--abbrev=0', '--match', 'SerialMate-v*'],
cwd=BASE, stderr=subprocess.DEVNULL)
return out.decode().strip().removeprefix('SerialMate-v')
except Exception:
sys.exit('未能从 git tag 推断版本号, 请手动指定: python package_release.py <版本号>')
def main():
version = (sys.argv[1] if len(sys.argv) > 1 else detect_version()).lstrip('v')
exe = os.path.join(RELEASE, 'SerialMate.exe')
readme = os.path.join(BASE, 'README.md')
if not os.path.exists(exe):
sys.exit('缺少 release/SerialMate.exe, 先运行: python build_exe.py')
if not os.path.exists(readme):
sys.exit(f'缺少 {readme}')
shutil.copy2(readme, os.path.join(RELEASE, 'README.md'))
zip_name = f'SerialMate-v{version}-win64.zip'
zip_path = os.path.join(RELEASE, zip_name)
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as z:
z.write(exe, f'SerialMate/{os.path.basename(exe)}')
z.write(os.path.join(RELEASE, 'README.md'), 'SerialMate/README.md')
print(f'发布文件夹: {RELEASE} (exe + README)')
print(f'发布包: {zip_path} ({os.path.getsize(zip_path) / 1024 / 1024:.1f} MB)')
print('下一步上传: python publish_gitea.py', zip_name)
if __name__ == '__main__':
main()