On Windows, explicit pwsh does not fall back to Powershell Desktop
Describe the bug
The docs say that if shell: pwsh is specified on a Windows self-hosted runner, and Powershell Core is not installed on the runner, then Powershell Desktop will be used instead. I have not found this to be true.
To Reproduce
jobs:
pwsh_test:
runs-on: [self-hosted, windows]
steps:
- shell: pwsh
run: Get-ChildItem
Expected behavior I should see a directory listing
Runner Version and Platform
Version of your runner? 2.317.0
OS of the machine running the runner? Windows
What's not working?
I get Error: pwsh: command not found
Job Log Output
2024-08-03T14:46:01.5498934Z ##[debug]Evaluating condition for step: 'Run Get-ChildItem'
2024-08-03T14:46:01.5732322Z ##[debug]Evaluating: success()
2024-08-03T14:46:01.5741534Z ##[debug]Evaluating success:
2024-08-03T14:46:01.5786071Z ##[debug]=> true
2024-08-03T14:46:01.5797753Z ##[debug]Result: true
2024-08-03T14:46:01.5857543Z ##[debug]Starting: Run Get-ChildItem
2024-08-03T14:46:01.6984079Z ##[debug]Loading inputs
2024-08-03T14:46:01.7056280Z ##[debug]Loading env
2024-08-03T14:46:01.7246604Z ##[group]Run Get-ChildItem
2024-08-03T14:46:01.7247734Z [36;1mGet-ChildItem[0m
2024-08-03T14:46:01.7543572Z ##[error]pwsh: command not found
2024-08-03T14:46:01.7562102Z ##[debug]System.IO.FileNotFoundException: pwsh: command not found
2024-08-03T14:46:01.7563794Z ##[debug]File name: 'pwsh'
2024-08-03T14:46:01.7566153Z ##[debug] at GitHub.Runner.Sdk.WhichUtil.Which(String command, Boolean require, ITraceWriter trace, String prependPath)
2024-08-03T14:46:01.7570036Z ##[debug] at GitHub.Runner.Worker.Handlers.ScriptHandler.PrintActionDetails(ActionRunStage stage)
2024-08-03T14:46:01.7573443Z ##[debug] at GitHub.Runner.Worker.Handlers.Handler.PrepareExecution(ActionRunStage stage)
2024-08-03T14:46:01.7575978Z ##[debug] at GitHub.Runner.Worker.ActionRunner.RunAsync()
2024-08-03T14:46:01.7578997Z ##[debug] at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
2024-08-03T14:46:01.7595221Z ##[debug]Finishing: Run Get-ChildItem
Diagnosis
I think the issue is in this block of code. If there is no shell specified on Windows, then the if block will look for pwsh and fall back to powershell. But if pwsh is specified as the shell, the else block does not have a fallback provision.
It looks like the same issue with bash on non-Windows hosts, which the docs say is supposed to fall back to sh if bash is not available.
If this is the intended behavior, then the docs should be updated accordingly. But I would submit that the behavior described in the docs is desirable, and the code should be fixed to provide a fallback when pwsh or bash is specified.
My use case is a job which can run on Windows or Linux. My Linux self-hosted runner has pwsh installed, but my Windows runner does not. (I don't control the configuration of the runners.) I'd like to be able to specify shell: pwsh for a step and provide a script that works on both runners, using pwsh on Linux and powershell on Windows; the docs imply that this should work.