82 lines
3.1 KiB
YAML
82 lines
3.1 KiB
YAML
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_TOKEN: ${{ secrets.AUTOGENERATE }}
|
||
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 "$GITHUB_OUTPUT" ]; then
|
||
echo "::error::提交信息中未找到有效的版本号 (示例: 'Release v1.0.5')"
|
||
exit 1
|
||
fi
|
||
|
||
- name: 创建并推送标签
|
||
run: |
|
||
git tag -a $GITHUB_OUTPUT \
|
||
-m "Release $GITHUB_OUTPUT"
|
||
git push origin $GITHUB_OUTPUT
|
||
|
||
- name: 创建Gitea发布
|
||
uses: https://gitea.com/actions/release-action@main
|
||
with:
|
||
tag_name: $GITHUB_OUTPUT
|
||
release_name: Release $GITHUB_OUTPUT
|
||
body: "自动化发布版本 $GITHUB_OUTPUT" |