Skip to content

Commit 62b85d5

Browse files
committed
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
1 parent 497d9ab commit 62b85d5

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

.github/workflows/swift_package_test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,17 @@ jobs:
920920
921921
# Run the command following `Invoke-Program`.
922922
# If that command returns a non-zero exit code, return the same exit code from this script.
923+
# When there is no exit code (e.g. program failed to launch), we fall back to $?.
923924
function Invoke-Program($Executable) {
925+
$global:LASTEXITCODE = $null
924926
& $Executable @args
925-
if ($LastExitCode -ne 0) {
926-
exit $LastExitCode
927+
$ok = $?
928+
if ($null -eq $LASTEXITCODE) {
929+
if (-not $ok) {
930+
exit 1
931+
}
932+
} elseif ($LASTEXITCODE -ne 0) {
933+
exit $LASTEXITCODE
927934
}
928935
}
929936
Invoke-Program swift --version

0 commit comments

Comments
 (0)