From 43de3b005464c42704e8a0c9b083ae16af3ac7fe Mon Sep 17 00:00:00 2001 From: qiqi Date: Sun, 29 Nov 2026 12:35:33 +0800 Subject: [PATCH] =?UTF-8?q?chore(guard):=20=E5=8F=91=E5=B8=83=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E4=B8=8E=20pre-push=20=E9=83=BD=E6=8E=A5=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=B8=A4=E4=BB=93=E4=B8=80=E8=87=B4=E6=80=A7=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 补「四道关卡」表与钩子安装方法 --- docs/standards/plugin-source-of-truth.md | 15 +++++++++++++++ package.json | 1 + scripts/git-hooks/pre-push | 12 ++++++++++++ scripts/install-git-hooks.sh | 12 ++++++++++++ scripts/publish-update.sh | 7 +++++++ scripts/release.sh | 9 ++++++++- 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 scripts/git-hooks/pre-push create mode 100755 scripts/install-git-hooks.sh diff --git a/docs/standards/plugin-source-of-truth.md b/docs/standards/plugin-source-of-truth.md index 5c842e1..32b56ef 100644 --- a/docs/standards/plugin-source-of-truth.md +++ b/docs/standards/plugin-source-of-truth.md @@ -52,6 +52,21 @@ node scripts/gen-market.js && node scripts/gen-market-page.js ## 4. 门禁与命令 +三道关卡,从「本地提交」到「发布」都拦: + +| 关卡 | 位置 | 触发 | 行为 | +| --- | --- | --- | --- | +| pre-push 钩子 | `.git/hooks/pre-push`(源文件在 `scripts/git-hooks/pre-push`) | `git push` 桌面仓 | 两仓不一致直接拒绝推送 | +| 发布前置 | `scripts/release.sh` / `scripts/publish-update.sh` 开头 | 发版 | 不一致即退出,不发包、不传 NAS | +| 发布收尾 | 同上脚本末尾 | 发版结束 | 再核一次,防止发布过程中有人手改产物 | +| 市场前置 | `scripts/gen-market.js` 开头 | 发插件市场 | 不一致即中止 | + +钩子安装(每台机器一次,clone 后执行):`npm run hooks:install`(等价 `bash scripts/install-git-hooks.sh`)。 +钩子里的检查在「源仓不存在」时会跳过,所以别人机器/CI 不会被卡。 + +--- + + | 命令 | 作用 | 谁在用 | | --- | --- | --- | | `npm run validate`(源仓) | 源仓内部一致性:id/apiVersion/version 与 package.json 对齐 | 改插件的必跑 | diff --git a/package.json b/package.json index c55f2de..257caf0 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js", "plugins:gc": "node scripts/plugins-publish.mjs --gc", "check:plugins": "node scripts/check-plugins-sync.js", + "hooks:install": "bash scripts/install-git-hooks.sh", "coverage:browser": "npm run build && node scripts/coverage-browser.js", "audit:pins": "node scripts/audit-source-pins.js", "tokens:write": "node scripts/gen-tokens.js --write", diff --git a/scripts/git-hooks/pre-push b/scripts/git-hooks/pre-push new file mode 100755 index 0000000..23b3c89 --- /dev/null +++ b/scripts/git-hooks/pre-push @@ -0,0 +1,12 @@ +#!/bin/sh +# pre-push:推送前校验桌面仓 plugins/ 与插件源仓一致(v3.26.109) +# 由 scripts/install-git-hooks.sh 安装;源仓不存在时 check 脚本会自行跳过。 +root=$(git rev-parse --show-toplevel) +if ! node "$root/scripts/check-plugins-sync.js"; then + echo '' + echo '[pre-push] 插件两仓不一致,已阻止推送。' + echo '[pre-push] 正确做法:在 iwb-plugins-desktop 改源码 → 桌面仓 node scripts/sync-plugins-from-repo.js' + echo '[pre-push] 说明:docs/standards/plugin-source-of-truth.md' + exit 1 +fi +exit 0 diff --git a/scripts/install-git-hooks.sh b/scripts/install-git-hooks.sh new file mode 100755 index 0000000..4b196ea --- /dev/null +++ b/scripts/install-git-hooks.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# 安装仓库自带的 git hooks(目前只有 pre-push:插件两仓一致性) +set -e +root=$(cd "$(dirname "$0")/.." && pwd) +hooks="$root/.git/hooks" +[ -d "$hooks" ] || { echo "找不到 $hooks"; exit 1; } +for f in "$root"/scripts/git-hooks/*; do + name=$(basename "$f") + cp "$f" "$hooks/$name" + chmod +x "$hooks/$name" + echo "installed .git/hooks/$name" +done diff --git a/scripts/publish-update.sh b/scripts/publish-update.sh index a1a938f..461de39 100755 --- a/scripts/publish-update.sh +++ b/scripts/publish-update.sh @@ -17,6 +17,10 @@ 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; } + [ $# -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}" @@ -133,3 +137,6 @@ fi 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 + +# 收尾再核一次:发布过程中若有人手改了产物层,这里会立刻暴露。 +node scripts/check-plugins-sync.js || { echo '⚠ 收尾校验失败:插件两仓已不一致,请按 docs/standards/plugin-source-of-truth.md 回写源仓'; exit 1; } diff --git a/scripts/release.sh b/scripts/release.sh index 47c4f6b..edab756 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -3,6 +3,10 @@ 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}" @@ -73,4 +77,7 @@ 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/" \ No newline at end of file +echo "✓ 发布完成:https://download.maqiart.eu.org/" + +# 收尾再核一次:发布过程中若有人手改了产物层,这里会立刻暴露。 +node scripts/check-plugins-sync.js || { echo '⚠ 收尾校验失败:插件两仓已不一致,请按 docs/standards/plugin-source-of-truth.md 回写源仓'; exit 1; }