From a0b05812d3f81e911b23f9f75a75281b4b9f6cf8 Mon Sep 17 00:00:00 2001 From: hanxuanyu <2252193204@qq.com> Date: Tue, 27 Jan 2026 15:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=84=9A=E6=9C=AC=EF=BC=9A?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E5=A4=84=E7=90=86=E5=92=8C=20PowerS?= =?UTF-8?q?hell=20=E8=84=9A=E6=9C=AC=E7=94=A8=E4=BA=8E=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=A0=87=E7=AD=BE=E7=9A=84=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E5=88=9B=E5=BB=BA=E4=B8=8E=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tag.bat | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/tag.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 scripts/tag.bat create mode 100644 scripts/tag.ps1 diff --git a/scripts/tag.bat b/scripts/tag.bat new file mode 100644 index 0000000..92236db --- /dev/null +++ b/scripts/tag.bat @@ -0,0 +1,53 @@ +@echo off +setlocal enabledelayedexpansion + +:: 切换到项目根目录 +cd /d %~dp0.. + +:: 获取版本号 +set TAG_NAME=%1 + +if "%TAG_NAME%"=="" ( + echo Usage: .\scripts\tag.bat ^ + exit /b 1 +) + +:: 确保在 master 分支 +for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set CURRENT_BRANCH=%%i +if not "%CURRENT_BRANCH%"=="master" ( + echo Error: Must be on master branch to tag. Current branch: %CURRENT_BRANCH% + exit /b 1 +) + +:: 检查是否有未提交的代码 +set CHANGES= +for /f "tokens=*" %%i in ('git status --porcelain') do set CHANGES=%%i +if not "%CHANGES%"=="" ( + echo Error: You have uncommitted changes. Please commit or stash them first. + exit /b 1 +) + +:: 拉取最新代码 +echo Updating master branch... +git pull origin master +if %errorlevel% neq 0 exit /b %errorlevel% + +:: 检查本地和远端是否一致 +for /f "tokens=*" %%i in ('git rev-parse @') do set LOCAL=%%i +for /f "tokens=*" %%i in ('git rev-parse @{u}') do set REMOTE=%%i + +if not "%LOCAL%"=="%REMOTE%" ( + echo Error: Local branch is not in sync with remote. Please push your changes first. + exit /b 1 +) + +:: 创建并推送 tag +echo Creating tag %TAG_NAME%... +git tag -f "%TAG_NAME%" +if %errorlevel% neq 0 exit /b %errorlevel% + +echo Pushing tag %TAG_NAME% to remote... +git push origin "%TAG_NAME%" -f +if %errorlevel% neq 0 exit /b %errorlevel% + +echo Done! GitHub Action should be triggered shortly. diff --git a/scripts/tag.ps1 b/scripts/tag.ps1 new file mode 100644 index 0000000..57980da --- /dev/null +++ b/scripts/tag.ps1 @@ -0,0 +1,50 @@ +# 切换到项目根目录 +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition +if ($ScriptDir) { Set-Location (Join-Path $ScriptDir "..") } + +# 获取版本号 +$TagName = $args[0] + +if (-not $TagName) { + Write-Host "Usage: .\scripts\tag.ps1 " + exit 1 +} + +# 确保在 master 分支 +$CurrentBranch = git rev-parse --abbrev-ref HEAD +if ($CurrentBranch -ne "master") { + Write-Host "Error: Must be on master branch to tag. Current branch: $CurrentBranch" -ForegroundColor Red + exit 1 +} + +# 检查是否有未提交的代码 +$Changes = git status --porcelain +if ($Changes) { + Write-Host "Error: You have uncommitted changes. Please commit or stash them first." -ForegroundColor Red + exit 1 +} + +# 拉取最新代码 +Write-Host "Updating master branch..." +git pull origin master +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +# 检查本地和远端是否一致 +$Local = git rev-parse @ +$Remote = git rev-parse @{u} + +if ($Local -ne $Remote) { + Write-Host "Error: Local branch is not in sync with remote. Please push your changes first." -ForegroundColor Red + exit 1 +} + +# 创建并推送 tag +Write-Host "Creating tag $TagName..." +git tag -f "$TagName" +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +Write-Host "Pushing tag $TagName to remote..." +git push origin "$TagName" -f +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +Write-Host "Done! GitHub Action should be triggered shortly."