Make dev validateBuild bounds check resilient

Retry and prefer LAN bounds URL to avoid transient 504 failures.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Danila Khodjaef
2026-07-08 15:48:51 +03:00
co-authored by Cursor
parent aa6635803d
commit ae6ffc8a08
+49 -17
View File
@@ -170,21 +170,36 @@ function Get-LatestDevBackup {
} }
function Test-BoundsJson { function Test-BoundsJson {
param([string]$Url, [switch]$Insecure) param(
[string]$Url,
[switch]$Insecure,
[int]$MaxTimeSeconds = 10,
[int]$Retries = 3
)
$curlArgs = @('-s', '-f') for ($attempt = 1; $attempt -le $Retries; $attempt++) {
if ($Insecure) { $curlArgs += '-k' } $curlArgs = @('-s', '-f', '--max-time', $MaxTimeSeconds)
$curlArgs += $Url if ($Insecure) { $curlArgs += '-k' }
$body = & curl.exe @curlArgs 2>$null $curlArgs += $Url
if ($LASTEXITCODE -ne 0 -or -not $body) {
return $false $body = & curl.exe @curlArgs 2>$null
} if ($LASTEXITCODE -eq 0 -and $body) {
try { try {
$json = $body | ConvertFrom-Json $json = $body | ConvertFrom-Json
return ($null -ne $json.min_year -and $null -ne $json.max_year) if ($null -ne $json.min_year -and $null -ne $json.max_year) {
} catch { return $true
return $false }
} catch {
# Continue retries below.
}
}
if ($attempt -lt $Retries) {
Start-Sleep -Seconds 2
}
} }
return $false
} }
# --- Load config --- # --- Load config ---
@@ -232,12 +247,29 @@ if (Get-StepEnabled $steps 'validateBuild') {
$code = Invoke-Npm 'prod:build' $code = Invoke-Npm 'prod:build'
if ($code -ne 0) { return $code } if ($code -ne 0) { return $code }
$devUrl = if ($cfg.verify.devUrl) { $cfg.verify.devUrl } else { 'https://devgallery.mysuperlab.netcraze.pro/api/bounds' } $devCandidates = @()
if (-not (Test-BoundsJson -Url $devUrl -Insecure)) { if ($cfg.verify.lanUrl) { $devCandidates += $cfg.verify.lanUrl }
Write-Host "Dev API check failed: $devUrl" -ForegroundColor Red if ($cfg.verify.devUrl -and ($devCandidates -notcontains $cfg.verify.devUrl)) { $devCandidates += $cfg.verify.devUrl }
if (-not $devCandidates -or $devCandidates.Count -eq 0) {
$devCandidates = @('https://devgallery.mysuperlab.netcraze.pro/api/bounds')
}
$devOk = $false
foreach ($u in $devCandidates) {
Write-Host "Checking dev /api/bounds: $u"
$useInsecure = $u.StartsWith('https://', [System.StringComparison]::OrdinalIgnoreCase)
if (Test-BoundsJson -Url $u -Insecure:$useInsecure -MaxTimeSeconds 10 -Retries 3) {
Write-Host "Dev API OK: $u"
$devOk = $true
break
}
Write-Host "Dev API check failed for: $u" -ForegroundColor DarkYellow
}
if (-not $devOk) {
Write-Host "Dev API check failed on all URLs." -ForegroundColor Red
return 1 return 1
} }
Write-Host "Dev API OK: $devUrl"
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 }