Files
image-workbench-desktop/scripts/publish-update.sh
T
qiqi 0851c22574
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 45s
fix(release): publish-update.sh 合并 windows 条目进 latest.json + 新增 win AI 协作说明
根因:win 应用 endpoints 只配 latest.json,但 publish-update.sh 旧逻辑硬编码只写 darwin 两平台、丢弃 windows 条目 → 每次 mac 发版都抹掉 windows,win 用户「检查更新」找不到自己平台、卡「正在检查…」(v3.25.31 实测踩过,当时手工合并救火)。

修法:写 latest.json 时从 latest-windows.json 读 windows 条目,【仅当 win 清单 version == 本次 mac version(三平台同批)】才合并;版本不一致则拒绝合并并提示「待 win 同批后重跑本脚本」,避免顶层 version 新、win 包旧导致 updater 反复提示同一旧包的死循环。
单测:UPD_VERSION=3.25.31 同批→三平台齐平;=3.25.32 win 没跟上→拒绝合并+警告。bash -n 语法通过。

另:docs/AI-HANDOFF-WINDOWS.md 给 win 端 AI 的认知/边界说明(架构根因、发布链路、职责边界、踩坑记录),配套 WIN_BUILD_SPEC.md(操作清单)。
2026-11-19 11:55:17 +08:00

