|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Verify that a signed Aspire CLI archive produces a working binary. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + This script: |
| 7 | + 1. Cleans ~/.aspire to ensure no stale state |
| 8 | + 2. Extracts the CLI archive to a temp location |
| 9 | + 3. Runs 'aspire --version' to validate the binary executes |
| 10 | + 4. Runs 'aspire new aspire-starter' to test bundle self-extraction + project creation |
| 11 | + 5. Cleans up temp directories |
| 12 | +
|
| 13 | +.PARAMETER ArchivePath |
| 14 | + Path to the CLI archive (.zip or .tar.gz) |
| 15 | +
|
| 16 | +.EXAMPLE |
| 17 | + .\verify-cli-archive.ps1 -ArchivePath "artifacts\packages\Release\Shipping\aspire-cli-win-x64-10.0.0.zip" |
| 18 | +#> |
| 19 | + |
| 20 | +param( |
| 21 | + [Parameter(Mandatory = $true, Position = 0)] |
| 22 | + [string]$ArchivePath |
| 23 | +) |
| 24 | + |
| 25 | +$ErrorActionPreference = 'Stop' |
| 26 | + |
| 27 | +function Write-Step { param([string]$msg) Write-Host "▶ $msg" -ForegroundColor Cyan } |
| 28 | +function Write-Ok { param([string]$msg) Write-Host "✅ $msg" -ForegroundColor Green } |
| 29 | +function Write-Err { param([string]$msg) Write-Host "❌ $msg" -ForegroundColor Red } |
| 30 | + |
| 31 | +$verifyTmpDir = $null |
| 32 | +$aspireBackup = $null |
| 33 | + |
| 34 | +function Invoke-Cleanup { |
| 35 | + if ($verifyTmpDir -and (Test-Path $verifyTmpDir)) { |
| 36 | + Write-Step "Cleaning up temp directory: $verifyTmpDir" |
| 37 | + Remove-Item -Recurse -Force $verifyTmpDir -ErrorAction SilentlyContinue |
| 38 | + } |
| 39 | + # Restore ~/.aspire if we backed it up |
| 40 | + $aspireDir = Join-Path $env:USERPROFILE ".aspire" |
| 41 | + if ($aspireBackup -and (Test-Path $aspireBackup)) { |
| 42 | + if (Test-Path $aspireDir) { |
| 43 | + Remove-Item -Recurse -Force $aspireDir -ErrorAction SilentlyContinue |
| 44 | + } |
| 45 | + Move-Item $aspireBackup $aspireDir |
| 46 | + Write-Step "Restored original ~/.aspire" |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +try { |
| 51 | + # Validate archive exists |
| 52 | + if (-not (Test-Path $ArchivePath)) { |
| 53 | + Write-Err "Archive not found: $ArchivePath" |
| 54 | + exit 1 |
| 55 | + } |
| 56 | + |
| 57 | + $ArchivePath = (Resolve-Path $ArchivePath).Path |
| 58 | + |
| 59 | + # Suppress interactive prompts and telemetry |
| 60 | + $env:ASPIRE_CLI_TELEMETRY_OPTOUT = "true" |
| 61 | + $env:DOTNET_CLI_TELEMETRY_OPTOUT = "true" |
| 62 | + $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true" |
| 63 | + $env:DOTNET_GENERATE_ASPNET_CERTIFICATE = "false" |
| 64 | + |
| 65 | + Write-Host "" |
| 66 | + Write-Host "==========================================" |
| 67 | + Write-Host " Aspire CLI Archive Verification" |
| 68 | + Write-Host "==========================================" |
| 69 | + Write-Host " Archive: $ArchivePath" |
| 70 | + Write-Host "==========================================" |
| 71 | + Write-Host "" |
| 72 | + |
| 73 | + # Step 1: Back up and clean ~/.aspire |
| 74 | + Write-Step "Cleaning ~/.aspire state..." |
| 75 | + $aspireDir = Join-Path $env:USERPROFILE ".aspire" |
| 76 | + if (Test-Path $aspireDir) { |
| 77 | + $aspireBackup = Join-Path ([System.IO.Path]::GetTempPath()) "aspire-backup-$([System.IO.Path]::GetRandomFileName())" |
| 78 | + Move-Item $aspireDir $aspireBackup |
| 79 | + Write-Step "Backed up existing ~/.aspire to $aspireBackup" |
| 80 | + } |
| 81 | + Write-Ok "Clean ~/.aspire state" |
| 82 | + |
| 83 | + # Step 2: Extract the archive |
| 84 | + $verifyTmpDir = Join-Path ([System.IO.Path]::GetTempPath()) "aspire-verify-$([System.IO.Path]::GetRandomFileName())" |
| 85 | + $extractDir = Join-Path $verifyTmpDir "cli" |
| 86 | + New-Item -ItemType Directory -Path $extractDir -Force | Out-Null |
| 87 | + |
| 88 | + Write-Step "Extracting archive to $extractDir..." |
| 89 | + if ($ArchivePath.EndsWith(".zip")) { |
| 90 | + Expand-Archive -Path $ArchivePath -DestinationPath $extractDir |
| 91 | + } |
| 92 | + elseif ($ArchivePath.EndsWith(".tar.gz")) { |
| 93 | + tar -xzf $ArchivePath -C $extractDir |
| 94 | + if ($LASTEXITCODE -ne 0) { |
| 95 | + Write-Err "Failed to extract tar.gz archive" |
| 96 | + exit 1 |
| 97 | + } |
| 98 | + } |
| 99 | + else { |
| 100 | + Write-Err "Unsupported archive format: $ArchivePath (expected .zip or .tar.gz)" |
| 101 | + exit 1 |
| 102 | + } |
| 103 | + |
| 104 | + # Find the aspire binary |
| 105 | + $aspireBin = Join-Path $extractDir "aspire.exe" |
| 106 | + if (-not (Test-Path $aspireBin)) { |
| 107 | + $aspireBin = Join-Path $extractDir "aspire" |
| 108 | + if (-not (Test-Path $aspireBin)) { |
| 109 | + Write-Err "Could not find 'aspire' binary in extracted archive." |
| 110 | + Get-ChildItem $extractDir | Format-Table |
| 111 | + exit 1 |
| 112 | + } |
| 113 | + } |
| 114 | + Write-Ok "Extracted CLI binary: $aspireBin" |
| 115 | + |
| 116 | + # Install to ~/.aspire/bin so self-extraction works correctly |
| 117 | + Write-Step "Installing CLI to ~/.aspire/bin..." |
| 118 | + $aspireDir = Join-Path $env:USERPROFILE ".aspire" |
| 119 | + $aspireBinDir = Join-Path $aspireDir "bin" |
| 120 | + New-Item -ItemType Directory -Path $aspireBinDir -Force | Out-Null |
| 121 | + Copy-Item $aspireBin (Join-Path $aspireBinDir (Split-Path $aspireBin -Leaf)) |
| 122 | + $aspireBin = Join-Path $aspireBinDir (Split-Path $aspireBin -Leaf) |
| 123 | + $env:PATH = "$aspireBinDir;$env:PATH" |
| 124 | + Write-Ok "CLI installed to ~/.aspire/bin" |
| 125 | + |
| 126 | + # Step 3: Verify aspire --version |
| 127 | + Write-Step "Running 'aspire --version'..." |
| 128 | + $versionOutput = & $aspireBin --version 2>&1 |
| 129 | + if ($LASTEXITCODE -ne 0) { |
| 130 | + Write-Err "'aspire --version' failed with exit code $LASTEXITCODE" |
| 131 | + Write-Host "Output: $versionOutput" |
| 132 | + exit 1 |
| 133 | + } |
| 134 | + Write-Host " Version: $versionOutput" |
| 135 | + Write-Ok "'aspire --version' succeeded" |
| 136 | + |
| 137 | + # Step 4: Create a new project with aspire new |
| 138 | + # This exercises bundle self-extraction and aspire-managed (template search + download + scaffolding) |
| 139 | + $projectDir = Join-Path $verifyTmpDir "VerifyApp" |
| 140 | + New-Item -ItemType Directory -Path $projectDir -Force | Out-Null |
| 141 | + |
| 142 | + Write-Step "Running 'aspire new aspire-starter --name VerifyApp --output $projectDir --non-interactive --nologo'..." |
| 143 | + & $aspireBin new aspire-starter --name VerifyApp --output $projectDir --non-interactive --nologo 2>&1 | Write-Host |
| 144 | + if ($LASTEXITCODE -ne 0) { |
| 145 | + Write-Err "'aspire new' failed with exit code $LASTEXITCODE" |
| 146 | + exit 1 |
| 147 | + } |
| 148 | + |
| 149 | + # Verify the project was created |
| 150 | + $appHostDir = Join-Path $projectDir "VerifyApp.AppHost" |
| 151 | + if (-not (Test-Path $appHostDir)) { |
| 152 | + Write-Err "Expected project directory 'VerifyApp.AppHost' not found after 'aspire new'" |
| 153 | + Get-ChildItem $projectDir | Format-Table |
| 154 | + exit 1 |
| 155 | + } |
| 156 | + Write-Ok "'aspire new' created project successfully" |
| 157 | + |
| 158 | + Write-Host "" |
| 159 | + Write-Host "==========================================" |
| 160 | + Write-Host " All verification checks passed!" -ForegroundColor Green |
| 161 | + Write-Host "==========================================" |
| 162 | + Write-Host "" |
| 163 | +} |
| 164 | +catch { |
| 165 | + Write-Err "Verification failed: $_" |
| 166 | + Write-Host $_.ScriptStackTrace |
| 167 | + exit 1 |
| 168 | +} |
| 169 | +finally { |
| 170 | + Invoke-Cleanup |
| 171 | +} |
0 commit comments