From 62b85d51b0d13eec9a44558381216d152e598823 Mon Sep 17 00:00:00 2001 From: Prajwal Nadig Date: Wed, 22 Jul 2026 13:08:11 +0100 Subject: [PATCH] Fix Windows CI passing when a command fails to launch Invoke-Program used `exit $LastExitCode`, but when a native command fails to launch (e.g. a broken toolchain) no exit code is set, leaving `$LASTEXITCODE` as $null. `exit $null` exits 0, so the container reports success and the step is green despite the failure (like this occurence[1] in swiftlang/swift-package-manager). Reset `$LASTEXITCODE` before each call and fall back to $? when no exit code is produced, so launch failures now fail properly. [1]: https://github.com/swiftlang/swift-package-manager/actions/runs/29766644951/job/88434456907?pr=10308 --- .github/workflows/swift_package_test.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/swift_package_test.yml b/.github/workflows/swift_package_test.yml index 950b6c0c..f99927f2 100644 --- a/.github/workflows/swift_package_test.yml +++ b/.github/workflows/swift_package_test.yml @@ -920,10 +920,17 @@ jobs: # Run the command following `Invoke-Program`. # If that command returns a non-zero exit code, return the same exit code from this script. + # When there is no exit code (e.g. program failed to launch), we fall back to $?. function Invoke-Program($Executable) { + $global:LASTEXITCODE = $null & $Executable @args - if ($LastExitCode -ne 0) { - exit $LastExitCode + $ok = $? + if ($null -eq $LASTEXITCODE) { + if (-not $ok) { + exit 1 + } + } elseif ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE } } Invoke-Program swift --version