From 31a7767ae403f07a8e307978bd70d0b4345137d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Thu, 13 Nov 2025 19:06:06 +0800 Subject: [PATCH] Improve previous tag detection in auto-release workflow Replaces 'git describe' with logic to find the previous tag by sorting all tags by creation date. This ensures accurate detection of the previous tag for release note generation and adds error handling if no previous tag is found. --- .github/workflows/auto-release.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 369c96fc..f078692b 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -94,8 +94,24 @@ jobs: # 当前 tag CURRENT_TAG="${GITHUB_REF#refs/tags/}" - # 上一个 tag - PREV_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG^") + # 获取所有 tag 按创建时间倒序排列 + TAGS=( $(git tag --sort=-creatordate) ) + + # 找到上一个 tag + PREV_TAG="" + for i in "${!TAGS[@]}"; do + if [ "${TAGS[$i]}" = "$CURRENT_TAG" ]; then + if [ $((i+1)) -lt ${#TAGS[@]} ]; then + PREV_TAG="${TAGS[$((i+1))]}" + fi + break + fi + done + + if [ -z "$PREV_TAG" ]; then + echo "❌ Could not find previous tag for $CURRENT_TAG, aborting." + exit 1 + fi echo "Generating release note from $PREV_TAG to $CURRENT_TAG"