From 65cb5ad41fc3e989f573f75034625b489b5d7dbf Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sat, 6 Sep 2025 18:29:52 +0800 Subject: [PATCH] =?UTF-8?q?ci(release):=20=E4=BC=98=E5=8C=96=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E5=B7=A5=E4=BD=9C=E6=B5=81=E4=B8=AD=E7=9A=84=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E8=8E=B7=E5=8F=96=E5=92=8C=E5=8F=98=E6=9B=B4=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改进标签获取逻辑以处理首次发布的情况 使用更可靠的方式获取当前标签并生成变更日志 --- .github/workflows/release.yml | 36 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 594bc10..27045bc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,6 @@ name: Release on: - workflow_dispatch: release: types: [published] @@ -12,26 +11,39 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Get previous tag - id: prev_tag - run: | - PREV_TAG=$(git describe --tags --abbrev=0 $(git rev-list --tags --skip=1 --max-count=1)) - echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV - - - name: Get commits between tags - id: changelog + - name: Get all tags and check current/previous + id: get_tags run: | git fetch --tags - COMMITS=$(git log $PREV_TAG..${{ github.event.release.tag_name }} --pretty=format:"- %s (%an)") + 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<> $GITHUB_ENV cat commits.txt >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - - name: Update Release Notes + - name: Update GitHub Release notes uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.event.release.tag_name }} + tag_name: ${{ env.CURRENT_TAG }} body: | ${{ env.COMMITS }} env: