添加最后标签编译脚本,程序启动与单元测试流程优化。

This commit is contained in:
2026-01-21 16:21:20 +08:00
parent 73dfac7822
commit 014e20b37f
9 changed files with 561 additions and 311 deletions

View File

@@ -0,0 +1,44 @@
#!/bin/bash
set -euo pipefail
# 前置校验当前是否为git仓库非git仓库直接退出
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "错误当前目录不是git仓库终止执行"
exit 1
fi
# 重置本地修改、切main分支拉最新代码
git restore .
git checkout main || { echo "切换main分支失败终止执行"; exit 1; }
git pull origin main --rebase || { echo "拉取main分支最新代码失败终止执行"; exit 1; }
# 优先取HEAD关联tag无则取仓库最近tag
get_latest_tag() {
local head_tag=$(git log -1 --pretty=format:%D 2>/dev/null | grep -o 'tag: [^, ]*' | awk -F': ' '{print $2}')
[ -n "$head_tag" ] && { echo "$head_tag"; return 0; }
local latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || true)
[ -n "$latest_tag" ] && { echo "$latest_tag"; return 0; }
echo "no_tag" && return 1
}
# 获取并校验tag无tag直接退出
latest_tag=$(get_latest_tag)
if [ "$latest_tag" = "no_tag" ]; then
echo "仓库无任何tag终止执行"
exit 1
fi
echo "获取到目标tag$latest_tag"
# 切换tag失败退出
git checkout "$latest_tag" || { echo "切换至tag $latest_tag失败,终止执行"; exit 1; }
# 执行构建脚本,失败直接退出
bash bash/build_class.sh || { echo "构建脚本执行失败,终止执行"; exit 1; }
# 确保config目录存在写入tag信息
mkdir -p config
echo "$latest_tag" > config/version.flags
echo "✅ 全部操作完成tag已写入config/version.flags"