[cli-release-discovery][iter-1] fix(install): select stable CLI releases and verify platform assets
这个提交包含在:
+31
-36
@@ -57,37 +57,38 @@ function Test-Avx2Support {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-LatestVersion {
|
||||
# Resolve the latest version by following the /releases/latest redirect to
|
||||
# /releases/tag/vX.Y.Z. This avoids the API, which is
|
||||
# rate-limited to 60 requests/hour per IP.
|
||||
$latestUrl = "$baseUrl/$REPO/releases/latest"
|
||||
$location = $null
|
||||
$request = [System.Net.HttpWebRequest]::Create($latestUrl)
|
||||
$request.Method = "HEAD"
|
||||
$request.AllowAutoRedirect = $false
|
||||
$request.UserAgent = "octopus-installer"
|
||||
try {
|
||||
$response = $request.GetResponse()
|
||||
$location = $response.Headers["Location"]
|
||||
$response.Close()
|
||||
} catch [System.Net.WebException] {
|
||||
$resp = $_.Exception.Response
|
||||
if ($null -ne $resp) {
|
||||
$location = $resp.Headers["Location"]
|
||||
$resp.Close()
|
||||
function Get-LatestVersion([string]$Filename) {
|
||||
# Desktop archives share this repository. /releases/latest and limit=1
|
||||
# are not CLI selectors. Follow API order, paging past non-CLI releases.
|
||||
$apiUrl = if ($env:GITEA_API_URL) { $env:GITEA_API_URL.TrimEnd('/') } else { "https://eightarms.net/api/v1" }
|
||||
for ($page = 1; $page -le 100; $page++) {
|
||||
$releases = @(Invoke-RestMethod -Uri "$apiUrl/repos/$REPO/releases?limit=50&page=$page" -UseBasicParsing -TimeoutSec 30 -ErrorAction Stop)
|
||||
if ($releases.Count -eq 0) { return "" }
|
||||
foreach ($release in $releases) {
|
||||
if ($release.tag_name -cnotmatch '^v[0-9]+\.[0-9]+\.[0-9]+\z') { continue }
|
||||
if ($release.draft -isnot [bool] -or $release.draft -ne $false) { continue }
|
||||
if ($release.prerelease -isnot [bool] -or $release.prerelease -ne $false) { continue }
|
||||
$assets = @($release.assets | Where-Object { $_.name -ceq $Filename })
|
||||
if ($assets.Count -eq 0) {
|
||||
throw "Latest stable CLI release $($release.tag_name) is missing platform asset $Filename."
|
||||
}
|
||||
return $release.tag_name.Substring(1)
|
||||
}
|
||||
}
|
||||
if (-not $location) { return "" }
|
||||
if ($location -match '/tag/v?([^/]+)/?$') {
|
||||
return $Matches[1] -replace '^v', ''
|
||||
}
|
||||
return ""
|
||||
throw "No public stable CLI release found within 100 pages."
|
||||
}
|
||||
|
||||
function Install-Octopus {
|
||||
$arch = Get-Arch
|
||||
|
||||
# Resolve the platform asset before discovery, so an incomplete release
|
||||
# cannot be selected and a missing baseline/ARM64 archive fails clearly.
|
||||
$target = "$APP-windows-$arch"
|
||||
if ($arch -eq "x64" -and -not (Test-Avx2Support)) {
|
||||
$target = "$APP-windows-$arch-baseline"
|
||||
}
|
||||
$filename = "$target.zip"
|
||||
|
||||
# Resolve version
|
||||
if ($Version -ne "") {
|
||||
$specificVersion = $Version -replace '^v', ''
|
||||
@@ -98,14 +99,14 @@ function Install-Octopus {
|
||||
} catch {
|
||||
Write-Color "Error: Release v$specificVersion not found." "Red"
|
||||
Write-Color "Available releases: $baseUrl/$REPO/releases" "DarkGray"
|
||||
exit 1
|
||||
throw "Release resolution failed."
|
||||
}
|
||||
} else {
|
||||
Write-Color "Fetching latest version..." "DarkGray"
|
||||
$specificVersion = Get-LatestVersion
|
||||
$specificVersion = Get-LatestVersion -Filename $filename
|
||||
if (-not $specificVersion) {
|
||||
Write-Color "Error: Failed to fetch latest version." "Red"
|
||||
exit 1
|
||||
throw "Failed to fetch latest CLI version."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,19 +117,13 @@ function Install-Octopus {
|
||||
$installedVersion = & $existing --version 2>$null
|
||||
if ($installedVersion -eq $specificVersion) {
|
||||
Write-Color "Version $specificVersion already installed." "DarkGray"
|
||||
exit 0
|
||||
return
|
||||
} else {
|
||||
Write-Color "Installed version: $installedVersion" "DarkGray"
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
# Build filename
|
||||
$target = "$APP-windows-$arch"
|
||||
if ($arch -eq "x64" -and -not (Test-Avx2Support)) {
|
||||
$target = "$APP-windows-$arch-baseline"
|
||||
}
|
||||
$filename = "$target.zip"
|
||||
$downloadUrl = "$baseUrl/$REPO/releases/download/v$specificVersion/$filename"
|
||||
|
||||
Write-Color ""
|
||||
@@ -147,7 +142,7 @@ function Install-Octopus {
|
||||
Write-Color "Error: Failed to download $downloadUrl" "Red"
|
||||
Write-Color $_.Exception.Message "Red"
|
||||
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
||||
exit 1
|
||||
throw "CLI installation failed."
|
||||
}
|
||||
|
||||
# Extract
|
||||
@@ -159,7 +154,7 @@ function Install-Octopus {
|
||||
if (-not (Test-Path $exeSrc)) {
|
||||
Write-Color "Error: $APP.exe not found in archive." "Red"
|
||||
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
||||
exit 1
|
||||
throw "CLI installation failed."
|
||||
}
|
||||
Copy-Item -Path $exeSrc -Destination (Join-Path $INSTALL_DIR "$APP.exe") -Force
|
||||
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
||||
|
||||
在新工单中引用
屏蔽一个用户