Files
ISEP/hooks/release-tag-guard.sh
Leo e4e3d69acf fix(release): 版本只有 Gitea Releases 答得出來,不再靠 README 自報(inkstone/ISEP#6)
現況:README.md 宣稱「狀態 0.1.0」,但 repo release_counter=0、一個 tag
都沒打。leo 當場指出這是違規,命中規範自己的 E12(宣稱交付但沒有 tag);
leo 補充:「release 不是寫在 readme,要放在 release 裡」。

改法(結構性防漂移,不是靠人記得同步):
- README.md 不再自行宣告版本號,改成指向 Gitea Releases 頁面
- .claude-plugin/plugin.json 的 version 改回哨兵值 0.0.0
  (=誠實承認目前沒有一個經過驗證、掛在 Releases 上的版本;
  真正打 tag 那天才跟 tag 一起同步成那個號碼)
- 新增 scripts/check-version-consistency.sh:隨時可跑的一致性檢查
  (plugin.json version 是否等於最新 tag/README 是否偷偷自報版本)
- 新增 hooks/release-tag-guard.sh:PreToolUse Bash 閘,在真正打 git tag
  的那一刻擋下與 plugin.json 不一致的版本號,註冊進 hooks.json

紅線:本次不打 tag、不建 release——那是總管驗過整個 milestone 之後的動作,
這裡交的是機制與草稿。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-20 13:10:00 +08:00

82 lines
4.0 KiB
Bash
Executable File
Raw Permalink 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.
#!/bin/sh
# release-tag-guard.sh — PreToolUseBash):打 tag 那一刻擋下版本不一致
#
# 立這道閘的來由(inkstone/ISEP#62026-08-20):
# README.md 曾寫死「狀態:0.1.0」,但這個 repo `release_counter=0`、
# 一個 tag 都沒打。leo 當場指出這是違規,且命中規範自己的 E12
# (宣稱交付但沒有 tag);leo 補充:「release 不是寫在 readme,要放在 release 裡」。
#
# 這支閘解的不是「README 寫錯字」,是**結構性防漂移**:
# 「ISEP 現在是哪一版」只有一個地方答得出來= Gitea Releasesgit tag)。
# `.claude-plugin/plugin.json` 的 `version` 欄位必須跟這個 tag 完全一致,
# 不然又回到「版本號在不同地方各說各話」的老路——只是這次換成
# 「manifest 一個號碼、tag 又一個號碼」而不是「README 一個號碼、repo 裡沒 tag」。
# 同一套判準也寫在 `scripts/check-version-consistency.sh`(可以隨時手動跑,
# 不必等到打 tag那一刻);這支 hook 是「結構性做不到」的那一半——
# 在真正動手打 tag 的當下擋住,而不是靠事後補跑腳本才發現。
#
# 🔴 紅線:**這支 hook 不打 tag、不建 release**——它只在別人(人類/總管)要打 tag 時
# 檢查一致性。真正打哪個版本號的 tag,是總管驗過整個 milestone 之後的動作。
#
# 設計紀律(沿用本 repo既有 guard 的兩條,見 main-and-prod-push-guard.sh 註解):
# • **先排除「談論/讀取/刪除/列出」**,只擋「真的要打一個新 tag」的那個命令形狀。
# • **抽不出版本號就不擋**(fail-open on 解析失敗,不是 fail-open on 檢查結果)——
# 避免因為指令格式特殊(例如帶簽名 `-s`、多行訊息)誤攔到人,
# 那正是「閘被誤攔多次會被繞過」的病根(README 段落引的 D95 同一款教訓)。
set -eu
INPUT="$(cat)"
CMD=$(printf '%s' "$INPUT" | python3 -c '
import sys, json
try: print(json.load(sys.stdin).get("tool_input", {}).get("command", "") or "")
except Exception: print("")
' 2>/dev/null || printf '')
[ -z "$CMD" ] && exit 0
# ── 先排除不是「打新 tag」的動作 ──────────────────────────────────────
case "$CMD" in
sed\ *|cat\ *|grep\ *|head\ *|tail\ *|wc\ *|less\ *|ls\ *|awk\ *|rg\ *|echo\ *) exit 0 ;;
*"git tag -d"*|*"git tag --delete"*|*"git tag -l"*|*"git tag --list"*|*"git tag -n"*) exit 0 ;;
*" --dry-run"*|*"--dry-run "*) exit 0 ;;
esac
case "$CMD" in
*"git tag "*) ;;
*) exit 0 ;;
esac
# ── 從命令裡萃取版本號(第一個 vX.Y.Z 或 X.Y.Z 樣式的 token)───────────
TAGNAME=$(printf '%s' "$CMD" | grep -oE 'v?[0-9]+\.[0-9]+\.[0-9]+' | head -1 || printf '')
[ -n "$TAGNAME" ] || exit 0 # 抽不出版本號=不是本閘管的形狀,不擋(見上方設計紀律)
VER=${TAGNAME#v}
PROJ="${CLAUDE_PROJECT_DIR:-$(pwd)}"
PLUGIN_JSON="$PROJ/.claude-plugin/plugin.json"
[ -f "$PLUGIN_JSON" ] || exit 0 # 不在 ISEP repo 裡(沒有這個檔案)=不是本閘管的 repo
PJVER=$(python3 -c "import json;print(json.load(open('$PLUGIN_JSON')).get('version',''))" 2>/dev/null || printf '')
[ -n "$PJVER" ] || exit 0
if [ "$PJVER" != "$VER" ]; then
cat >&2 <<MSG
🚫 版本不一致,擋下這次打 taginkstone/ISEP#6:版本結構性防漂移閘)
你想打的 tag$TAGNAME(版本號 $VER
.claude-plugin/plugin.json 現在的 version$PJVER
兩者必須完全一致——「ISEP 現在是哪一版」只有 Gitea Releases 答得出來,
而 Releases 的 tag 名稱跟 plugin.json 的宣稱要是同一個數字,不然又是各說各話。
【怎麼過】把 .claude-plugin/plugin.json 的 version 改成 $VER
連同這次要發的其他改動一起 commit,再重新打 tag $TAGNAME。
(或者你要打的其實是 $PJVER 這個號碼,那就把 tag 名稱改對。)
驗法一致的獨立腳本:scripts/check-version-consistency.sh
MSG
exit 2
fi
exit 0