ActionDemo/.gitea/workflows/AutoRelease.yaml
liyp 959bfac1cc
Some checks failed
自动版本发布 / AutoRelease (push) Successful in 15s
自动版本发布 / AutoREADME.md (push) Failing after 24s
Release v1.5.0 测试生成readme.md
2025-04-12 18:33:29 +08:00

266 lines
11 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://git.linuxacme.com/iorebuild/checkout@v4
with:
fetch-depth: 0
# 启用子模块支持
submodules: false
- name: 设置环境变量
env:
CURRENT_USER_NAME: "iorebuild"
CURRENT_USER_EMAIL: "liyepan@linuxacme.com"
GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
git config user.name "$CURRENT_USER_NAME"
git config user.email "$CURRENT_USER_EMAIL"
echo "Name = $CURRENT_USER_NAME"
echo "Email = $CURRENT_USER_EMAIL"
- 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: 从提交信息提取版本号
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=$VERSION" >> $GITHUB_OUTPUT
echo "提取到的版本号: $VERSION"
- 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: 查找第1个.bin 文件
id: find-bin-files-1
run: |
BIN_FILES=$(find ./Bin -name "*.bin" -print0 | tr '\0' ',')
BIN_FILES=${BIN_FILES%,}
echo "bin_files=$BIN_FILES" >> $GITHUB_OUTPUT
echo "bin_files=$BIN_FILES"
- name: 查找第2个.bin 文件
id: find-bin-files-2
run: |
BIN_FILES=$(find ./Bin1 -name "*.bin" -print0 | tr '\0' ',')
BIN_FILES=${BIN_FILES%,}
echo "bin_files=$BIN_FILES" >> $GITHUB_OUTPUT
- name: 查找第3个.bin 文件
id: find-bin-files-3
run: |
BIN_FILES=$(find ./Bin2 -name "*.bin" -print0 | tr '\0' ',')
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" >> $GITHUB_OUTPUT
echo "commit_log=$COMMIT_LOG"
- name: 解析Release标题
id: parse-release
run: |
commit_message="${{ github.event.head_commit.message }}"
title=$(echo "$commit_message" | cut -d ' ' -f 3-)
if [ -z "$title" ]; then
echo "未在提交信息中找到 Release 标题。"
title="default_title"
fi
# 使用新语法设置输出
echo "title=$title" >> $GITHUB_OUTPUT
echo "title=$title"
- name: 获取最终Release信息
run: |
echo "Version = ${{ steps.extract_version.outputs.version }}"
echo "Repo = ${{ github.server_url }}/${{ github.repository }}"
echo "TagName = ${{ steps.extract_version.outputs.version }}"
echo "ReleaseName = ${{ steps.parse-release.outputs.title }}"
echo "Body = ${{ steps.get-commit-log.outputs.commit_log }}"
- name: 创建Gitea发布
uses: https://git.linuxacme.com/iorebuild/gitea-release-action@main
with:
gitea_token: ${{ secrets.AUTOGENERATE }}
gitea_instance_url: ${{ github.server_url }}
repository: ${{ github.repository }}
name: ${{ steps.parse-release.outputs.title }}
tag_name: ${{ steps.extract_version.outputs.version }}
body: |
${{ steps.get-commit-log.outputs.commit_log }}
draft: false
prerelease: false
files: |
${{ steps.find-bin-files-1.outputs.bin_files }}
${{ steps.find-bin-files-2.outputs.bin_files }}
${{ steps.find-bin-files-3.outputs.bin_files }}
AutoREADME.md:
# 工作在ubuntu-latest系统中
runs-on: ubuntu-latest
# 以下是steps
steps:
- name: 检出仓库
uses: https://git.linuxacme.com/iorebuild/checkout@v4
with:
fetch-depth: 0
# 启用子模块支持
submodules: false
- name: 设置环境变量
env:
CURRENT_USER_NAME: "iorebuild"
CURRENT_USER_EMAIL: "liyepan@linuxacme.com"
GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
git config user.name "$CURRENT_USER_NAME"
git config user.email "$CURRENT_USER_EMAIL"
echo "Name = $CURRENT_USER_NAME"
echo "Email = $CURRENT_USER_EMAIL"
- 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: 安装jq工具
run: |
sudo apt update
sudo apt install jq -y
- name: 如果有README文件存在则删除掉
run: |
if [ -f "README.md" ]; then
rm README.md
echo "README.md has been removed."
else
echo "README.md does not exist."
fi
- name: 添加工程名字到README.md
run: |
REPO_NAME="ActionDemo"
if [ -f "README.md" ]; then
TEMP=$(cat README.md)
echo "$REPO_NAME" > README.md
echo "$TEMP" >> README.md
else
echo "$REPO_NAME" > README.md
fi
- name: Get all releases
id: get-releases
env:
GITEA_API_TOKEN: ${{ secrets.GITEA_API_TOKEN }}
GITEA_INSTANCE_URL: ${{ secrets.GITEA_INSTANCE_URL }}
GITEA_REPO: ${{ secrets.GITEA_REPO }}
run: |
# 获取所有发布信息,使用 Gitea API
releases=$(curl -s -H "Authorization: token $GITEA_API_TOKEN" \
"$GITEA_INSTANCE_URL/api/v1/repos/$GITEA_REPO/releases")
# 解析发布信息,提取名称、发布时间和发布说明
output=""
for row in $(echo "${releases}" | jq -r '.[] | @base64'); do
_jq() {
echo "${row}" | base64 --decode | jq -r "${1}"
}
name=$(_jq '.name')
published_at=$(_jq '.published_at')
body=$(_jq '.body')
output="${output}- **${name}** (${published_at}):\n ${body}\n"
done
# 按发布时间倒序排序
sorted_output=$(echo -e "${output}" | sort -r)
echo "::set-output name=release_info::$sorted_output"
- name: Update README.md
run: |
release_info="${{ steps.get-releases.outputs.release_info }}"
if [ -f README.md ]; then
# 查找并替换原有的版本发布部分,如果没有则添加到开头
if grep -q "### Release Information" README.md; then
sed -i '/### Release Information/,/^$/d' README.md
fi
{
echo "### Release Information"
echo "$release_info"
echo ""
cat README.md
} > temp.md
mv temp.md README.md
else
{
echo "### Release Information"
echo "$release_info"
} > README.md
fi
- name: 提交和推送代码
run: |
git add README.md
git commit -m "Update README.md"
git push https://${{ secrets.AUTOGENERATE }}@git.linuxacme.com/${{ github.repository }}