Files
image-workbench-desktop/scripts/release.sh
T
qiqi 43de3b0054
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 49s
chore(guard): 发布脚本与 pre-push 都接插件两仓一致性检查
- scripts/release.sh、scripts/publish-update.sh:开头加前置门禁(不一致直接退出,不发包不传 NAS),
  末尾加收尾复核(发布过程中若有人手改产物层,这里立刻暴露)
- scripts/git-hooks/pre-push + scripts/install-git-hooks.sh + npm run hooks:install:
  推送桌面仓前自动比对两仓,不一致拒绝推送;源仓不存在时跳过(CI/别人机器不阻塞)
- docs/standards/plugin-source-of-truth.md §4 补「四道关卡」表与钩子安装方法
2026-11-29 12:35:33 +08:00

84 lines
4.7 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
# 桌面版一键发布:构建 dmg → 算 hash → 更新 releases.json → 生成页面 → 上传 NAS → 校验
set -euo pipefail
cd "$(dirname "$0")/.."
# 插件两仓一致性(v3.26.109):桌面仓 plugins/ 必须等于插件源仓,否则发布的包/市场会和源码分叉。
# 源仓不存在时脚本自身会跳过(CI / 别人机器不阻塞)。见 docs/standards/plugin-source-of-truth.md。
node scripts/check-plugins-sync.js || { echo '✗ 插件两仓不一致,已停止发布(先同步插件源仓)'; exit 1; }
NAS_HOST="${NAS_HOST:-192.168.100.185}"
NAS_USER="${NAS_USER:-malongan}"
NAS_DIR="${NAS_DIR:-/vol8/web/iwb-download}"
SSH_KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519_fnos}"
PLATFORM="${PLATFORM:-darwin-aarch64}"
SKIP_BUILD=0
NOTES=""
while [ $# -gt 0 ]; do
case "$1" in
--skip-build) SKIP_BUILD=1; shift ;;
--notes) NOTES="$2"; shift 2 ;;
*) echo "未知参数:$1"; exit 1 ;;
esac
done
VERSION=$(node -e "console.log(require('./src-tauri/tauri.conf.json').version)")
echo "版本:$VERSION"
if [ "$SKIP_BUILD" -eq 0 ]; then
echo "→ 构建 dmg…"
# tauri 的 bundle_dmg.sh 在新版 macOS 上会因设备名解析 bug 失败
# (grep: bad regex '/dev/disk1Xs': brackets ([ ]) not balanced,详见 scripts/make-dmg.sh 头注释)。
# 那一刻 app 本体已经构建成功,只是封装失败 —— 降级到 hdiutil 兜底,不重跑几分钟的 release 编译。
if ! npx tauri build --bundles dmg; then
echo "⚠ tauri 封装 dmg 失败,改用 hdiutil 兜底(app 已构建成功)"
bash scripts/make-dmg.sh
fi
fi
DMG=$(ls -t src-tauri/target/release/bundle/dmg/*.dmg 2>/dev/null | head -1 || true)
if [ -z "$DMG" ]; then echo "找不到 dmg,先跑一次完整构建"; exit 1; fi
echo "产物:$DMG"
SIZE=$(stat -f%z "$DMG")
SHA=$(shasum -a 256 "$DMG" | awk '{print $1}')
BASE=$(basename "$DMG")
REMOTE_REL="updates/$PLATFORM/$BASE"
# 注意:必须用数组传参。旧写法 `EXTRA="--notes $NOTES"` 在 `$EXTRA` 展开时按空格拆词,
# 带空格的说明会被腰斩(v3.25.23 真实发生:线上 notes 只剩「…(插件」)。
NOTES_ARG=()
if [ -n "$NOTES" ]; then NOTES_ARG=(--notes "$NOTES"); fi
node scripts/update-releases.js --version "$VERSION" --platform "$PLATFORM" \
--file "$REMOTE_REL" --size "$SIZE" --sha256 "$SHA" ${NOTES_ARG[@]+"${NOTES_ARG[@]}"}
node scripts/gen-release-page.js
# 首页 / 插件页也带版本号与插件数(gen-site.js 渲染)——不重跑就会出现
# 「包已经是新版、首页还写着下载 v3.25.22」(v3.25.23 真实发生)。
node scripts/gen-site.js
echo "→ 上传到 ${NAS_USER}@${NAS_HOST}:$NAS_DIR"
ssh -i "$SSH_KEY" -o BatchMode=yes "${NAS_USER}@${NAS_HOST}" "mkdir -p $NAS_DIR/updates/$PLATFORM $NAS_DIR/download $NAS_DIR/plugins"
scp -i "$SSH_KEY" -o BatchMode=yes "$DMG" "${NAS_USER}@${NAS_HOST}:$NAS_DIR/updates/$PLATFORM/" >/dev/null
# 下载页要落在 $NAS_DIR/download/,**不能**和首页一起 scp —— 两个文件都叫 index.html,
# 同目录展开时后者覆盖前者(v3.25.23 真实发生:首页被下载页顶掉)。
scp -i "$SSH_KEY" -o BatchMode=yes site/releases.json site/index.html site/plugins-index.json "${NAS_USER}@${NAS_HOST}:$NAS_DIR/" >/dev/null
scp -i "$SSH_KEY" -o BatchMode=yes site/download/index.html "${NAS_USER}@${NAS_HOST}:$NAS_DIR/download/" >/dev/null
scp -i "$SSH_KEY" -o BatchMode=yes site/plugins/index.html "${NAS_USER}@${NAS_HOST}:$NAS_DIR/plugins/" >/dev/null
ssh -i "$SSH_KEY" -o BatchMode=yes "${NAS_USER}@${NAS_HOST}" "chmod -R a+rX $NAS_DIR"
echo "→ 校验公网"
# 包是 8~9 MB,走隧道回读要几十秒:超时给短了 curl 直接非零退出,
# set -e 下会「无声退出」,看起来像发布成功(v3.25.23 真实发生)。
# 必须带 ?h=<sha12> 回读:CF 对同名 dmg 有 4 小时强缓存,不带指纹会验到旧字节。
SHA12=$(printf '%s' "$SHA" | cut -c1-12)
PKG_URL="https://download.maqiart.eu.org/$REMOTE_REL?h=$SHA12"
CODE=$(curl -s -o /dev/null -m 120 -w '%{http_code}' "$PKG_URL") || CODE=000
SIZE2=$(curl -s -o /dev/null -m 120 -w '%{size_download}' "$PKG_URL") || SIZE2=0
PAGE_CODE=$(curl -s -o /dev/null -m 20 -w '%{http_code}' https://download.maqiart.eu.org/) || PAGE_CODE=000
echo " 页面 $PAGE_CODE 包 $CODE 远端 $SIZE2 B / 本地 $SIZE B"
if [ "$CODE" != "200" ] || [ "$SIZE2" != "$SIZE" ]; then echo "✗ 校验失败"; exit 1; fi
echo "✓ 发布完成:https://download.maqiart.eu.org/"
# 收尾再核一次:发布过程中若有人手改了产物层,这里会立刻暴露。
node scripts/check-plugins-sync.js || { echo '⚠ 收尾校验失败:插件两仓已不一致,请按 docs/standards/plugin-source-of-truth.md 回写源仓'; exit 1; }