|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Tests the PowerShell dependency injection into winget manifests. |
| 4 | +.DESCRIPTION |
| 5 | + Downloads wingetcreate, generates a manifest for an existing package version, |
| 6 | + injects the PowerShell dependency, and validates the result. |
| 7 | +.PARAMETER PackageId |
| 8 | + The package ID to test (default: GitHub.Copilot.Prerelease) |
| 9 | +#> |
| 10 | +param( |
| 11 | + [string]$PackageId = "GitHub.Copilot.Prerelease" |
| 12 | +) |
| 13 | + |
| 14 | +$ErrorActionPreference = "Stop" |
| 15 | + |
| 16 | +# Create temp directory |
| 17 | +$tempDir = Join-Path $env:TEMP "winget-test-$(Get-Random)" |
| 18 | +New-Item -ItemType Directory -Path $tempDir -Force | Out-Null |
| 19 | +Push-Location $tempDir |
| 20 | + |
| 21 | +try { |
| 22 | + Write-Host "Working in: $tempDir" -ForegroundColor Cyan |
| 23 | + |
| 24 | + # Download wingetcreate |
| 25 | + Write-Host "Downloading wingetcreate..." -ForegroundColor Cyan |
| 26 | + curl.exe -JLO https://aka.ms/wingetcreate/latest |
| 27 | + |
| 28 | + # Get the latest version from winget-pkgs to use as a reference |
| 29 | + Write-Host "Fetching existing manifest for $PackageId..." -ForegroundColor Cyan |
| 30 | + .\wingetcreate.exe update $PackageId --out manifests 2>&1 | Out-Null |
| 31 | + |
| 32 | + if (-not (Test-Path manifests)) { |
| 33 | + throw "Failed to generate manifests directory" |
| 34 | + } |
| 35 | + |
| 36 | + # Find and modify the installer manifest |
| 37 | + $installerManifest = Get-ChildItem -Path manifests -Filter "*.installer.yaml" -Recurse | Select-Object -First 1 |
| 38 | + if (-not $installerManifest) { |
| 39 | + throw "Could not find installer manifest" |
| 40 | + } |
| 41 | + |
| 42 | + Write-Host "Found installer manifest: $($installerManifest.FullName)" -ForegroundColor Cyan |
| 43 | + Write-Host "`n--- BEFORE ---" -ForegroundColor Yellow |
| 44 | + Get-Content $installerManifest | Select-Object -First 20 |
| 45 | + |
| 46 | + # Apply the dependency injection (same logic as workflow) |
| 47 | + $content = Get-Content $installerManifest -Raw |
| 48 | + $dependency = @" |
| 49 | +Dependencies: |
| 50 | + PackageDependencies: |
| 51 | + - PackageIdentifier: Microsoft.PowerShell |
| 52 | + MinimumVersion: "7.0.0" |
| 53 | +"@ |
| 54 | + $content = $content -replace '(?m)^Installers:', "$dependency`nInstallers:" |
| 55 | + Set-Content -Path $installerManifest -Value $content -NoNewline |
| 56 | + |
| 57 | + Write-Host "`n--- AFTER ---" -ForegroundColor Green |
| 58 | + Get-Content $installerManifest | Select-Object -First 25 |
| 59 | + |
| 60 | + # Validate the manifest using winget CLI if available |
| 61 | + Write-Host "`n--- VALIDATING ---" -ForegroundColor Cyan |
| 62 | + if (Get-Command winget -ErrorAction SilentlyContinue) { |
| 63 | + winget validate $installerManifest.Directory.FullName |
| 64 | + if ($LASTEXITCODE -eq 0) { |
| 65 | + Write-Host "`n✓ Validation passed!" -ForegroundColor Green |
| 66 | + } else { |
| 67 | + Write-Host "`n✗ Validation failed!" -ForegroundColor Red |
| 68 | + exit 1 |
| 69 | + } |
| 70 | + } else { |
| 71 | + Write-Host "winget CLI not available - skipping validation" -ForegroundColor Yellow |
| 72 | + Write-Host "✓ Dependency injection succeeded (manual review above)" -ForegroundColor Green |
| 73 | + } |
| 74 | +} |
| 75 | +finally { |
| 76 | + Pop-Location |
| 77 | + # Cleanup |
| 78 | + Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue |
| 79 | +} |
0 commit comments