feat(release): add Alibaba Cloud OSS distribution (#166)
This commit is contained in:
+154
-3
@@ -11,12 +11,19 @@ $Installer = Join-Path $RepoRoot "install.ps1"
|
||||
$WorkDir = Join-Path ([IO.Path]::GetTempPath()) "penguin-installer-tests-$PID"
|
||||
$OriginalPath = $env:Path
|
||||
$OriginalOs = $env:OS
|
||||
$OriginalDownloadBaseUrl = $env:PENGUIN_DOWNLOAD_BASE_URL
|
||||
$OriginalDownloadFallbackBaseUrl = $env:PENGUIN_DOWNLOAD_FALLBACK_BASE_URL
|
||||
$OriginalDownloadSource = $env:PENGUIN_DOWNLOAD_SOURCE
|
||||
$OriginalArchive = $env:PENGUIN_ARCHIVE
|
||||
$OriginalInstallDir = $env:PENGUIN_INSTALL_DIR
|
||||
$OriginalVersion = $env:PENGUIN_VERSION
|
||||
$Fixture = @{
|
||||
Requests = [Collections.Generic.List[string]]::new()
|
||||
Mode = "canonical"
|
||||
GoodBundle = $null
|
||||
BadInnerBundle = $null
|
||||
LegacyArchive = $null
|
||||
Installer = $Installer
|
||||
}
|
||||
$global:PenguinInstallerFixture = $Fixture
|
||||
|
||||
@@ -53,13 +60,39 @@ function global:Invoke-WebRequest {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$Uri,
|
||||
[Parameter(Mandatory = $true)][string]$OutFile,
|
||||
[switch]$UseBasicParsing
|
||||
[switch]$UseBasicParsing,
|
||||
[int]$TimeoutSec = 0
|
||||
)
|
||||
$f = $global:PenguinInstallerFixture
|
||||
$f.Requests.Add($Uri)
|
||||
if ($f.Mode -eq "404") { throw "fixture 404: $Uri" }
|
||||
if ($f.Mode -eq "network") { throw "fixture network failure: $Uri" }
|
||||
if ($f.Mode -eq "primary-network" -and $Uri -like "https://penguin-harness-releases.oss-cn-beijing.aliyuncs.com/*") {
|
||||
throw "fixture primary network failure"
|
||||
}
|
||||
if ($f.Mode -eq "forced-oss-payload" -and
|
||||
$Uri -like "https://penguin-harness-releases.oss-cn-beijing.aliyuncs.com/*/penguin-*") {
|
||||
throw "fixture forced OSS payload failure"
|
||||
}
|
||||
if ($f.Mode -eq "forwarder-auto-github" -and $Uri -like "*/latest.json") {
|
||||
throw "fixture OSS metadata failure"
|
||||
}
|
||||
switch -Wildcard ($Uri) {
|
||||
"*/latest.json" {
|
||||
if ($f.Mode -eq "forwarder-invalid-metadata") {
|
||||
'{"schemaVersion":1,"tag":"../invalid","releaseBaseUrl":"https://example.invalid"}' |
|
||||
Set-Content -LiteralPath $OutFile -Encoding ascii
|
||||
} else {
|
||||
@{
|
||||
schemaVersion = 1
|
||||
tag = "v0.0.0-test"
|
||||
releaseBaseUrl = "https://penguin-harness-releases.oss-cn-beijing.aliyuncs.com/releases/v0.0.0-test"
|
||||
} | ConvertTo-Json | Set-Content -LiteralPath $OutFile -Encoding ascii
|
||||
}
|
||||
}
|
||||
"*/install.ps1" {
|
||||
Copy-Item -LiteralPath $f.Installer -Destination $OutFile
|
||||
}
|
||||
"*/penguin-win32-x64.zip.sha256" {
|
||||
switch ($f.Mode) {
|
||||
"outer-sha-mismatch" {
|
||||
@@ -94,17 +127,54 @@ function Invoke-OnlineCase(
|
||||
$Arguments = @{ InstallDir = $InstallDir }
|
||||
if ($Version) { $Arguments.Version = $Version }
|
||||
$Succeeded = $true
|
||||
try { & $Installer @Arguments *>&1 | Out-Null } catch { $Succeeded = $false }
|
||||
$Output = @()
|
||||
try { $Output = @(& $Installer @Arguments *>&1) } catch { $Succeeded = $false }
|
||||
Assert-True ($Succeeded -eq $ShouldSucceed) "$Name returned an unexpected result"
|
||||
Assert-True ($Fixture.Requests.Count -eq $ExpectedRequests) `
|
||||
"$Name made $($Fixture.Requests.Count) requests, expected $ExpectedRequests"
|
||||
[PSCustomObject]@{ InstallDir = $InstallDir; Requests = @($Fixture.Requests) }
|
||||
[PSCustomObject]@{ InstallDir = $InstallDir; Requests = @($Fixture.Requests); Output = @($Output) }
|
||||
}
|
||||
|
||||
function Invoke-ForwarderCase(
|
||||
[string]$Name,
|
||||
[string]$Mode,
|
||||
[string]$Source,
|
||||
[int]$ExpectedRequests,
|
||||
[string]$Version = "",
|
||||
[bool]$ShouldSucceed = $true
|
||||
) {
|
||||
$Fixture.Mode = $Mode
|
||||
$Fixture.Requests.Clear()
|
||||
$InstallDir = Join-Path $WorkDir "$Name-install"
|
||||
if ($Version) {
|
||||
Remove-Item Env:\PENGUIN_ARCHIVE -ErrorAction SilentlyContinue
|
||||
$env:PENGUIN_VERSION = $Version
|
||||
} else {
|
||||
$env:PENGUIN_ARCHIVE = $Fixture.GoodBundle
|
||||
Remove-Item Env:\PENGUIN_VERSION -ErrorAction SilentlyContinue
|
||||
}
|
||||
$env:PENGUIN_INSTALL_DIR = $InstallDir
|
||||
$env:PENGUIN_DOWNLOAD_SOURCE = $Source
|
||||
Remove-Item Env:\PENGUIN_DOWNLOAD_BASE_URL, Env:\PENGUIN_DOWNLOAD_FALLBACK_BASE_URL -ErrorAction SilentlyContinue
|
||||
$Forwarder = Join-Path $RepoRoot "packages\landing\public\install.ps1"
|
||||
$Output = @()
|
||||
$Succeeded = $true
|
||||
try { $Output = @(& $Forwarder *>&1) } catch { $Succeeded = $false }
|
||||
Assert-True ($Succeeded -eq $ShouldSucceed) "$Name returned an unexpected result"
|
||||
Assert-True ($Fixture.Requests.Count -eq $ExpectedRequests) `
|
||||
"$Name made $($Fixture.Requests.Count) requests, expected $ExpectedRequests"
|
||||
Assert-True (-not (($Output | Out-String) -match 'aliyuncs\.com')) `
|
||||
"$Name exposed the OSS URL in normal output"
|
||||
[PSCustomObject]@{ InstallDir = $InstallDir; Requests = @($Fixture.Requests); Output = @($Output) }
|
||||
}
|
||||
|
||||
try {
|
||||
New-Item -ItemType Directory -Path $WorkDir -Force | Out-Null
|
||||
# Keep the fixture tests away from the runner's user registry Path.
|
||||
$env:OS = "PenguinInstallerFixtureTest"
|
||||
Remove-Item Env:\PENGUIN_DOWNLOAD_BASE_URL, Env:\PENGUIN_DOWNLOAD_FALLBACK_BASE_URL, `
|
||||
Env:\PENGUIN_DOWNLOAD_SOURCE, Env:\PENGUIN_ARCHIVE, Env:\PENGUIN_INSTALL_DIR, `
|
||||
Env:\PENGUIN_VERSION -ErrorAction SilentlyContinue
|
||||
|
||||
# --- Offline program archive: good install, then a failing upgrade must roll back. ---
|
||||
$InstallDir = Join-Path $WorkDir "offline-installed"
|
||||
@@ -171,6 +241,57 @@ try {
|
||||
"canonical did not request the canonical bundle"
|
||||
$Version = & (Join-Path $canonical.InstallDir "bin\penguin.cmd") --version
|
||||
Assert-True ($Version -eq "fixture-old") "canonical bundle was not installed"
|
||||
|
||||
$env:PENGUIN_DOWNLOAD_BASE_URL = "https://penguin-harness-releases.oss-cn-beijing.aliyuncs.com/releases/v0.0.0-test"
|
||||
$override = Invoke-OnlineCase "download-base-override" "canonical" "" $true 2
|
||||
Assert-True ($override.Requests[0] -eq "https://penguin-harness-releases.oss-cn-beijing.aliyuncs.com/releases/v0.0.0-test/penguin-win32-x64.zip") `
|
||||
"download base override did not request the configured asset directory"
|
||||
Assert-True (($override.Output | Out-String) -match 'OSS mirror') `
|
||||
"download base override did not identify the OSS mirror"
|
||||
Assert-True (-not (($override.Output | Out-String) -match 'aliyuncs\.com')) `
|
||||
"download base override exposed the OSS URL in normal output"
|
||||
|
||||
$env:PENGUIN_DOWNLOAD_FALLBACK_BASE_URL = "https://github.com/Prism-Shadow/penguin-harness/releases/download/v0.0.0-test"
|
||||
$fallback = Invoke-OnlineCase "download-fallback" "primary-network" "" $true 3
|
||||
Assert-True ($fallback.Requests[0] -like "https://penguin-harness-releases.oss-cn-beijing.aliyuncs.com/*") `
|
||||
"download fallback did not try the primary source first"
|
||||
Assert-True ($fallback.Requests[1] -like "https://github.com/*/penguin-win32-x64.zip") `
|
||||
"download fallback did not use the same-version GitHub source"
|
||||
Assert-True (-not (($fallback.Output | Out-String) -match 'aliyuncs\.com')) `
|
||||
"download fallback exposed the OSS URL in normal output"
|
||||
Remove-Item Env:\PENGUIN_DOWNLOAD_FALLBACK_BASE_URL
|
||||
Remove-Item Env:\PENGUIN_DOWNLOAD_BASE_URL
|
||||
|
||||
$forwarderOss = Invoke-ForwarderCase "forwarder-oss" "forwarder-oss" "auto" 2
|
||||
Assert-True ($forwarderOss.Requests[0] -like "*/latest.json") `
|
||||
"OSS forwarder did not request release metadata first"
|
||||
Assert-True ($forwarderOss.Requests[1] -like "*/releases/v0.0.0-test/install.ps1") `
|
||||
"OSS forwarder did not request the versioned installer"
|
||||
|
||||
$forwarderGitHub = Invoke-ForwarderCase "forwarder-auto-github" "forwarder-auto-github" "auto" 2
|
||||
Assert-True ($forwarderGitHub.Requests[1] -like "https://github.com/*/releases/latest/download/install.ps1") `
|
||||
"forwarder did not fall back to the GitHub installer"
|
||||
|
||||
$invalidMetadata = Invoke-ForwarderCase "forwarder-invalid-metadata" "forwarder-invalid-metadata" "auto" 2
|
||||
Assert-True ($invalidMetadata.Requests[1] -like "https://github.com/*/releases/latest/download/install.ps1") `
|
||||
"invalid OSS metadata did not fall back to the GitHub installer"
|
||||
|
||||
$forcedGitHub = Invoke-ForwarderCase "forwarder-github" "canonical" "github" 1
|
||||
Assert-True ($forcedGitHub.Requests[0] -like "https://github.com/*/releases/latest/download/install.ps1") `
|
||||
"forced GitHub mode did not request the GitHub installer"
|
||||
|
||||
$forcedOss = Invoke-ForwarderCase "forwarder-forced-oss-no-fallback" `
|
||||
"forced-oss-payload" "oss" 2 "v0.0.0-test" $false
|
||||
Assert-True (-not (($forcedOss.Requests | Out-String) -match 'github\.com')) `
|
||||
"forced OSS mode unexpectedly fell back to GitHub"
|
||||
|
||||
$pinnedForwarder = Invoke-ForwarderCase "forwarder-pinned" "canonical" "auto" 3 "v0.0.0-test"
|
||||
Assert-True ($pinnedForwarder.Requests[0] -like "*/releases/v0.0.0-test/install.ps1") `
|
||||
"pinned forwarder did not request the versioned installer"
|
||||
Assert-True ($pinnedForwarder.Requests[1] -like "*/releases/v0.0.0-test/penguin-win32-x64.zip") `
|
||||
"pinned installer did not keep the selected release version"
|
||||
Remove-Item Env:\PENGUIN_ARCHIVE, Env:\PENGUIN_INSTALL_DIR, Env:\PENGUIN_DOWNLOAD_SOURCE, Env:\PENGUIN_VERSION -ErrorAction SilentlyContinue
|
||||
|
||||
Invoke-OnlineCase "outer-mismatch" "outer-sha-mismatch" "" $false 2 | Out-Null
|
||||
Invoke-OnlineCase "inner-mismatch" "inner-sha-mismatch" "" $false 2 | Out-Null
|
||||
Invoke-OnlineCase "latest-404" "404" "" $false 1 | Out-Null
|
||||
@@ -183,6 +304,36 @@ try {
|
||||
} finally {
|
||||
$env:Path = $OriginalPath
|
||||
$env:OS = $OriginalOs
|
||||
if ($null -eq $OriginalDownloadBaseUrl) {
|
||||
Remove-Item Env:\PENGUIN_DOWNLOAD_BASE_URL -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$env:PENGUIN_DOWNLOAD_BASE_URL = $OriginalDownloadBaseUrl
|
||||
}
|
||||
if ($null -eq $OriginalDownloadFallbackBaseUrl) {
|
||||
Remove-Item Env:\PENGUIN_DOWNLOAD_FALLBACK_BASE_URL -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$env:PENGUIN_DOWNLOAD_FALLBACK_BASE_URL = $OriginalDownloadFallbackBaseUrl
|
||||
}
|
||||
if ($null -eq $OriginalDownloadSource) {
|
||||
Remove-Item Env:\PENGUIN_DOWNLOAD_SOURCE -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$env:PENGUIN_DOWNLOAD_SOURCE = $OriginalDownloadSource
|
||||
}
|
||||
if ($null -eq $OriginalArchive) {
|
||||
Remove-Item Env:\PENGUIN_ARCHIVE -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$env:PENGUIN_ARCHIVE = $OriginalArchive
|
||||
}
|
||||
if ($null -eq $OriginalInstallDir) {
|
||||
Remove-Item Env:\PENGUIN_INSTALL_DIR -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$env:PENGUIN_INSTALL_DIR = $OriginalInstallDir
|
||||
}
|
||||
if ($null -eq $OriginalVersion) {
|
||||
Remove-Item Env:\PENGUIN_VERSION -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$env:PENGUIN_VERSION = $OriginalVersion
|
||||
}
|
||||
Remove-Item Function:\Invoke-WebRequest -ErrorAction SilentlyContinue
|
||||
Remove-Variable PenguinInstallerFixture -Scope Global -ErrorAction SilentlyContinue
|
||||
if (Test-Path -LiteralPath $WorkDir) { Remove-Item -LiteralPath $WorkDir -Recurse -Force }
|
||||
|
||||
Reference in New Issue
Block a user