老板反馈:升级弹窗里的更新说明挤成一整段,看不出版本更新了哪几条。
两个原因,都修:
1. 弹窗的说明区用的是 textContent,CSS 没有 white-space:pre-wrap
→ 说明文本里的 \n 全被压成空格。加上 pre-wrap,行高也放宽到 1.7
2. 发布时的说明本来就是一段流水文字,没有编号 → 以后按「① ② ③」逐条写
publish.py 新增 --notes-file,多行说明从文件读,省得命令行转义
顺带把发布时间格式化:原来是 time::OffsetDateTime 的默认 Display,
显示成 "2:43:08.0 +00:00:00"(带微秒和时区尾巴,还是 UTC)。
改成按 unix_timestamp 转 chrono 本地时间,格式 %Y-%m-%d %H:%M。
验证:用真实 tauri-bridge.js + 假 __TAURI__ 渲染了一遍弹窗(截图确认):
发现新版本 v2.6.4
发布时间:2026-11-20 10:53
① 更新入口在状态栏右下角,蓝色「检查更新」
② 弹窗里不再显示当前版本,按钮居中
③ 更新说明按序号换行,发布时间改为本地时间
[立即升级] [稍后] ← 居中
已构建发布 2.6.4:xymd_2.6.4.exe + .sig,签名实验通过。
152 lines
5.6 KiB
Python
152 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
||
"""把小银 Markdown 的构建产物发布到官网,并生成升级清单。
|
||
|
||
用法:
|
||
python3 tools/release/publish.py --notes "更新说明……" # 用当前 tauri.conf.json 的版本
|
||
python3 tools/release/publish.py --notes "……" --dry-run
|
||
|
||
做的事:
|
||
1. 从 src-tauri/.../bundle/nsis/ 找安装包和 .sig 签名
|
||
2. 拷安装包到站点 download/(顺便拷一份免安装 exe)
|
||
3. 写 site/update/latest.json —— 客户端 updater 就拉这个
|
||
4. 打印最终 URL 与校验值
|
||
|
||
客户端地址:https://md.wangjinding.com/update/latest.json
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import argparse
|
||
import hashlib
|
||
import json
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
from datetime import datetime, timezone
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parents[2]
|
||
TARGET = ROOT / "src-tauri" / "target" / "x86_64-pc-windows-gnu" / "release"
|
||
NSIS_DIR = TARGET / "bundle" / "nsis"
|
||
SITE = ROOT / "site"
|
||
SITE_DOWNLOAD = Path("/opt/1panel/www/sites/md.wangjinding.com/index/download")
|
||
SITE_UPDATE = Path("/opt/1panel/www/sites/md.wangjinding.com/index/update")
|
||
BASE_URL = "https://md.wangjinding.com"
|
||
|
||
|
||
def conf_version() -> str:
|
||
d = json.loads((ROOT / "src-tauri" / "tauri.conf.json").read_text(encoding="utf-8"))
|
||
return d["version"]
|
||
|
||
|
||
def sha256(path: Path) -> str:
|
||
h = hashlib.sha256()
|
||
with path.open("rb") as f:
|
||
for chunk in iter(lambda: f.read(1 << 20), b""):
|
||
h.update(chunk)
|
||
return h.hexdigest()
|
||
|
||
|
||
def main() -> int:
|
||
ap = argparse.ArgumentParser()
|
||
ap.add_argument("--notes", default="", help="更新说明(会显示在客户的升级弹窗里)")
|
||
ap.add_argument("--notes-file", default="", help="从文件读更新说明,多行编号时用,避免命令行转义")
|
||
ap.add_argument("--dry-run", action="store_true")
|
||
args = ap.parse_args()
|
||
if args.notes_file:
|
||
args.notes = Path(args.notes_file).read_text(encoding="utf-8").strip()
|
||
|
||
version = conf_version()
|
||
setup = NSIS_DIR / f"XiaoyinMarkdown_{version}_x64-setup.exe"
|
||
sig_file = Path(str(setup) + ".sig")
|
||
|
||
if not setup.exists():
|
||
print(f"❌ 找不到安装包:{setup}", file=sys.stderr)
|
||
return 1
|
||
if not sig_file.exists():
|
||
print(f"❌ 找不到签名:{sig_file}\n 构建时是否漏了 TAURI_SIGNING_PRIVATE_KEY?", file=sys.stderr)
|
||
return 1
|
||
|
||
signature = sig_file.read_text(encoding="utf-8").strip()
|
||
size = setup.stat().st_size
|
||
digest = sha256(setup)
|
||
# 下载文件名带版本号:xymd_2.6.2.exe(浏览器另存就是这个名)
|
||
dl_name = f"xymd_{version}.exe"
|
||
url = f"{BASE_URL}/download/{dl_name}"
|
||
|
||
manifest = {
|
||
"version": version,
|
||
"notes": args.notes or f"小银 Markdown v{version}",
|
||
"pub_date": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||
"platforms": {
|
||
"windows-x86_64": {
|
||
"signature": signature,
|
||
"url": url,
|
||
"size": size,
|
||
"sha256": digest,
|
||
}
|
||
},
|
||
}
|
||
|
||
print(f" 版本 : {version}")
|
||
print(f" 安装包 : {setup.name} {size/1048576:.2f} MB")
|
||
print(f" sha256 : {digest[:32]}…")
|
||
print(f" 签名 : {signature[:40]}…")
|
||
print(f" 下载地址 : {url}")
|
||
|
||
if args.dry_run:
|
||
print(" [dry-run] 不写入任何文件")
|
||
return 0
|
||
|
||
SITE_UPDATE.mkdir(parents=True, exist_ok=True)
|
||
SITE_DOWNLOAD.mkdir(parents=True, exist_ok=True)
|
||
|
||
# ① 安装包(客户下载 + updater 拉取的是同一个)
|
||
shutil.copy2(setup, SITE_DOWNLOAD / setup.name)
|
||
(SITE_DOWNLOAD / setup.name).chmod(0o644)
|
||
|
||
# ② 免安装版
|
||
portable = TARGET / "xiaoyin-markdown.exe"
|
||
if portable.exists():
|
||
shutil.copy2(portable, SITE_DOWNLOAD / "XiaoyinMarkdown-portable.exe")
|
||
(SITE_DOWNLOAD / "XiaoyinMarkdown-portable.exe").chmod(0o644)
|
||
|
||
# ③ 升级清单(站点 + 仓库各存一份,方便回滚)
|
||
body = json.dumps(manifest, ensure_ascii=False, indent=2) + "\n"
|
||
(SITE_UPDATE / "latest.json").write_text(body, encoding="utf-8")
|
||
(SITE / "update").mkdir(parents=True, exist_ok=True)
|
||
(SITE / "update" / "latest.json").write_text(body, encoding="utf-8")
|
||
|
||
# ④ 带版本号的文件名(浏览器另存为 xymd_<版本>.exe)
|
||
for name, real in ((dl_name, setup.name), (f"xymd_{version}_portable.exe", "XiaoyinMarkdown-portable.exe")):
|
||
link = SITE_DOWNLOAD / name
|
||
if link.is_symlink() or link.exists():
|
||
link.unlink()
|
||
if (SITE_DOWNLOAD / real).exists():
|
||
link.symlink_to(real)
|
||
|
||
# ⑤ 稳定别名:官网页固定链到 latest-setup.exe,发版不用改 HTML
|
||
for alias, real in (("latest-setup.exe", setup.name), ("latest-portable.exe", "XiaoyinMarkdown-portable.exe")):
|
||
link = SITE_DOWNLOAD / alias
|
||
if link.is_symlink() or link.exists():
|
||
link.unlink()
|
||
link.symlink_to(real)
|
||
|
||
# ⑤ 官网静态兜底版本号也一起改(正常浏览器会被 latest.json 覆盖,这是给无 JS 情况的)
|
||
import re as _re
|
||
idx = SITE / "index.html"
|
||
if idx.exists():
|
||
html = idx.read_text(encoding="utf-8")
|
||
html2 = _re.sub(r"(data-ver>)\d+\.\d+\.\d+", lambda m: m.group(1) + version, html)
|
||
if html2 != html:
|
||
idx.write_text(html2, encoding="utf-8")
|
||
|
||
print(f"\n ✅ 已发布:{BASE_URL}/update/latest.json")
|
||
print(f" ✅ 稳定别名:{BASE_URL}/download/latest-setup.exe")
|
||
print(f" ✅ 版本文件名:{url}")
|
||
print(f" ✅ 安装包:{url}")
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
raise SystemExit(main())
|