ci(release): automatically extract and render commit changelog into release notes
This commit is contained in:
@@ -20,26 +20,27 @@ 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)
|
||||||
|
if [ -z "$PREV_TAG" ]; then
|
||||||
|
PREV_TAG=""
|
||||||
|
fi
|
||||||
|
|
||||||
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}"
|
||||||
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$VER_NUM"
|
||||||
|
PATCH=$((PATCH + 1))
|
||||||
|
TAG="v${MAJOR}.${MINOR}.${PATCH}"
|
||||||
fi
|
fi
|
||||||
# 去除前缀 v
|
|
||||||
VER_NUM="${LATEST_TAG#v}"
|
|
||||||
# 拆解 MAJOR.MINOR.PATCH
|
|
||||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$VER_NUM"
|
|
||||||
PATCH=$((PATCH + 1))
|
|
||||||
TAG="v${MAJOR}.${MINOR}.${PATCH}"
|
|
||||||
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 +48,19 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# 生成有意义的变更日志内容
|
||||||
|
echo "### 🚀 What's Changed in ${TAG}" > release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
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
|
||||||
|
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${TAG}" >> release_notes.md
|
||||||
|
cat release_notes.md
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
@@ -68,11 +82,11 @@ jobs:
|
|||||||
sha256sum * > checksums.txt
|
sha256sum * > checksums.txt
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user