auto-release/action.yaml

79 lines
2.5 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: auto-release
description: 自动发布版本
inputs:
server_url:
required: false
description: 服务器地址
default: ${{ gitea.server_url }}
token:
required: false
description: 授权凭证
default: ${{ gitea.token }}
files:
required: false
description: 要上传的文件
outputs:
version:
description: 发布的版本号
value: ${{ steps.get_version.outputs.version }}
runs:
using: composite
steps:
- name: 获取最新发布版本号
id: get_version
shell: bash
run: |
# 获取当前日期作为基础版本号
current_date=$(date +"%Y.%m.%d" | sed 's/\.0/\./g')
# 获取所有发布版本号
json=''
json=$(curl -s -H 'Authorization:token ${{ inputs.token }}' ${{ inputs.server_url }}/api/v1/repos/${{ gitea.repository }}/releases)
# 检查是否存在当前日期的版本
if [ -n "$json" ] && [ "$json" != "[]" ]; then
# 尝试使用jq工具解析JSON更可靠
if command -v jq &> /dev/null; then
tags=$(echo "$json" | jq -r '.[].tag_name' 2>/dev/null || echo "")
else
# 回退到使用grep解析
tags=$(echo $json | grep -oP '"tag_name"\s*:\s*"\K[^"]*' 2>/dev/null || echo "")
fi
# 过滤出当前日期的版本
date_tags=$(echo "$tags" | grep "^$current_date" 2>/dev/null || echo "")
if [ -n "$date_tags" ]; then
# 计算当前日期版本的数量
count=$(echo "$date_tags" | wc -l)
# 版本号格式为日期-数字
version="$current_date-$count"
else
# 没有当前日期的版本,使用初始版本号
version="$current_date"
fi
else
# 未获取到发布版本信息,使用初始版本号
version="$current_date"
fi
echo "version=$version"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: 创建标签
shell: bash
run: |
tag_name="${{ steps.get_version.outputs.version }}"
git tag $tag_name ${{ gitea.ref_name }}
git push --tags
- name: 发布版本
uses: actions/release@master
with:
name: ${{ steps.get_version.outputs.version }}
tag_name: ${{ steps.get_version.outputs.version }}
target_commitish: ${{ gitea.ref_name }}
files: ${{ inputs.files }}