Compare commits

...
2 Commits
Author SHA1 Message Date
kory 16ece31d57 ci(release): generate formatted markdown changelog and release notes for each release
Release / Build & Release (push) Canceled after 0s
2026-09-28 10:30:27 +08:00
kory 8d8b201498 ci(release): automatically extract and render commit changelog into release notes 2026-09-28 10:29:17 +08:00
+29 -11
View File
@@ -20,26 +20,25 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Determine Version Tag - name: Determine Version Tag & Generate Notes
id: versioning id: versioning
run: | run: |
PREV_TAG=$(git tag -l "v*" --sort=-v:refname | head -n1)
echo "Previous tag: $PREV_TAG"
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
TAG="${GITHUB_REF#refs/tags/}" TAG="${GITHUB_REF#refs/tags/}"
else else
# 获取最新语义化版本 tag (例如 v1.1.0) if [ -z "$PREV_TAG" ]; then
LATEST_TAG=$(git tag -l "v*" --sort=-v:refname | head -n1) TAG="v1.0.0"
if [ -z "$LATEST_TAG" ]; then else
LATEST_TAG="v1.0.0" VER_NUM="${PREV_TAG#v}"
fi
# 去除前缀 v
VER_NUM="${LATEST_TAG#v}"
# 拆解 MAJOR.MINOR.PATCH
IFS='.' read -r MAJOR MINOR PATCH <<< "$VER_NUM" IFS='.' read -r MAJOR MINOR PATCH <<< "$VER_NUM"
PATCH=$((PATCH + 1)) PATCH=$((PATCH + 1))
TAG="v${MAJOR}.${MINOR}.${PATCH}" TAG="v${MAJOR}.${MINOR}.${PATCH}"
fi
echo "Auto incremented patch version to $TAG" echo "Auto incremented patch version to $TAG"
# 打上本地 tag 并推送到远程
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com" git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$TAG" git tag "$TAG"
@@ -47,6 +46,25 @@ jobs:
fi fi
echo "tag=$TAG" >> $GITHUB_OUTPUT echo "tag=$TAG" >> $GITHUB_OUTPUT
# 生成详细的 Release Changelog 正文
cat << NOTES > release_notes.md
### 🚀 What's Changed in ${TAG}
NOTES
if [ -n "$PREV_TAG" ]; then
git log "${PREV_TAG}..HEAD" --pretty=format:"- %s (%h by @%an)" >> release_notes.md
else
git log -n 10 --pretty=format:"- %s (%h by @%an)" >> release_notes.md
fi
echo "" >> release_notes.md
echo "" >> release_notes.md
if [ -n "$PREV_TAG" ]; then
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${TAG}" >> release_notes.md
fi
cat release_notes.md
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
@@ -73,6 +91,6 @@ jobs:
with: with:
tag_name: ${{ steps.versioning.outputs.tag }} tag_name: ${{ steps.versioning.outputs.tag }}
name: Release ${{ steps.versioning.outputs.tag }} name: Release ${{ steps.versioning.outputs.tag }}
body_path: release_notes.md
files: | files: |
dist/* dist/*
generate_release_notes: true