Files
proto/script/get_next_version.sh
2025-08-20 22:37:07 +08:00

34 lines
967 B
Bash
Executable File
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.

#!/bin/bash
# 版本号管理脚本:负责生成并返回下一个版本号
# 递增规则每次递增MINOR位重置PATCH位为0
# 获取proto根目录
ROOT_DIR=$(dirname "$(dirname "$0")")
# 确保version.txt文件存在并设置默认值
if [ ! -f "$ROOT_DIR/version.txt" ]; then
echo "1.0.0" > "$ROOT_DIR/version.txt"
echo "警告version.txt文件不存在已创建并设置默认值1.0.0"
fi
# 读取当前版本号
CURRENT_VERSION=$(cat "$ROOT_DIR/version.txt")
# 解析版本号的MAJOR、MINOR和PATCH部分
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
# 递增MINOR版本号并重置PATCH为0
MINOR=$((MINOR + 1))
PATCH=0
# 生成新版本号
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
# 更新version.txt文件
echo "$NEW_VERSION" > "$ROOT_DIR/version.txt"
# 输出版本号变更信息
echo "版本号已从 $CURRENT_VERSION 更新到 $NEW_VERSION"