From 880c8902b254c3c3ae458f3b206db0f6536e2a6a Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Fri, 20 Sep 2024 16:08:35 -0700 Subject: [PATCH] (maint) Abort testing if test packages don't pack This adds logic to the Invoke-Tests file to abort testing if packages fail to pack. This is to improve the developer experience by not allowing tests to run without the full set of test packages. --- Invoke-Tests.ps1 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Invoke-Tests.ps1 b/Invoke-Tests.ps1 index 9fe215b79..e6d6f1887 100644 --- a/Invoke-Tests.ps1 +++ b/Invoke-Tests.ps1 @@ -57,10 +57,28 @@ if (-not (Test-Path "$TestPath/packages") -or -not $SkipPackaging) { $nuspecs = Get-ChildItem -Path $PSScriptRoot/src/chocolatey.tests.integration, $PSScriptRoot/tests/packages -Recurse -Include *.nuspec | Where-Object FullName -NotMatch 'bin' Get-ChildItem -Path $PSScriptRoot/tests/packages -Recurse -Include *.nupkg | Copy-Item -Destination "$TestPath/packages" - foreach ($file in $nuspecs) { - Write-Host "Packaging $file" + $packFailures = foreach ($file in $nuspecs) { # Include allow-unofficial in case an unofficial Chocolatey has been installed globally for testing - $null = choco pack $file.FullName --out "$TestPath/packages" --allow-unofficial + $packOutput = choco pack $file.FullName --out "$TestPath/packages" --allow-unofficial + if ($LASTEXITCODE -ne 0) { + [pscustomobject]@{ + Package = $file.FullName + ExitCode = $LASTEXITCODE + Output = $packOutput + } + Write-Warning "Failed to pack $file" + } + else { + Write-Host "Packaged $file" + } + } + + if ($null -ne $packFailures) { + foreach ($failure in $packFailures) { + Write-Warning "$($failure.Package) failed to pack with exit code: $($failure.ExitCode)" + $failure.Output | Write-Warning + } + throw "$($packFailures.Count) packages failed to pack." } }