Files
MonkeyCode/desktop/scripts/gen-latest-json.py
xiaomakuaiz 1d99f4fb89 feat(desktop): 补齐 Linux 打包,并把打包配置移出 Tauri 平台自动合并名
Linux 此前完全没有打包路径。补 deb + rpm + AppImage:bundle.linux.conf.json、
Makefile 的 linux/linux-release/engine-linux/check-linux、
gen-latest-json.py 的 linux 通道、desktop-linux.yml(tag 触发)。

**本地真打过**:deb 与 rpm 产物已验证内容——sidecar 落 usr/bin/ohmyagent
(20MB)、图标落 hicolor 的 32/128/256@2/512 四档、.desktop 条目在、
依赖声明正确。AppImage 在本机差最后一步(构建机缺 xdg-open,见下),CI 装了
xdg-utils;deb/rpm 走的是同一条 bundler 主路径,已跑通。

顺带修掉两个只有真打包才会暴露的问题:
1. deb 依赖重复。Tauri 的 deb bundler 会自动补 libwebkit2gtk-4.1-0 /
   libgtk-3-0 / libayatana-appindicator3-1,我再写显式 depends 就让 control
   里出现重复项、且 appindicator 同时落进 Depends 与 Recommends。改成 deb
   只留 gstreamer 到 recommends(mp3 提示音,缺了只是没声);rpm 侧未观察到
   自动补包级依赖,保留显式 depends。这处不对称在 Makefile 注明是实测所得。
2. AppImage bundler 会把系统的 xdg-open 复制进包,缺了要等 release 编译跑完
   三分钟之后才报错。check-linux 前置查掉。实测仅把 xdg-open 放进 PATH 不够,
   bundler 按系统路径找 —— 注释里钉住了这一点。

Linux 自更新只对 AppImage 有效:updater 在 Linux 是原地替换当前 AppImage
文件(tauri-plugin-updater::install_appimage),deb/rpm 装出来的是 /usr/bin 下
的普通可执行文件,覆盖它既越权又会搞乱包管理器记录。main.rs 新增
updater_supported():非 AppImage 运行直接不提供更新能力,而不是让用户点了
"更新"再收一个权限错误。三个更新入口都经 build_updater 收口,守卫只放一处。

---

**重命名 tauri.{macos,windows,win7}.conf.json → bundle.*.conf.json**

加 Linux 配置时撞上的:tauri.<平台>.conf.json 是 Tauri 的平台自动合并约定
(tauri-utils/src/config/parse.rs 的 into_platform_file_name),这个名字
**一存在就生效、不需要 --config**,会被并进该平台上的每次 cargo build/check。
实测:仅仅创建 tauri.linux.conf.json,本机 `cargo check` 就报
"resource path binaries/ohmyagent-x86_64-unknown-linux-gnu doesn't exist"
—— 打包专属的 active/externalBin/resources 全被拖进了普通开发构建。

推论同样适用于既有的两个文件,也就是说 desktop-check.yml 的 windows job
(以及我上一轮加的 macos job)本来就跑不过:它们只跑 cargo check,既没编
sidecar 也没建 browser-extension/dist,而平台配置会把这两样都变成硬依赖。
重命名后普通 cargo check 零告警通过,打包配置只经 --config 显式传入。

check_bundle_configs.py 把这条铁律做成守卫:凡出现平台自动合并名(json/
json5/toml 三种格式)即报错并给出应改的名字;顺带按目标平台要求图标格式
(nsis/msi→.ico、app/dmg→.icns、deb/rpm/appimage→.png)。反向验证过:
改回 tauri.linux.conf.json 后检查器报错,且 cargo check 确实被拖挂。

验证:cargo check --all-targets --locked 零告警;cargo test 100 passed
(连跑 3 次稳定)+ 真引擎 --include-ignored 106 passed;三个检查器 OK;
scripts 单测 27 passed(新增 4 例覆盖自动合并名与 Linux 图标);
UI 27 files 199 passed;五个 workflow YAML 解析通过。

留待人工:AppImage 产物需在装了 xdg-utils 的机器/CI 上出一次并试装;
deb/rpm 已出包但未在干净发行版上实测安装与托盘/提示音。
2026-07-25 11:17:34 +00:00

