ActionDemo/.gitea/workflows/AutoRelease.yaml
iorebuild 81aae1071b
Some checks failed
自动版本发布 / AutoRelease (push) Has been cancelled
Release v1.0.9
2025-04-10 22:04:35 +08:00

117 lines
4.6 KiB
YAML
Raw 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: 自动版本发布
on:
push:
branches:
- main
jobs:
AutoRelease:
# 如果有Release标签则运行jobs
if: "contains(github.event.head_commit.message, 'Release')"
# 工作在ubuntu-latest系统中
runs-on: ubuntu-latest
# 以下是steps
steps:
- name: 检出仓库
uses: https://gitee.com/actions-mirror/checkout@v4
with:
fetch-depth: 0
# 启用子模块支持
submodules: true
- name: 设置环境变量
env:
GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.git.linuxacme.com"
- name: 替换软件源为国内软件源USTC
run: |
cat /etc/os-release
sudo rm -f /etc/apt/sources.list
sudo rm -f /etc/apt/sources.list.d/*
sudo tee /etc/apt/sources.list <<EOF
deb http://mirrors.ustc.edu.cn/ubuntu/ noble main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ noble main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ noble-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ noble-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
EOF
- name: 安装 tea 工具
run: |
# 更新 apt 缓存
sudo apt-get update
# 安装 tea 工具
sudo apt-get install -y tea golang
- name: 从提交信息提取版本号
id: extract_version
run: |
# 从提交信息中提取 vX.X.X 格式的版本号
VERSION=$(echo "${{ github.event.head_commit.message }}" | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+')
echo "提取到的版本号: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: 验证版本号
run: |
if [ -z "${{ steps.extract_version.outputs.version }}" ]; then
echo "::error::提交信息中未找到有效的版本号 (示例: 'Release v1.0.5')"
exit 1
fi
echo "${{ steps.extract_version.outputs.version }}"
- name: 创建并推送标签
run: |
git tag -a ${{ steps.extract_version.outputs.version }} \
-m "Release ${{ steps.extract_version.outputs.version }}"
git push origin ${{ steps.extract_version.outputs.version }}
- name: 查找 .bin 文件
id: find-bin-files
run: |
BIN_FILES=$(find ./Bin -name "*.bin" -print0 | tr '\0' ',')
BIN_FILES=${BIN_FILES%,} # 移除最后一个逗号
echo "bin_files=$BIN_FILES"
echo "bin_files=$BIN_FILES" >> $GITHUB_OUTPUT
- name: 获取上次发布标签
id: get-previous-tag
run: |
PREVIOUS_TAG=$(git tag --sort=-creatordate | sed -n '2p')
if [ -z "$PREVIOUS_TAG" ]; then
PREVIOUS_TAG="HEAD~1" # 如果没有上次标签,使用上一次提交
fi
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
echo "$PREVIOUS_TAG"
- name: 获取提交记录
id: get-commit-log
run: |
COMMIT_LOG=$(git log ${{ steps.get-previous-tag.outputs.previous_tag }}..HEAD --pretty=format:"- %s (%h)" | tr '\n' '\r')
echo "commit_log=$COMMIT_LOG"
echo "commit_log=$COMMIT_LOG" >> $GITHUB_OUTPUT
- name: 创建Gitea发布
uses: https://gitea.com/actions/gitea-release-action@main
with:
run: |
echo "${{ secrets.AUTOGENERATE }}"
gitea_token: ${{ secrets.AUTOGENERATE }}
gitea_instance_url: ${{ github.server_url }}
repository: ${{ github.repository }}
tag_name: ${{ steps.extract_version.outputs.version }}
release_name: Release ${{ steps.extract_version.outputs.version }}
body: |
${{ steps.get-commit-log.outputs.commit_log }}
draft: false
prerelease: false
files: ${{ steps.find-bin-files.outputs.bin_files }}