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.
This commit is contained in:
手瓜一十雪 2025-11-13 19:06:06 +08:00
parent fec024334a
commit 31a7767ae4

View File

@ -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"