ThinkAdmin/.github/split-linux.sh
Anyon f2de95223a ci(release): 完善双分支自动拆分与发布流程
为 ThinkAdmin 主仓库补强 v6-dev 与 v8-dev 的自动化处理机制,避免两个开发分支在插件仓库分支、发布 Tag 与 Release Notes 生成时互相覆盖。

主要内容:

- 拆分工作流仅允许 v6-dev 与 v8-dev,按同名分支推送各插件仓库。

- 发布工作流按 v6.* / v8.* Tag 自动选择对应开发分支,并要求 Tag 指向对应分支最新提交。

- 发布脚本同步推送插件分支和同名 Tag,遇到冲突 Tag 会拒绝覆盖。

- 新增中文 Release Notes 生成器,按提交前缀自动汇总本次变更内容。

- 静态分析步骤兼容 v6-dev 未定义 analyse 脚本的情况,避免旧分支发布失败。
2026-05-08 15:56:55 +08:00

52 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
CURRENT_BRANCH="${SPLIT_BRANCH:-${GITHUB_REF_NAME:-$(git rev-parse --abbrev-ref HEAD)}}"
BASEPATH="$(cd "$(dirname "$0")"; cd ../plugin/; pwd)"
REPOS=("$@")
case "$CURRENT_BRANCH" in
v6-dev|v8-dev) ;;
*)
echo "Only v6-dev and v8-dev are allowed to split, current: ${CURRENT_BRANCH}" >&2
exit 1
;;
esac
remote() {
local name="$1"
local url="$2"
if git remote get-url "$name" >/dev/null 2>&1; then
git remote set-url "$name" "$url"
else
git remote add "$name" "$url"
fi
}
split_branch() {
local repo="$1"
local prefix="plugin/${repo}"
local sha1
sha1="$(.github/splitsh-lite-linux --prefix="$prefix")"
echo "Split ${prefix} => ${sha1}, push branch ${CURRENT_BRANCH}"
git push "$repo" "${sha1}:refs/heads/${CURRENT_BRANCH}" -f
}
if [[ ${#REPOS[@]} -eq 0 ]]; then
while IFS= read -r repo; do
REPOS+=("$repo")
done < <(find "$BASEPATH" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort)
fi
if [[ -n "${GITHUB_ACTIONS:-}" ]]; then
git fetch origin "$CURRENT_BRANCH" || true
else
git pull --ff-only origin "$CURRENT_BRANCH"
fi
for repo in "${REPOS[@]}"; do
remote "$repo" "git@github.com:zoujingli/${repo}.git"
split_branch "$repo"
done