♻️ Refactoring configuration migration service
This commit is contained in:
73
scripts/version.bat
Normal file
73
scripts/version.bat
Normal file
@@ -0,0 +1,73 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM Simplified version management script - Windows version
|
||||
REM Auto-increment patch version from git tags or use custom version
|
||||
|
||||
REM Configuration section - Set custom version here if needed
|
||||
set "CUSTOM_VERSION="
|
||||
REM Example: set "CUSTOM_VERSION=2.0.0"
|
||||
|
||||
set "VERSION_FILE=version.txt"
|
||||
|
||||
REM Check if custom version is set
|
||||
if not "%CUSTOM_VERSION%"=="" (
|
||||
echo [INFO] Using custom version: %CUSTOM_VERSION%
|
||||
set "VERSION=%CUSTOM_VERSION%"
|
||||
goto :save_version
|
||||
)
|
||||
|
||||
REM Check if git is available
|
||||
git --version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Git is not installed or not in PATH
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Check if in git repository
|
||||
git rev-parse --git-dir >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Not in a git repository
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Get latest git tag
|
||||
git describe --abbrev=0 --tags > temp_tag.txt 2>nul
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] No git tags found in repository
|
||||
if exist temp_tag.txt del temp_tag.txt
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set /p LATEST_TAG=<temp_tag.txt
|
||||
del temp_tag.txt
|
||||
|
||||
if not defined LATEST_TAG (
|
||||
echo [ERROR] Failed to read git tag
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [INFO] Latest git tag: %LATEST_TAG%
|
||||
|
||||
REM Remove v prefix
|
||||
set "CLEAN_VERSION=%LATEST_TAG:v=%"
|
||||
|
||||
REM Split version number and increment patch
|
||||
for /f "tokens=1,2,3 delims=." %%a in ("%CLEAN_VERSION%") do (
|
||||
set "MAJOR=%%a"
|
||||
set "MINOR=%%b"
|
||||
set /a "PATCH=%%c+1"
|
||||
)
|
||||
|
||||
set "VERSION=%MAJOR%.%MINOR%.%PATCH%"
|
||||
echo [INFO] Auto-incremented patch version: %VERSION%
|
||||
|
||||
:save_version
|
||||
REM Output version information
|
||||
echo [SUCCESS] Version resolved: %VERSION%
|
||||
echo VERSION=%VERSION%
|
||||
|
||||
REM Save to file
|
||||
echo VERSION=%VERSION% > %VERSION_FILE%
|
||||
|
||||
echo [INFO] Version information saved to %VERSION_FILE%
|
||||
50
scripts/version.sh
Normal file
50
scripts/version.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 配置区域 - 如需自定义版本,请在此处设置
|
||||
CUSTOM_VERSION=""
|
||||
# 示例: CUSTOM_VERSION="2.0.0"
|
||||
|
||||
VERSION_FILE="version.txt"
|
||||
|
||||
# 检查是否设置了自定义版本
|
||||
if [ -n "$CUSTOM_VERSION" ]; then
|
||||
echo "[INFO] Using custom version: $CUSTOM_VERSION"
|
||||
VERSION="$CUSTOM_VERSION"
|
||||
else
|
||||
# 检查git是否可用
|
||||
if ! command -v git &> /dev/null; then
|
||||
echo "[ERROR] Git is not installed or not in PATH"
|
||||
exit 1
|
||||
elif ! git rev-parse --git-dir &> /dev/null; then
|
||||
echo "[ERROR] Not in a git repository"
|
||||
exit 1
|
||||
else
|
||||
# 获取最新的git标签
|
||||
LATEST_TAG=$(git describe --abbrev=0 --tags 2>/dev/null)
|
||||
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
echo "[ERROR] No git tags found in repository"
|
||||
exit 1
|
||||
else
|
||||
echo "[INFO] Latest git tag: $LATEST_TAG"
|
||||
|
||||
# 移除v前缀
|
||||
CLEAN_VERSION=${LATEST_TAG#v}
|
||||
|
||||
# 分割版本号并递增patch版本
|
||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$CLEAN_VERSION"
|
||||
PATCH=$((PATCH + 1))
|
||||
|
||||
VERSION="$MAJOR.$MINOR.$PATCH"
|
||||
echo "[INFO] Auto-incremented patch version: $VERSION"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# 输出版本信息
|
||||
echo "VERSION=$VERSION"
|
||||
|
||||
# 保存到文件供其他脚本使用
|
||||
echo "VERSION=$VERSION" > "$VERSION_FILE"
|
||||
|
||||
echo "[INFO] Version information saved to $VERSION_FILE"
|
||||
Reference in New Issue
Block a user