115 lines
6.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 发布在线更新:签名构建(双架构)+ 上传产物 + 生成 latest.json
#
# 用法:
# ./scripts/publish-update.sh # 用 package.json 的版本
# ./scripts/publish-update.sh 3.25.3 # 先改版本再发布(等价于 set-version + 本脚本)
#
# 依赖:
# · 签名私钥:~/.config/iwb-updater.key(TAURI_SIGNING_PRIVATE_KEY)
# · 公钥已写进 src-tauri/tauri.conf.json → plugins.updater.pubkey
# · NAS 可 ssh(~/.ssh/id_ed25519_fnos)
#
# 产物:
# <target>/bundle/macos/image-workbench.app.tar.gz(.sig) ← 更新器用
# <target>/bundle/dmg/*.dmg ← 官网下载用
# https://download.maqiart.eu.org/updates/latest.json ← 更新源
set -euo pipefail
cd "$(dirname "$0")/.."
[ $# -ge 1 ] && node scripts/set-version.js "$1"
V=$(node -e "console.log(require('./package.json').version)")
KEY="${TAURI_SIGNING_PRIVATE_KEY:-$HOME/.config/iwb-updater.key}"
export TAURI_SIGNING_PRIVATE_KEY="$KEY"
export TAURI_SIGNING_PRIVATE_KEY_PASSWORD="${TAURI_SIGNING_PRIVATE_KEY_PASSWORD:-}"
export CARGO_HOME="${CARGO_HOME:-$PWD/.cargo-home}"
NAS_HOST="${NAS_HOST:-malongan@192.168.100.185}"
NAS_DIR="${NAS_DIR:-/vol8/web/iwb-download}"
SSH_KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519_fnos}"
SCP="scp -i $SSH_KEY -o BatchMode=yes"
# macOS 26(26.6.2 实测)上 tauri 自带的 create-dmg / bundle_dmg.sh 会在
# "Searching for mounted interstitial disk image" 处报 `grep: bad regex` 并中止,
# 整条发布链因此断在 dmg 上(而 .app 与签名产物其实已经生成)。
# 所以:只让 tauri 打 app(含 .app.tar.gz + .sig),dmg 用 hdiutil 自己封。
make_dmg() { # $1=app 路径 $2=输出 dmg
local app="$1" out="$2" stage
stage=$(mktemp -d)
cp -R "$app" "$stage/"
ln -s /Applications "$stage/Applications"
rm -f "$out"
hdiutil create -volname "image-workbench" -srcfolder "$stage" -ov -format UDZO -quiet "$out"
rm -rf "$stage"
}
echo "== 1/4 构建 arm64(app + 签名产物)"
npx tauri build --bundles app >/dev/null
echo "== 2/4 构建 x86_64(app + 签名产物)"
npx tauri build --target x86_64-apple-darwin --bundles app >/dev/null
ARM="src-tauri/target/release/bundle"
INT="src-tauri/target/x86_64-apple-darwin/release/bundle"
mkdir -p "$ARM/dmg" "$INT/dmg"
echo "== 封装 dmg"
make_dmg "$ARM/macos/image-workbench.app" "$ARM/dmg/image-workbench_${V}_aarch64.dmg"
make_dmg "$INT/macos/image-workbench.app" "$INT/dmg/image-workbench_${V}_x64.dmg"
echo "== 3/4 上传产物"
TMP=$(mktemp -d)
cp "$ARM/macos/image-workbench.app.tar.gz" "$TMP/image-workbench_${V}_aarch64.app.tar.gz"
cp "$ARM/macos/image-workbench.app.tar.gz.sig" "$TMP/image-workbench_${V}_aarch64.app.tar.gz.sig"
cp "$INT/macos/image-workbench.app.tar.gz" "$TMP/image-workbench_${V}_x64.app.tar.gz"
cp "$INT/macos/image-workbench.app.tar.gz.sig" "$TMP/image-workbench_${V}_x64.app.tar.gz.sig"
$SCP "$TMP"/*.app.tar.gz* "$NAS_HOST:$NAS_DIR/updates/darwin-aarch64/" 2>/dev/null || true
$SCP "$TMP/image-workbench_${V}_aarch64.app.tar.gz" "$TMP/image-workbench_${V}_aarch64.app.tar.gz.sig" "$NAS_HOST:$NAS_DIR/updates/darwin-aarch64/"
$SCP "$TMP/image-workbench_${V}_x64.app.tar.gz" "$TMP/image-workbench_${V}_x64.app.tar.gz.sig" "$NAS_HOST:$NAS_DIR/updates/darwin-x86_64/"
$SCP "$ARM/dmg/image-workbench_${V}_aarch64.dmg" "$NAS_HOST:$NAS_DIR/updates/darwin-aarch64/"
$SCP "$INT/dmg/image-workbench_${V}_x64.dmg" "$NAS_HOST:$NAS_DIR/updates/darwin-x86_64/"
echo "== 4/4 生成 latest.json"
export SIG_ARM="$(cat "$ARM/macos/image-workbench.app.tar.gz.sig")"
export SIG_INT="$(cat "$INT/macos/image-workbench.app.tar.gz.sig")"
export UPD_VERSION="$V"
# Windows 包由 win 端构建、mac 端 publish-windows-update.sh 签名发布,写独立的 latest-windows.json。
# 但应用 endpoints 只配了 latest.json(mac/win 共用同一份 tauri.conf.json,无法按平台分 endpoint),
# 所以 mac 发布【必须】把 windows 条目合并进 latest.json,否则 win 用户「检查更新」找不到自己平台、
# 会卡在「正在检查…」(v3.25.31 实测踩过:旧逻辑硬编码只写 darwin,每次 mac 发版都抹掉 windows 条目)。
# 合并条件:latest-windows.json 的 version == 本次 mac version(三平台同批)。
# 若 win 还没跟上本次版本,【不合并】——避免「顶层 version 新、win 包旧」让 updater 反复提示同一旧包;
# 等 win 同批发布后重跑本脚本即自动齐平。
curl -s -m 20 https://download.maqiart.eu.org/updates/latest.json -o /tmp/iwb-latest-prev.json 2>/dev/null || echo '{}' > /tmp/iwb-latest-prev.json
curl -s -m 20 https://download.maqiart.eu.org/updates/latest-windows.json -o /tmp/iwb-latest-win.json 2>/dev/null || echo '{}' > /tmp/iwb-latest-win.json
node -e '
const fs = require("fs")
const v = process.env.UPD_VERSION
let win = {}
try { win = JSON.parse(fs.readFileSync("/tmp/iwb-latest-win.json", "utf8")) } catch (e) { win = {} }
const j = {
version: v,
notes: process.env.UPD_NOTES || "",
pub_date: new Date().toISOString(),
platforms: {
"darwin-aarch64": { signature: process.env.SIG_ARM, url: "https://download.maqiart.eu.org/updates/darwin-aarch64/image-workbench_" + v + "_aarch64.app.tar.gz" },
"darwin-x86_64": { signature: process.env.SIG_INT, url: "https://download.maqiart.eu.org/updates/darwin-x86_64/image-workbench_" + v + "_x64.app.tar.gz" },
},
}
if (win.platforms && win.platforms["windows-x86_64"]) {
if (win.version === v) {
j.platforms["windows-x86_64"] = win.platforms["windows-x86_64"]
console.log("已合并 windows-x86_64 条目(v" + v + ",三平台齐平)")
} else {
console.log("⚠ latest-windows.json 仍是 v" + win.version + ",本次 mac 发 v" + v + ":latest.json 暂不含 windows 条目。win 用户停留旧版,待 win 同批发布后【重跑本脚本】即自动齐平(切勿手工塞旧 win 包,会触发 updater 版本错配死循环)。")
}
}
fs.writeFileSync("/tmp/iwb-latest.json", JSON.stringify(j, null, 2))
console.log("latest.json -> v" + v + " platforms: " + Object.keys(j.platforms).join(","))
'
$SCP /tmp/iwb-latest.json "$NAS_HOST:$NAS_DIR/updates/latest.json"
ssh -i "$SSH_KEY" -o BatchMode=yes "$NAS_HOST" "chmod -R a+rX $NAS_DIR"
echo "== 完成:https://download.maqiart.eu.org/updates/latest.json"
curl -s -m 15 https://download.maqiart.eu.org/updates/latest.json | head -c 200; echo