Files
LeonOS/.github/workflows/release.yml
Leonmmcoset 65cb5ad41f ci(release): 优化发布工作流中的标签获取和变更日志生成
改进标签获取逻辑以处理首次发布的情况
使用更可靠的方式获取当前标签并生成变更日志
2025-09-06 18:29:52 +08:00

50 lines
1.4 KiB
YAML
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.

name: Release
on:
release:
types: [published]
jobs:
build-release-notes:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get all tags and check current/previous
id: get_tags
run: |
git fetch --tags
TAGS=$(git tag --sort=-creatordate)
COUNT=$(echo "$TAGS" | wc -l)
if [ "$COUNT" -le 1 ]; then
echo "PREV_TAG=" >> $GITHUB_ENV
else
# 第二新第2行为上一个tag
PREV_TAG=$(echo "$TAGS" | sed -n '2p')
echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV
fi
echo "CURRENT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Generate changelog
id: changelog
run: |
if [ -z "$PREV_TAG" ]; then
# 首次release显示全部历史
COMMITS=$(git log --pretty=format:"- %s (%an)")
else
COMMITS=$(git log $PREV_TAG..$CURRENT_TAG --pretty=format:"- %s (%an)")
fi
echo "$COMMITS" > commits.txt
echo "COMMITS<<EOF" >> $GITHUB_ENV
cat commits.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Update GitHub Release notes
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.CURRENT_TAG }}
body: |
${{ env.COMMITS }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}