This commit is contained in:
parent
7d7d6af56f
commit
31f04e11d3
37
action.yaml
37
action.yaml
|
|
@ -30,33 +30,44 @@ runs:
|
|||
current_date=$(date +"%Y.%m.%d" | sed 's/\.0/\./g')
|
||||
echo "current_date=$current_date"
|
||||
|
||||
echo "curl -H 'Authorization:token ${{ inputs.token }}' ${{ inputs.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"
|
||||
echo "正在调用API: ${{ inputs.server_url }}/api/v1/repos/${{ inputs.repository }}/releases"
|
||||
# 获取所有发布版本号
|
||||
json=''
|
||||
json=$(curl -H 'Authorization:token ${{ inputs.token }}' ${{ inputs.server_url }}/api/v1/repos/${{ gitea.repository }}/releases)
|
||||
echo "json=$json"
|
||||
json=$(curl -s -H 'Authorization:token ${{ inputs.token }}' ${{ inputs.server_url }}/api/v1/repos/${{ inputs.repository }}/releases)
|
||||
echo "API响应长度: ${#json}"
|
||||
echo "API响应前100字符: ${json:0:100}"
|
||||
|
||||
# 检查是否存在当前日期的版本
|
||||
if [ -n "$json" ]; then
|
||||
# 提取所有标签名
|
||||
tags=$(echo $json | grep -oP '"tag_name"\s*:\s*"\K[^"]*')
|
||||
if [ -n "$json" ] && [ "$json" != "[]" ]; then
|
||||
# 尝试使用jq工具解析JSON(更可靠)
|
||||
if command -v jq &> /dev/null; then
|
||||
echo "使用jq解析JSON"
|
||||
tags=$(echo "$json" | jq -r '.[].tag_name')
|
||||
else
|
||||
# 回退到使用grep解析
|
||||
echo "使用grep解析JSON"
|
||||
tags=$(echo $json | grep -oP '"tag_name"\s*:\s*"\K[^"]*')
|
||||
fi
|
||||
|
||||
echo "提取到的标签数量: $(echo "$tags" | wc -l)"
|
||||
echo "前5个标签: $(echo "$tags" | head -5)"
|
||||
|
||||
# 过滤出当前日期的版本
|
||||
date_tags=$(echo "$tags" | grep "^$current_date")
|
||||
echo "date_tags=$date_tags"
|
||||
echo "当前日期的标签: $date_tags"
|
||||
|
||||
if [ -n "$date_tags" ]; then
|
||||
# 计算当前日期版本的数量
|
||||
count=$(echo "$date_tags" | wc -l)
|
||||
# 如果有多个版本,添加数字后缀
|
||||
if [ $count -gt 0 ]; then
|
||||
version="$current_date-$count"
|
||||
else
|
||||
version="$current_date"
|
||||
fi
|
||||
echo "当前日期版本数量: $count"
|
||||
# 版本号格式为日期-数字
|
||||
version="$current_date-$count"
|
||||
else
|
||||
# 没有当前日期的版本,使用初始版本号
|
||||
version="$current_date"
|
||||
fi
|
||||
else
|
||||
echo "未获取到发布版本信息,使用初始版本号"
|
||||
version="$current_date"
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue