chore(gc): GitHub 公開 mirror 管線(publish-github.sh+排除清單)——D22 模型落地:Gitea 私有真相源/GitHub 過濾樹乾淨歷史

This commit is contained in:
uncle6me-web
2026-07-18 20:21:15 +08:00
parent e1071edfe8
commit ca57fd6a1a
3 changed files with 93 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
# GitHub 公開 mirror 排除清單(publish-github.sh 用)
# 一行一個路徑(相對 repo 根),# 開頭為註解。改這份檔就能調整公開範圍。
# 內部 LLM wiki / SDD / 事故紀錄 / 交接文件(含 CF account id、內部部署細節)
system-dev
docs
# 內部 AI 開發規範與 hooks
.claude
CLAUDE.md
AGENTS.md
skills
landing/CLAUDE.md
landing/AGENTS.md
# 內部待辦與資料檔
BACKLOG.md
agentdb.rvf
agentdb.rvf.lock
# 本 publish 管線自身(公開端不需要)
scripts/publish-github.sh
scripts/github-publish-exclude.txt
+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# publish-github.sh — 產生過濾後的公開樹,維護 GitHub public mirror(乾淨歷史)
#
# 模型(D22 拍板):Gitea = 私有真相源(全量,含內部 wiki/SDD)
# GitHub = 公開櫥窗(過濾樹 + 每次發版一個 release commit,不帶內部歷史)
# 流量紅線(D20):push 前需 leo 親跑 github-arm.sh 解保險;低頻手動、單 repo、不掛 Actions。
#
# 用法:
# scripts/publish-github.sh # 只建/更新本機 mirror.github-public/),不 push
# scripts/publish-github.sh --push # 另加 push(需 env GITHUB_REMOTE=https://github.com/<帳號>/<repo>.git
#
# 排除清單:scripts/github-publish-exclude.txt(一行一個路徑,相對 repo 根;# 開頭為註解)
set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel)"
EXCLUDE_FILE="$REPO_ROOT/scripts/github-publish-exclude.txt"
MIRROR_DIR="${MIRROR_DIR:-$REPO_ROOT/.github-public}"
GITHUB_REMOTE="${GITHUB_REMOTE:-}"
TMP_EXPORT="$(mktemp -d)"
trap 'rm -rf "$TMP_EXPORT"' EXIT
# 1) 只匯出 HEAD 的 tracked 檔(.env / credentials 等 untracked 永不混入)
git -C "$REPO_ROOT" archive HEAD | tar -x -C "$TMP_EXPORT"
# 2) LFS 檔用實體內容取代 pointer(公開端不吃 LFS
if command -v git-lfs >/dev/null 2>&1; then
git -C "$REPO_ROOT" lfs ls-files --name-only 2>/dev/null | while IFS= read -r f; do
if [ -n "$f" ] && [ -f "$REPO_ROOT/$f" ]; then
mkdir -p "$TMP_EXPORT/$(dirname "$f")"
cp "$REPO_ROOT/$f" "$TMP_EXPORT/$f"
fi
done
fi
# 3) 套排除清單
while IFS= read -r p; do
case "$p" in ''|\#*) continue ;; esac
rm -rf "${TMP_EXPORT:?}/$p"
done < "$EXCLUDE_FILE"
# 4) 同步進常駐 mirrormirror 自己的 .git = 公開端乾淨歷史)
mkdir -p "$MIRROR_DIR"
[ -d "$MIRROR_DIR/.git" ] || git -C "$MIRROR_DIR" init -q -b main
rsync -a --delete --exclude='.git' "$TMP_EXPORT/" "$MIRROR_DIR/"
cd "$MIRROR_DIR"
git add -A
if git diff --cached --quiet && git rev-parse -q --verify HEAD >/dev/null; then
echo "️ 無變更,mirror 已是最新"
else
git -c user.name="Arcrun Release" -c user.email="release@arcrun.dev" \
commit -q -m "release: snapshot $(git -C "$REPO_ROOT" rev-parse --short HEAD) ($(git -C "$REPO_ROOT" log -1 --format=%cd --date=short))"
echo "✅ mirror 已更新:$(git log --oneline -1)"
fi
echo "📁 mirror${MIRROR_DIR}$(git rev-list --count HEAD) 個公開 commit"
if [ "${1:-}" = "--push" ]; then
if [ -z "$GITHUB_REMOTE" ]; then
echo "❌ 缺 GITHUB_REMOTE(例:https://github.com/<帳號>/<repo>.git" >&2
exit 1
fi
git remote remove github 2>/dev/null || true
git remote add github "$GITHUB_REMOTE"
git push -u github main
echo "🚀 已 push → $GITHUB_REMOTE"
fi