添加最后标签编译脚本,程序启动与单元测试流程优化。
This commit is contained in:
44
bash/build_class_by_last_tag_version.sh
Normal file
44
bash/build_class_by_last_tag_version.sh
Normal 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"
|
||||
|
||||
Reference in New Issue
Block a user