ActionDemo/.gitea/workflows/AutoRelease.yaml
iorebuild 8c24ce7d93
All checks were successful
自动版本发布 / AutoRelease (push) Successful in 1m5s
Release v1.0.6
2025-04-10 21:42:41 +08:00

95 lines
3.8 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
- 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" >> $GITHUB_OUTPUT
- name: 创建Gitea发布
uses: https://gitea.com/actions/gitea-release-action@main
with:
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: "This is a release created by Gitea Release Action."
draft: false
prerelease: false
files: ${{ steps.find-bin-files.outputs.bin_files }}