feat: 更新 action.yml 文件,统一引号格式,增强 Git 标签获取逻辑,确保在 GitHub Actions 中正确处理标签信息

This commit is contained in:
Lyda
2025-08-21 14:58:56 +08:00
parent 1299feac14
commit 77dcc1bed2

View File

@@ -1,42 +1,42 @@
name: 'Trigger Version Info' name: "Trigger Version Info"
description: '获取触发版本信息,支持标签触发、版本分支触发和常规分支触发' description: "获取触发版本信息,支持标签触发、版本分支触发和常规分支触发"
author: 'Your Organization' author: "Your Organization"
inputs: inputs:
version-prefix: version-prefix:
description: '版本前缀用于匹配版本标签或分支默认v' description: "版本前缀用于匹配版本标签或分支默认v"
required: false required: false
default: 'v' default: "v"
use-latest-version: use-latest-version:
description: '在非版本触发时是否使用当前分支最新的版本标签默认false' description: "在非版本触发时是否使用当前分支最新的版本标签默认false"
required: false required: false
default: 'false' default: "false"
outputs: outputs:
ref-type: ref-type:
description: '引用类型 (tag/branch)' description: "引用类型 (tag/branch)"
value: ${{ steps.get-version-info.outputs.ref_type }} value: ${{ steps.get-version-info.outputs.ref_type }}
ref-name: ref-name:
description: '引用名称' description: "引用名称"
value: ${{ steps.get-version-info.outputs.ref_name }} value: ${{ steps.get-version-info.outputs.ref_name }}
is-version-trigger: is-version-trigger:
description: '是否为版本触发true/false' description: "是否为版本触发true/false"
value: ${{ steps.get-version-info.outputs.is_version_trigger }} value: ${{ steps.get-version-info.outputs.is_version_trigger }}
trigger-version: trigger-version:
description: '触发的版本号标准化为v开头的格式' description: "触发的版本号标准化为v开头的格式"
value: ${{ steps.get-version-info.outputs.trigger_version }} value: ${{ steps.get-version-info.outputs.trigger_version }}
trigger-source: trigger-source:
description: '触发源tag/branch' description: "触发源tag/branch"
value: ${{ steps.get-version-info.outputs.trigger_source }} value: ${{ steps.get-version-info.outputs.trigger_source }}
full-ref: full-ref:
description: '完整的 Git 引用' description: "完整的 Git 引用"
value: ${{ steps.get-version-info.outputs.full_ref }} value: ${{ steps.get-version-info.outputs.full_ref }}
version-with-dash: version-with-dash:
description: '版本号点替换为横线例如v1.2.3 -> v1-2-3' description: "版本号点替换为横线例如v1.2.3 -> v1-2-3"
value: ${{ steps.get-version-info.outputs.version_with_dash }} value: ${{ steps.get-version-info.outputs.version_with_dash }}
runs: runs:
using: 'composite' using: "composite"
steps: steps:
- name: 获取触发版本信息 - name: 获取触发版本信息
id: get-version-info id: get-version-info
@@ -89,7 +89,25 @@ runs:
# 检查git仓库是否可用 # 检查git仓库是否可用
if git rev-parse --git-dir > /dev/null 2>&1; then if git rev-parse --git-dir > /dev/null 2>&1; then
LATEST_TAG=$(git tag --list "${VERSION_PREFIX}*" --sort=-version:refname 2>/dev/null | head -1) echo "✅ Git仓库可用开始获取标签..."
# 确保获取所有标签信息GitHub Actions 默认是浅克隆)
echo "📥 获取远程标签信息..."
git fetch --tags --quiet 2>/dev/null || echo "⚠️ 获取远程标签失败,继续使用本地标签"
# 获取所有匹配的标签
echo "🏷️ 查找匹配前缀 '${VERSION_PREFIX}' 的标签..."
ALL_TAGS=$(git tag --list "${VERSION_PREFIX}*" 2>/dev/null)
echo "找到的标签: $ALL_TAGS"
# 获取最新的版本标签
if command -v sort >/dev/null 2>&1; then
# 使用 sort 命令进行版本排序
LATEST_TAG=$(echo "$ALL_TAGS" | sort -V | tail -1)
else
# 如果没有 sort -V使用 git 的排序
LATEST_TAG=$(git tag --list "${VERSION_PREFIX}*" --sort=-version:refname 2>/dev/null | head -1)
fi
if [[ -n "$LATEST_TAG" ]]; then if [[ -n "$LATEST_TAG" ]]; then
# 找到了版本标签,使用它 # 找到了版本标签,使用它
@@ -101,14 +119,14 @@ runs:
IS_VERSION_TRIGGER=true IS_VERSION_TRIGGER=true
else else
# 没有找到版本标签 # 没有找到版本标签
echo "⚠️ 未找到版本标签,使用空版本" echo "⚠️ 未找到匹配前缀 '${VERSION_PREFIX}' 的版本标签,使用空版本"
IS_VERSION_TRIGGER=false IS_VERSION_TRIGGER=false
TRIGGER_VERSION="" TRIGGER_VERSION=""
VERSION_WITH_DASH="" VERSION_WITH_DASH=""
fi fi
else else
# Git仓库不可用 # Git仓库不可用
echo "⚠️ Git仓库不可用使用空版本" echo " Git仓库不可用使用空版本"
IS_VERSION_TRIGGER=false IS_VERSION_TRIGGER=false
TRIGGER_VERSION="" TRIGGER_VERSION=""
VERSION_WITH_DASH="" VERSION_WITH_DASH=""
@@ -139,5 +157,5 @@ runs:
echo "trigger_source=$TRIGGER_SOURCE" >> $GITHUB_OUTPUT echo "trigger_source=$TRIGGER_SOURCE" >> $GITHUB_OUTPUT
branding: branding:
icon: 'git-branch' icon: "git-branch"
color: 'blue' color: "blue"