Fix devtoprod git step exit-code handling
Add Invoke-Git with safe external command execution and stop using prod LAN URL for dev validateBuild checks. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
c391fcc21e
commit
0de95fd151
@@ -29,6 +29,7 @@
|
|||||||
"password": ""
|
"password": ""
|
||||||
},
|
},
|
||||||
"verify": {
|
"verify": {
|
||||||
|
"devLanUrl": "http://192.168.10.70:5173/api/bounds",
|
||||||
"devUrl": "https://devgallery.mysuperlab.netcraze.pro/api/bounds",
|
"devUrl": "https://devgallery.mysuperlab.netcraze.pro/api/bounds",
|
||||||
"lanUrl": "http://192.168.10.122:5173/api/bounds",
|
"lanUrl": "http://192.168.10.122:5173/api/bounds",
|
||||||
"publicUrl": "https://gallery.mysuperlab.netcraze.pro/api/bounds"
|
"publicUrl": "https://gallery.mysuperlab.netcraze.pro/api/bounds"
|
||||||
|
|||||||
@@ -55,22 +55,41 @@ function Invoke-Npm {
|
|||||||
$npmArgs += '--'
|
$npmArgs += '--'
|
||||||
$npmArgs += $ExtraArgs
|
$npmArgs += $ExtraArgs
|
||||||
}
|
}
|
||||||
# Important: callers assign the return value of this function to a variable
|
|
||||||
# (e.g. `$code = Invoke-Npm 'prod:build'`).
|
|
||||||
# If npm output is sent to the pipeline, PowerShell can accidentally capture
|
|
||||||
# stdout/stderr along with the function return value, breaking exit-code logic.
|
|
||||||
# So we stream npm output to $null and return only the exit code.
|
|
||||||
Write-Host ("Running npm: npm " + ($npmArgs -join ' ')) -ForegroundColor DarkGray
|
Write-Host ("Running npm: npm " + ($npmArgs -join ' ')) -ForegroundColor DarkGray
|
||||||
# Capture stdout/stderr so the function does not emit pipeline output.
|
return Invoke-ExternalCommand -Name 'npm' -CommandArgs $npmArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-Git {
|
||||||
|
param([string[]]$GitArgs)
|
||||||
|
Write-Host ("Running git: git " + ($GitArgs -join ' ')) -ForegroundColor DarkGray
|
||||||
|
return Invoke-ExternalCommand -Name 'git' -CommandArgs $GitArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-GitPorcelainStatus {
|
||||||
$prevEap = $ErrorActionPreference
|
$prevEap = $ErrorActionPreference
|
||||||
$ErrorActionPreference = 'Continue'
|
$ErrorActionPreference = 'Continue'
|
||||||
$npmOutput = & npm @npmArgs 2>&1
|
$output = & git status --porcelain 2>&1
|
||||||
|
$ErrorActionPreference = $prevEap
|
||||||
|
return ($output | Out-String).Trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-ExternalCommand {
|
||||||
|
param(
|
||||||
|
[string]$Name,
|
||||||
|
[string[]]$CommandArgs
|
||||||
|
)
|
||||||
|
|
||||||
|
# Capture stdout/stderr so callers assigning the return value only get exit code.
|
||||||
|
$prevEap = $ErrorActionPreference
|
||||||
|
$ErrorActionPreference = 'Continue'
|
||||||
|
$output = & $Name @CommandArgs 2>&1
|
||||||
|
$exit = $LASTEXITCODE
|
||||||
$ErrorActionPreference = $prevEap
|
$ErrorActionPreference = $prevEap
|
||||||
|
|
||||||
foreach ($line in $npmOutput) {
|
foreach ($line in $output) {
|
||||||
Write-Host $line
|
Write-Host $line
|
||||||
}
|
}
|
||||||
return $LASTEXITCODE
|
return $exit
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-Step {
|
function Invoke-Step {
|
||||||
@@ -93,6 +112,7 @@ function Invoke-Step {
|
|||||||
$code = if ($null -ne $LASTEXITCODE) { $LASTEXITCODE } else { 0 }
|
$code = if ($null -ne $LASTEXITCODE) { $LASTEXITCODE } else { 0 }
|
||||||
}
|
}
|
||||||
if ($code -ne 0) {
|
if ($code -ne 0) {
|
||||||
|
Write-Host ("Step failed with exit code: " + $code) -ForegroundColor Red
|
||||||
$script:FailedStep = $Name
|
$script:FailedStep = $Name
|
||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
@@ -259,15 +279,13 @@ Write-Host ('Steps: ' + ($enabled -join ', '))
|
|||||||
if (Get-StepEnabled $steps 'validateBuild') {
|
if (Get-StepEnabled $steps 'validateBuild') {
|
||||||
$ok = Invoke-Step 'validateBuild' {
|
$ok = Invoke-Step 'validateBuild' {
|
||||||
$code = Invoke-Npm 'prod:build'
|
$code = Invoke-Npm 'prod:build'
|
||||||
Write-Host ("prod:build exit code: " + $code)
|
|
||||||
if ($code -ne 0) { return $code }
|
if ($code -ne 0) { return $code }
|
||||||
|
|
||||||
# Always prefer the dev host on LAN (192.168.10.70) because the HTTPS dev domain
|
# Dev-only endpoints. Do not use verify.lanUrl here (that is prod on TrueNAS).
|
||||||
# can return transient 504 HTML pages during load.
|
$devCandidates = @(
|
||||||
$devCandidates = @()
|
'http://192.168.10.70:5173/api/bounds'
|
||||||
|
)
|
||||||
if ($cfg.verify.devLanUrl) { $devCandidates += $cfg.verify.devLanUrl }
|
if ($cfg.verify.devLanUrl) { $devCandidates += $cfg.verify.devLanUrl }
|
||||||
$devCandidates += 'http://192.168.10.70:5173/api/bounds'
|
|
||||||
if ($cfg.verify.lanUrl) { $devCandidates += $cfg.verify.lanUrl }
|
|
||||||
if ($cfg.verify.devUrl) { $devCandidates += $cfg.verify.devUrl }
|
if ($cfg.verify.devUrl) { $devCandidates += $cfg.verify.devUrl }
|
||||||
$devCandidates = $devCandidates | Select-Object -Unique
|
$devCandidates = $devCandidates | Select-Object -Unique
|
||||||
|
|
||||||
@@ -299,20 +317,20 @@ if (Get-StepEnabled $steps 'gitCommitPush') {
|
|||||||
$stageAll = if ($null -ne $cfg.git.stageAll) { [bool]$cfg.git.stageAll } else { $true }
|
$stageAll = if ($null -ne $cfg.git.stageAll) { [bool]$cfg.git.stageAll } else { $true }
|
||||||
|
|
||||||
if ($stageAll) {
|
if ($stageAll) {
|
||||||
git add -A
|
$code = Invoke-Git @('add', '-A')
|
||||||
if ($LASTEXITCODE -ne 0) { return $LASTEXITCODE }
|
if ($code -ne 0) { return $code }
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = git status --porcelain
|
$status = Get-GitPorcelainStatus
|
||||||
if (-not $status) {
|
if (-not $status) {
|
||||||
Write-Host 'Git: working tree clean, skipping commit.'
|
Write-Host 'Git: working tree clean, skipping commit.'
|
||||||
} else {
|
} else {
|
||||||
git commit -m $message
|
$code = Invoke-Git @('commit', '-m', $message)
|
||||||
if ($LASTEXITCODE -ne 0) { return $LASTEXITCODE }
|
if ($code -ne 0) { return $code }
|
||||||
}
|
}
|
||||||
|
|
||||||
git push origin $branch
|
$code = Invoke-Git @('push', 'origin', $branch)
|
||||||
if ($LASTEXITCODE -ne 0) { return $LASTEXITCODE }
|
if ($code -ne 0) { return $code }
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if (-not $ok) { Write-ReleaseBanner -Success $false -FailedAt $FailedStep; exit 1 }
|
if (-not $ok) { Write-ReleaseBanner -Success $false -FailedAt $FailedStep; exit 1 }
|
||||||
|
|||||||
Reference in New Issue
Block a user