86 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""汇集 updater 发布物:重命名为带版本文件名 + 生成对应平台的更新清单。
用法: gen-latest-json.py [macos|windows|win7|linux] (缺省 macos)
四条更新通道各自独立,清单由对应平台的发布构建产出,互不协调:
macos → latest.json (darwin 双架构,universal .app.tar.gz)
windows → latest-windows.json (windows-x86_64,NSIS setup exe)
win7 → latest-win7.json (windows-x86_64,NSIS setup exe,捆 WebView2)
linux → latest-linux.json (linux-x86_64,**只有 AppImage**)
Linux 只发 AppImage:updater 在 Linux 是把新包原地覆盖当前 AppImage 文件
(tauri-plugin-updater 的 install_appimage),deb/rpm 装出来的是 /usr/bin 下
的普通可执行文件,覆盖不了也不该覆盖——那两种由包管理器负责升级,壳侧对
非 AppImage 运行直接不提示更新(main.rs updater_supported)。
产物集中在 bundle 目录下的 updater/,人工上传 OSS(public/desktop/):
先传包,再覆盖清单,顺序保证客户端不会拉到不存在的包。
"""
import json
import pathlib
import shutil
import sys
from datetime import datetime, timezone
# Windows 的 Python 默认 locale 编码(cp1252):文件读写与 stdout/stderr 的
# 中文都会炸,进程内所有文本 IO 统一钉死 UTF-8
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
ROOT = pathlib.Path(__file__).resolve().parent.parent
URL_BASE = "https://release.monkeycode-ai.com/public/desktop/"
# 显式 UTF-8:Windows 的 Python 默认用 locale 编码(cp1252),读含中文的文件会炸
version = json.loads((ROOT / "tauri.conf.json").read_text(encoding="utf-8"))["version"]
short = version.removesuffix(".0.0") # 26071401.0.0 → 26071401
platform = sys.argv[1] if len(sys.argv) > 1 else "macos"
if platform == "macos":
bundle = ROOT / "target/universal-apple-darwin/release/bundle"
src = bundle / "macos/MonkeyCode.app.tar.gz"
name = f"MonkeyCode_{short}_universal.app.tar.gz"
manifest_name = "latest.json"
# universal 包同时服务两种架构,两个 target key 指向同一 URL
targets = ["darwin-aarch64", "darwin-x86_64"]
elif platform in ("windows", "win7"):
bundle = ROOT / "target/release/bundle"
src = bundle / f"nsis/MonkeyCode_{version}_x64-setup.exe"
# win7 包重命名区分通道(OSS 同目录),minisign 签名只关心内容与文件名无关
suffix = "-win7" if platform == "win7" else ""
name = f"MonkeyCode_{short}_x64-setup{suffix}.exe"
manifest_name = f"latest-{platform}.json"
targets = ["windows-x86_64"]
elif platform == "linux":
bundle = ROOT / "target/release/bundle"
# AppImage 文件名用 Tauri 的 x86_64 命名(非 deb 的 amd64)
src = bundle / f"appimage/MonkeyCode_{version}_amd64.AppImage"
name = f"MonkeyCode_{short}_amd64.AppImage"
manifest_name = "latest-linux.json"
targets = ["linux-x86_64"]
else:
sys.exit(f"未知平台: {platform}(可选 macos/windows/win7/linux)")
sig = pathlib.Path(str(src) + ".sig")
if not src.exists() or not sig.exists():
sys.exit(
f"缺少 updater 产物: {src}(.sig)\n"
"需要带签名的发布构建(--config tauri.release.conf.json,"
"设置 TAURI_SIGNING_PRIVATE_KEY)"
)
out = bundle / "updater"
out.mkdir(exist_ok=True)
shutil.copy2(src, out / name)
entry = {"signature": sig.read_text(encoding="utf-8"), "url": URL_BASE + name}
manifest = {
"version": version,
"pub_date": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"platforms": {t: entry for t in targets},
}
(out / manifest_name).write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print(f"updater 产物就绪: {out / name} + {manifest_name}(版本 {version})")