|
|
|
|
@@ -35,40 +35,68 @@ function Remove-GitNoise {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Convert-GitOutputLines {
|
|
|
|
|
param($Output)
|
|
|
|
|
return @(
|
|
|
|
|
@($Output) | ForEach-Object {
|
|
|
|
|
if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.ToString() }
|
|
|
|
|
else { "$_" }
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Call git.exe directly. Do not wrap with `cmd /c` — on Chinese Windows, cmd
|
|
|
|
|
# re-encodes -m / -F arguments through the OEM code page and garbles UTF-8
|
|
|
|
|
# annotated tag / commit messages (e.g. 「正式发布」 → 「姝e紡鍙戝竷」).
|
|
|
|
|
function Invoke-GitRaw {
|
|
|
|
|
param([Parameter(Mandatory = $true)][string[]]$GitArgs)
|
|
|
|
|
$prev = $ErrorActionPreference
|
|
|
|
|
$ErrorActionPreference = "Continue"
|
|
|
|
|
try {
|
|
|
|
|
$output = & git @GitArgs 2>&1
|
|
|
|
|
$code = $LASTEXITCODE
|
|
|
|
|
} finally {
|
|
|
|
|
$ErrorActionPreference = $prev
|
|
|
|
|
}
|
|
|
|
|
return [pscustomobject]@{
|
|
|
|
|
ExitCode = $code
|
|
|
|
|
Lines = @(Remove-GitNoise -Lines @(Convert-GitOutputLines -Output $output))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Invoke-Git {
|
|
|
|
|
param([Parameter(Mandatory = $true)][string]$Args)
|
|
|
|
|
Write-Host ">> git $Args" -ForegroundColor DarkGray
|
|
|
|
|
& cmd /c "git $Args 2>&1" | Out-Null
|
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
|
throw "git command failed: git $Args"
|
|
|
|
|
param([Parameter(Mandatory = $true)][string[]]$GitArgs)
|
|
|
|
|
Write-Host (">> git " + ($GitArgs -join " ")) -ForegroundColor DarkGray
|
|
|
|
|
$r = Invoke-GitRaw -GitArgs $GitArgs
|
|
|
|
|
if ($r.ExitCode -ne 0) {
|
|
|
|
|
throw "git command failed: git $($GitArgs -join ' ')"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-GitOutput {
|
|
|
|
|
param([Parameter(Mandatory = $true)][string]$Args)
|
|
|
|
|
$output = & cmd /c "git $Args 2>&1"
|
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
|
throw "git command failed: git $Args"
|
|
|
|
|
param([Parameter(Mandatory = $true)][string[]]$GitArgs)
|
|
|
|
|
$r = Invoke-GitRaw -GitArgs $GitArgs
|
|
|
|
|
if ($r.ExitCode -ne 0) {
|
|
|
|
|
throw "git command failed: git $($GitArgs -join ' ')"
|
|
|
|
|
}
|
|
|
|
|
return @(Remove-GitNoise -Lines @($output))
|
|
|
|
|
return @($r.Lines)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Test-Repo {
|
|
|
|
|
$output = & cmd /c "git rev-parse --is-inside-work-tree 2>&1"
|
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
|
$r = Invoke-GitRaw -GitArgs @("rev-parse", "--is-inside-work-tree")
|
|
|
|
|
if ($r.ExitCode -ne 0) {
|
|
|
|
|
return $false
|
|
|
|
|
}
|
|
|
|
|
$clean = Remove-GitNoise -Lines @($output)
|
|
|
|
|
return (($clean | Select-Object -First 1) -eq "true")
|
|
|
|
|
return (($r.Lines | Select-Object -First 1) -eq "true")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-CurrentBranch {
|
|
|
|
|
$b = (Get-GitOutput "branch --show-current" | Select-Object -First 1).Trim()
|
|
|
|
|
$b = (Get-GitOutput -GitArgs @("branch", "--show-current") | Select-Object -First 1).Trim()
|
|
|
|
|
return $b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-StatusPorcelain {
|
|
|
|
|
$lines = @(Get-GitOutput "status --porcelain")
|
|
|
|
|
$lines = @(Get-GitOutput -GitArgs @("status", "--porcelain"))
|
|
|
|
|
return $lines
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -92,7 +120,7 @@ function Parse-SemVerTag {
|
|
|
|
|
function Get-NextTag {
|
|
|
|
|
param([string]$TagPrefix)
|
|
|
|
|
|
|
|
|
|
$tags = Get-GitOutput "tag --list"
|
|
|
|
|
$tags = Get-GitOutput -GitArgs @("tag", "--list")
|
|
|
|
|
$parsed = @()
|
|
|
|
|
|
|
|
|
|
foreach ($t in $tags) {
|
|
|
|
|
@@ -181,7 +209,7 @@ function Ensure-CleanOrAutoCommit {
|
|
|
|
|
|
|
|
|
|
if ($NeedClean) {
|
|
|
|
|
Write-Host "Working tree is not clean and -RequireClean is enabled." -ForegroundColor Yellow
|
|
|
|
|
Remove-GitNoise -Lines @(& cmd /c "git status --short 2>&1") | ForEach-Object { Write-Host $_ }
|
|
|
|
|
(Invoke-GitRaw -GitArgs @("status", "--short")).Lines | ForEach-Object { Write-Host $_ }
|
|
|
|
|
throw "Abort: dirty working tree."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -200,8 +228,8 @@ function Ensure-CleanOrAutoCommit {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Invoke-Git "add -A"
|
|
|
|
|
Invoke-Git "commit -m `"$commitMsg`""
|
|
|
|
|
Invoke-Git -GitArgs @("add", "-A")
|
|
|
|
|
Invoke-Git -GitArgs @("commit", "-m", $commitMsg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -223,10 +251,10 @@ try {
|
|
|
|
|
if ($DryRun) {
|
|
|
|
|
Write-Host "[DryRun] Would run: git fetch --tags --prune origin" -ForegroundColor Yellow
|
|
|
|
|
} else {
|
|
|
|
|
Invoke-Git "fetch --tags --prune origin"
|
|
|
|
|
Invoke-Git -GitArgs @("fetch", "--tags", "--prune", "origin")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$skillRoot = (Get-GitOutput "rev-parse --show-toplevel" | Select-Object -First 1).Trim()
|
|
|
|
|
$skillRoot = (Get-GitOutput -GitArgs @("rev-parse", "--show-toplevel") | Select-Object -First 1).Trim()
|
|
|
|
|
if (Test-Path -LiteralPath (Join-Path $skillRoot "SKILL.md")) {
|
|
|
|
|
Assert-SkillReleasePackagingSources -SkillRoot $skillRoot
|
|
|
|
|
}
|
|
|
|
|
@@ -235,8 +263,8 @@ try {
|
|
|
|
|
|
|
|
|
|
Ensure-CleanOrAutoCommit -DoAutoCommit:$AutoCommit -NeedClean:$RequireClean -IsDryRun:$DryRun -Msg $CommitMessage
|
|
|
|
|
|
|
|
|
|
$null = Remove-GitNoise -Lines @(& cmd /c 'git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>&1')
|
|
|
|
|
$hasUpstream = ($LASTEXITCODE -eq 0)
|
|
|
|
|
$upstream = Invoke-GitRaw -GitArgs @("rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}")
|
|
|
|
|
$hasUpstream = ($upstream.ExitCode -eq 0)
|
|
|
|
|
|
|
|
|
|
if ($DryRun) {
|
|
|
|
|
if ($hasUpstream) {
|
|
|
|
|
@@ -246,16 +274,16 @@ try {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($hasUpstream) {
|
|
|
|
|
Invoke-Git "push"
|
|
|
|
|
Invoke-Git -GitArgs @("push")
|
|
|
|
|
} else {
|
|
|
|
|
Invoke-Git "push -u origin $branch"
|
|
|
|
|
Invoke-Git -GitArgs @("push", "-u", "origin", $branch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$nextTag = Get-NextTag -TagPrefix $Prefix
|
|
|
|
|
Write-Host "Next tag: $nextTag" -ForegroundColor Green
|
|
|
|
|
|
|
|
|
|
$existing = @(Get-GitOutput "tag --list `"$nextTag`"")
|
|
|
|
|
$existing = @(Get-GitOutput -GitArgs @("tag", "--list", $nextTag))
|
|
|
|
|
if ($existing.Length -gt 0) {
|
|
|
|
|
throw "Tag already exists: $nextTag"
|
|
|
|
|
}
|
|
|
|
|
@@ -267,8 +295,8 @@ try {
|
|
|
|
|
exit 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Invoke-Git "tag -a $nextTag -m `"$Message`""
|
|
|
|
|
Invoke-Git "push origin $nextTag"
|
|
|
|
|
Invoke-Git -GitArgs @("tag", "-a", $nextTag, "-m", $Message)
|
|
|
|
|
Invoke-Git -GitArgs @("push", "origin", $nextTag)
|
|
|
|
|
|
|
|
|
|
Write-Host "Release success: $nextTag" -ForegroundColor Green
|
|
|
|
|
Write-Host "=== Release Script Done ===" -ForegroundColor Cyan
|
|
|
|
|
|