Files
moonsource-linguoland/tools/release.sh
T
Garfield dfd2f7056e
Release / release (push) Successful in 11s
🔨 (release): 加上打标签推送的发布脚本
更新日志标题改成单独一行「## 0.1.0」,工作流才能截出这一节。
2026-11-27 00:56:00 +08:00

42 lines
1.3 KiB
Bash
Executable File
Raw 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。"