Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set pwsh PSNativeCommandUseErrorActionPreference #8900

Closed
10 tasks
vaind opened this issue Nov 27, 2023 · 4 comments
Closed
10 tasks

Set pwsh PSNativeCommandUseErrorActionPreference #8900

vaind opened this issue Nov 27, 2023 · 4 comments

Comments

@vaind
Copy link

vaind commented Nov 27, 2023

Description

There have been multiple issues asking to change the behavior of pwsh to respect executables exit codes. Since pwsh v7.3, there's a new setting to do exactly what other shells do: PSNativeCommandUseErrorActionPreference. This has become mainstream in pwsh v7.4: https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.4#psnativecommanderroractionpreference

One of the issues that this has come up before:

Depends on updating pwsh: #8847

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 20.04
  • Ubuntu 22.04
  • macOS 11
  • macOS 12
  • macOS 13
  • Windows Server 2019
  • Windows Server 2022

Image version and build link

https://github.com/getsentry/sentry-unity/actions/runs/6999733486/job/19047630987

Is it regression?

no

Expected behavior

(Native) executable errors should propagate and fail the step, the same way they would on other shells.

Docs already indicate they should: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference

Actual behavior

Errors let the step script continue as if nothing has happened, leading to an incorrect CI execution.

This partially works if there's a single command, because that one will get its exit code propagated

Repro steps

create a multiline run step, the first shell command failing, the second one passing (zero exit code)

@ilia-shipitsin
Copy link
Contributor

shouldn't it be done on Windows (or Powershell) level ?
we do not enforce any non default Powershell setting.

@vaind
Copy link
Author

vaind commented Nov 27, 2023

shouldn't it be done on Windows (or Powershell) level ?

technically, it's a breaking change in a wide world, that's why it's a new opt-in setting.
On the other hand, AFAIU, this setting will default to enabled on PWSH 7.4 so maybe this issue is not really necessary as a standalone one, because the change is covered by the issue requesting an update of pwsh.

we do not enforce any non default Powershell setting.

That's not entirely correct, see docs:

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
Fail-fast behavior when possible. For pwsh and powershell built-in shell, we will prepend $ErrorActionPreference = 'stop' to script contents.

@sergei-pyshnoi
Copy link
Contributor

Hello @vaind . Unfortunately we cannot enable this feature because current installed PowerShell version (7.2.16) doesn`t support those.

Enable-ExperimentalFeature PSNativeCommandErrorActionPreference
Enable-ExperimentalFeature: No experimental feature was found that matched the name 'PSNativeCommandErrorActionPreference'.

But, as you say, this setting will default to enabled on Powershell 7.4 . I am closing this issue for now, but if you have additional questions, feel free to ask.

@oblivioncth
Copy link

It seems that the setting ended up being defaulted to "false", not "true", so this issue is still valid (at least as of pwsh 7.4.5).

IMO it makes sense to force PSNativeCommandUseErrorActionPreference to not only unify behavior with unix shells, but also to match the clear fail-fast behavior intention that is mentioned in the docs linked by @vaind:

Fail-fast behavior when possible. For pwsh and powershell built-in shell, we will prepend $ErrorActionPreference = 'stop' to script contents.

Which could now of course read:

Fail-fast behavior when possible. For pwsh and powershell built-in shell, we will prepend $ErrorActionPreference = 'stop' and $PSNativeCommandUseErrorActionPreference = $true to script contents.

This behavior seems intuitive in the context of CI/CD, especially since again, bash and sh already function this way when used through GitHub Actions as shown in the above documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants