Skip to content

ci: update pwsh to use custom shell that fails-fast#32672

Closed
m3dwards wants to merge 1 commit intobitcoin:masterfrom
m3dwards:250603-pwsh-fail-fast
Closed

ci: update pwsh to use custom shell that fails-fast#32672
m3dwards wants to merge 1 commit intobitcoin:masterfrom
m3dwards:250603-pwsh-fail-fast

Conversation

@m3dwards
Copy link
Contributor

@m3dwards m3dwards commented Jun 3, 2025

Github by default sets fail fast behaviour on pswh shell which means that if any powershell cmdlet fails the script will stop and exit. The problem is that this behaviour doesn't apply when calling native executables, it only applies to powershell cmdlets.

I think the safest thing is to whenever we use pwsh to enable $PSNativeCommandUseErrorActionPreference = $true which will also fail calling any exe that returns a non-zero exit code.

Technically the step Adjust paths in test/config.ini only uses cmdlets so this step will not benefit from this change but I feel like it's good practice to still enable this feature in case this script gets modified in the future to call an exe.

Here is a CI run that has a script that fails silently (look at Windows Native, VS 2022 -> Get tool information): https://github.com/m3dwards/bitcoin/actions/runs/15415032095/job/43375709475
And with this change applied, the script correctly fails: https://github.com/m3dwards/bitcoin/actions/runs/15416585565/job/43380685364

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 3, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32672.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept NACK fanquake
Concept ACK hodlinator, hebasto, davidgumberg

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #34548 (ci: Add and use ci-windows-cross.py helper by maflcko)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fanquake
Copy link
Member

fanquake commented Jul 2, 2025

cc @hebasto @hodlinator @davidgumberg for Concept ACK / NACK.

@hodlinator
Copy link
Contributor

Concept ACK (but my PowerShell skill is 0).

@fanquake you are currently registered as a N-A-C-K.

@hebasto
Copy link
Member

hebasto commented Jul 3, 2025

Concept ACK.

Defining a new custom job.defaults.run.shell for all Windows jobs allows us to revert f861919 and use the same shell across all steps. This is especially convenient for reproducing failures locally.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Left a couple of notes regarding the current implementation:

  1. The output in the "Get tool information" step has changed:
--- old	2025-07-03 13:37:57.062194420 +0100
+++ new	2025-07-03 13:35:57.800242845 +0100
@@ -1,3 +1,15 @@
+
+Name                           Value
+----                           -----
+PSVersion                      7.4.10
+PSEdition                      Core
+GitCommitId                    7.4.10
+OS                             Microsoft Windows 10.0.20348
+Platform                       Win32NT
+PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
+PSRemotingProtocolVersion      2.3
+SerializationVersion           1.1.0.1
+WSManStackVersion              3.0
 cmake version 3.31.6
 
 CMake suite maintained and supported by Kitware (kitware.com/cmake).
  1. The exit code is not propagated to the action's status.

@m3dwards
Copy link
Contributor Author

m3dwards commented Jul 4, 2025

  1. The output in the "Get tool information" step has changed:

I just added this as a nice to have but happy to remove.

2. The exit code is not propagated to the action's status.

Unfortunately I think this is just how it works. When there is a failure it will always use code 1. Without having to write code that checks error codes and returns those codes each time we call a native executable I don't think it's possible to have the same error code.

@maflcko
Copy link
Member

maflcko commented Jul 4, 2025

This is especially convenient for reproducing failures locally.

Just a general note on CI reproducibility: My recommendation would be to put as little code into vendor-specific locked-in yaml files and instead place CI code into vendor-agnostic scripts, so that they can be re-used outside of that vendor.

I understand that it is nice to have the CI log split into sections, but this should also be possible with a script that allows several entry points: ./ci.py install; ./ci.py build; ./ci.py test; (or similar)

Just an unrelated general note. Anything is fine here and it is probably best to leave the decisions to the Windows devs here.

@m3dwards
Copy link
Contributor Author

m3dwards commented Jul 4, 2025

After reading @maflcko's comment (which I agree with) and speaking with @hebasto offline I think it would be best that we change this to use powershell for all run steps on Windows jobs and look at condensing steps down into one or more scripts to aid in local reproducibility. As it stands, for someone to reproduce these steps locally they would have to jump between two shells. As I understand it, the change to use bash on windows was for the nicer fail fast behaviour but if we can get that in powershell now we should probably use the more native windows shell.

Marking as draft for now until I rework.

@m3dwards m3dwards marked this pull request as draft July 4, 2025 09:30
@maflcko
Copy link
Member

maflcko commented Jul 4, 2025

As I understand it, the change to use bash on windows was for the nicer fail fast behaviour but if we can get that in powershell now we should probably use the more native windows shell.

bash is also easier for non-windows devs to read and modify, so an alternative would also be python or rust as the ci runner script, but no strong opinion, I'd say anything is fine here.

@m3dwards
Copy link
Contributor Author

m3dwards commented Jul 4, 2025

@hebasto is there any reason we need Powershell at all? Can we just use bash (or another language) everywhere?

@hebasto
Copy link
Member

hebasto commented Jan 19, 2026

@hebasto is there any reason we need Powershell at all?

In my opinion, it is convenient to be able to reproduce CI commands locally without needing to install additional tools.

Can we just use bash (or another language) everywhere?

There are no technical obstacles to doing so.

Github Actions does set ErrorActionPreference to Stop but this does not
apply when calling native executables. Use this custom shell that will
fail fast when any command fails.
@davidgumberg
Copy link
Contributor

I think it would be best that we change this to use powershell for all run steps on Windows jobs and look at condensing steps down into one or more scripts to aid in local reproducibility. As it stands, for someone to reproduce these steps locally they would have to jump between two shells. As I understand it, the change to use bash on windows was for the nicer fail fast behaviour but if we can get that in powershell now we should probably use the more native windows shell.

Concept ACK, seems reasonable to write the script in powershell and invoke it in the vendor ci.yml. I think the script should be moved out of the vendor-specific ci.yml as suggested by @maflcko.

Given that the script is mostly sequential command invocation, I'm not sure if there's much benefit from rewriting it in python or another language, and agree with @hebasto that for reproducibility it would be nice to have it in powershell. If there is a good reason to not have the CI script in powershell, maybe it would suffice to have a powershell script that does something like winget install Python.Python.3 and runs a python script.

@maflcko
Copy link
Member

maflcko commented Jan 28, 2026

Well, python is required and already installed on the GHA hosts, so the local runner will have to have it (pre-)installed in some way or another. I think it is fine to ignore the "install" part and only extract the "run" part, but anything is fine here. I'll likely not going to review this pull, so I don't want to give too much feedback 😅

@maflcko
Copy link
Member

maflcko commented Feb 4, 2026

I've implemented the concept of my idea in #34500

@maflcko
Copy link
Member

maflcko commented Feb 10, 2026

Did the rest in #34548

This leaves only:

      - &SET_UP_VS
        name: Set up VS Developer Prompt
        shell: pwsh -Command "$PSVersionTable; $PSNativeCommandUseErrorActionPreference = $true; $ErrorActionPreference = 'Stop'; & '{0}'"
        run: |
          $vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
          $installationPath = & $vswherePath -latest -property installationPath
          & "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -arch=x64 -no_logo && set" | foreach-object {
            $name, $value = $_ -split '=', 2
            echo "$name=$value" >> $env:GITHUB_ENV
          }

      - name: Get tool information
        shell: pwsh
        run: |
          cmake -version | Tee-Object -FilePath "cmake_version"
          Write-Output "---" 
          msbuild -version | Tee-Object -FilePath "msbuild_version"
          $env:VCToolsVersion | Tee-Object -FilePath "toolset_version"
          py -3 --version
          Write-Host "PowerShell version $($PSVersionTable.PSVersion.ToString())"
          bash --version

Not sure what to do about those. I think they can be left as-is? Or should something be done?

@m3dwards
Copy link
Contributor Author

Isn't Set up VS Developer Prompt already done?

I think it's probably ok just just leave as is, rather than making this tiny PR. If someone is in that area it might be nice to have for consistency.

@maflcko
Copy link
Member

maflcko commented Feb 12, 2026

Isn't Set up VS Developer Prompt already done?

I don't know. I presume the CI will fail if the step is removed?

I think it's probably ok just just leave as is, rather than making this tiny PR.

Yeah, I think it is best to close. I tried to move it to Python, but given that this calls cmd.exe, one enters the cmd passing/parsing hell on Windows.

Commit fa71b94 didn't pass CI.

It would have been nice, because it would allow to remove all pwsh in commit fae91a8, but I guess we are stuck with it for now.

@m3dwards m3dwards closed this Feb 12, 2026
@maflcko
Copy link
Member

maflcko commented Feb 13, 2026

Actually, #34583 fully removes pwsh and also passes CI

fanquake added a commit that referenced this pull request Feb 27, 2026
fa36ade ci: [refactor] Drop last use of pwsh (MarcoFalke)
fae31b1 ci: [refactor] Move github_import_vs_env to python script (MarcoFalke)

Pull request description:

  The use of pwsh was a bit confusing and inconsistent around the exit code. See also #32672

  I think it is fine to drop it and purely use Bash/Python.

  This also moves a bit of code from the github yaml to the python script.

ACKs for top commit:
  m3dwards:
    Looks good! re-ACK fa36ade
  hodlinator:
    re-ACK fa36ade

Tree-SHA512: 78edffc60c58c476b0acca5224150169d154b0b818114844a04295af9ba19b7cdf1fb2afb738f6cafd6172f0f477d546018ebf95061eb5bd8bbb35e065a129d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants