Files
2026-11-27 08:08:01 +08:00

42 lines
1.3 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
# 发布本书源:校验更新日志 → 本地打包 → 打轻量标签 v<版本> → 推送当前分支和标签。
# Release 由 .github/workflows/release.yml 在标签推上去之后创建,日志取 CHANGELOG.md 里精确的「## <版本>」一节。
# 用法:tools/release.sh <VERSION>
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
VERSION="${1:?用法:tools/release.sh <VERSION>}"
case "$VERSION" in
v*) echo "版本不要带 v:$VERSION" >&2; exit 1 ;;
esac
printf '%s\n' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([.+-].*)?$' \
|| { echo "版本应为 MAJOR.MINOR.PATCH:$VERSION" >&2; exit 1; }
grep -qx "## ${VERSION}" CHANGELOG.md \
|| { echo "CHANGELOG.md 缺少单独一行「## ${VERSION}」" >&2; exit 1; }
if [ -n "$(git status --porcelain)" ]; then
echo "工作区不干净,先提交再发布" >&2
exit 1
fi
tools/package.sh "$VERSION" dist
TAG="v${VERSION}"
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
HAVE="$(git rev-parse "${TAG}^{}")"
HEAD="$(git rev-parse HEAD)"
if [ "$HAVE" != "$HEAD" ]; then
echo "标签 ${TAG} 已经指向别的提交" >&2
exit 1
fi
else
git tag "$TAG"
fi
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
git push origin "$BRANCH"
git push origin "$TAG"
echo "已推送 ${TAG}。Actions 会打包并创建 Release。"