Skip to content

Conversation

bnbarham
Copy link
Contributor

windows_build_command was prefixed with a Invoke-Program to ensure we catch errors, but this then misses multiline commands. Move Invoke-Program up into the default command and then assume that it is passed if a non-default command is used.

Note that $ErrorActionPreference = 'Stop' is not an option here - it only stops for cmdlets, not native commands.
$PSNativeCommandUseErrorActionPreference = $true allows stopping on native commands too, but that was only introduced in PowerShell 7.3. windowsservercore-ltsc2022 has 5.1 by default (though we could install a newer if we wanted to).

Update PR testing in this repo to use Invoke-Program to then actually catch failures.

`windows_build_command` was prefixed with a `Invoke-Program` to ensure
we catch errors, but this then misses multiline commands. Move
`Invoke-Program` up into the default command and then assume that it is
passed if a non-default command is used.

Note that `$ErrorActionPreference = 'Stop'` is not an option here - it
only stops for cmdlets, not native commands.
`$PSNativeCommandUseErrorActionPreference = $true` allows stopping on
native commands too, but that was only introduced in PowerShell 7.3.
windowsservercore-ltsc2022 has 5.1 by default (though we could install a
newer if we wanted to).

Update PR testing in this repo to use `Invoke-Program` to then actually
catch failures.
@bnbarham bnbarham requested a review from a team as a code owner August 20, 2025 00:33
@@ -450,7 +450,7 @@ jobs:
Invoke-Program swift test --version
Invoke-Program cd $Source
${{ inputs.windows_pre_build_command }}
Invoke-Program ${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also leave this in, I am slightly concerned that Invoke-Program isn't being used in downstream overrides today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we should prefix it with Invoke-Program. Otherwise, you might learn that the command fails if you only have a single one in your windows_build_commands and are then surprised that this behavior doesn’t hold up when you add a second command to the script.

Instead, what I would suggest is that we go through the existing use cases of this workflow with windows_build_command and fix them. There’s only a handful and many of them are forks: https://github.com/search?q=swiftlang%2Fgithub-workflows%2F.github%2Fworkflows%2Fswift_package_test.yml%40main+windows_build_command&type=code

Copy link
Contributor Author

@bnbarham bnbarham Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is why I removed it. I'll go through them (I learned you can add NOT is:fork by the way)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but we should fix all existing innovations of this workflow to use Invoke-Program.

@@ -450,7 +450,7 @@ jobs:
Invoke-Program swift test --version
Invoke-Program cd $Source
${{ inputs.windows_pre_build_command }}
Invoke-Program ${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we should prefix it with Invoke-Program. Otherwise, you might learn that the command fails if you only have a single one in your windows_build_commands and are then surprised that this behavior doesn’t hold up when you add a second command to the script.

Instead, what I would suggest is that we go through the existing use cases of this workflow with windows_build_command and fix them. There’s only a handful and many of them are forks: https://github.com/search?q=swiftlang%2Fgithub-workflows%2F.github%2Fworkflows%2Fswift_package_test.yml%40main+windows_build_command&type=code

bnbarham added a commit to bnbarham/swift-syntax that referenced this pull request Aug 21, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
bnbarham added a commit to bnbarham/swift-build that referenced this pull request Aug 21, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
bnbarham added a commit to bnbarham/vscode-swift that referenced this pull request Aug 21, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
bnbarham added a commit to bnbarham/swift-foundation-icu that referenced this pull request Aug 21, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
bnbarham added a commit to bnbarham/swift-format that referenced this pull request Aug 21, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
bnbarham added a commit to bnbarham/swift-toolchain-sqlite that referenced this pull request Aug 21, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
bnbarham added a commit to bnbarham/vscode-swift that referenced this pull request Aug 22, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
plemarquand pushed a commit to swiftlang/vscode-swift that referenced this pull request Aug 22, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
bnbarham added a commit to swiftlang/swift-build that referenced this pull request Aug 22, 2025
Windows does not stop scripts when native commands exit with non-zero.
Instead, their exit status has to be checked manually. This can be done
through an `Invoke-Program` function that is added to the script running
`windows_build_command`, which also previously prefixed the given
command. This is changing in
swiftlang/github-workflows#154 since it doesn't
help with multi-line commands - update our modified
`windows_build_command` to use `Invoke-Program` instead.
@ahoppen ahoppen merged commit d3c64be into swiftlang:main Aug 25, 2025
67 checks passed
@bnbarham bnbarham deleted the error-on-failure branch August 25, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants