no message

This commit is contained in:
hajimi
2026-06-12 17:34:00 +08:00
parent b9669269b5
commit bd95eed024
20 changed files with 1383 additions and 112 deletions
+65 -1
View File
@@ -6,6 +6,9 @@ param(
[string]$HostName = "sbnews",
[string]$SshBin = "ssh.exe",
[switch]$AutoIncremental,
[ValidateRange(1, 1000)]
[int]$AutoIncrementalCommits = 1,
[string]$AutoCommitMessage = "",
[string]$From = "",
[string]$To = "",
[string]$RemoteTmp = "/tmp",
@@ -192,6 +195,55 @@ function Remove-IfExists {
}
}
function Get-DeployPathspec {
if ([string]::IsNullOrEmpty($GitPathPrefix)) {
return @(".")
}
return @($GitPathPrefix)
}
function Commit-SourceChangesIfNeeded {
param(
[string]$Repository,
[string[]]$Pathspec
)
$statusArgs = @("-C", $Repository, "status", "--porcelain=v1", "--untracked-files=all", "--") + $Pathspec
$statusLines = @(& git @statusArgs)
if ($LASTEXITCODE -ne 0) {
Fail "git status failed"
}
if ($statusLines.Count -eq 0) {
return
}
$unmerged = @($statusLines | Where-Object { $_ -match "^(DD|AU|UD|UA|DU|AA|UU)" })
if ($unmerged.Count -gt 0) {
Write-DeployLog "unmerged changes detected under ${SourceDir}:"
$unmerged | Select-Object -First 20 | ForEach-Object { Write-Host " $_" }
Fail "resolve merge conflicts under $SourceDir before deploy"
}
Write-DeployLog "uncommitted changes detected under $SourceDir; auto committing before deploy:"
$maxDisplay = 80
$statusLines | Select-Object -First $maxDisplay | ForEach-Object { Write-Host " $_" }
if ($statusLines.Count -gt $maxDisplay) {
Write-Host " ... and $($statusLines.Count - $maxDisplay) more"
}
Invoke-Native "git" (@("-C", $Repository, "add", "-A", "--") + $Pathspec)
$commitMessage = $AutoCommitMessage
if ([string]::IsNullOrWhiteSpace($commitMessage)) {
$commitMessage = "deploy: auto commit $SourceDir changes $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
}
Invoke-Native "git" (@("-C", $Repository, "commit", "-m", $commitMessage, "--") + $Pathspec)
$newCommit = (Invoke-NativeOutput "git" @("-C", $Repository, "rev-parse", "--short", "HEAD") | Select-Object -First 1)
Write-DeployLog "auto commit created: $newCommit"
}
function Copy-FullPayload {
Write-DeployLog "building full payload from current working tree: $SourceDir"
Write-DeployLog "full include paths: $($FullIncludePaths -join ' ')"
@@ -306,6 +358,9 @@ function Write-UpdateLog {
$fromShort = Get-ShortCommit $FromCommit
$toShort = Get-ShortCommit $ToCommit
Write-DeployLog "commit range: $fromShort -> $toShort"
if ($AutoIncremental) {
Write-DeployLog "auto incremental commits: $AutoIncrementalCommits"
}
$logArgs = @("-C", $GitCwd, "-c", "i18n.logOutputEncoding=utf-8", "log", "--encoding=UTF-8", "--no-merges", "--date=format:%Y-%m-%d %H:%M:%S", "--pretty=format: * %h %ad %an %s", "$FromCommit..$ToCommit")
if ($SourceIsGitLink) {
@@ -432,9 +487,13 @@ if ($AutoIncremental -and ($From -or $To)) {
Fail "-AutoIncremental cannot be used with -From/-To"
}
if (-not $AutoIncremental -and $PSBoundParameters.ContainsKey("AutoIncrementalCommits")) {
Fail "-AutoIncrementalCommits can only be used with -AutoIncremental"
}
if ($AutoIncremental) {
$Mode = "incremental"
$FromCommit = "HEAD~1"
$FromCommit = "HEAD~$AutoIncrementalCommits"
$ToCommit = "HEAD"
} elseif ($From -or $To) {
if (-not $From -or -not $To) {
@@ -483,6 +542,9 @@ if (-not $SourceIsGitRepo -and ($lsFiles | Where-Object { $_ -match "^160000\s"
$SourceIsGitLink = $true
}
$DeployPathspec = @(Get-DeployPathspec)
Commit-SourceChangesIfNeeded -Repository $GitCwd -Pathspec $DeployPathspec
if ($Mode -eq "incremental") {
& git -C $GitCwd rev-parse --verify "$FromCommit^{commit}" *> $null
if ($LASTEXITCODE -ne 0) {
@@ -532,8 +594,10 @@ try {
"built_at=$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
)
if ($Mode -eq "incremental") {
$autoIncrementalCommitCount = if ($AutoIncremental) { $AutoIncrementalCommits } else { 0 }
$deployInfo += @(
"auto_incremental=$([int]$AutoIncremental.IsPresent)",
"auto_incremental_commits=$autoIncrementalCommitCount",
"source_is_gitlink=$([int]$SourceIsGitLink)",
"from_commit=$FromCommit",
"to_commit=$ToCommit",