actions / runner

The Runner for GitHub Actions :rocket:
https://github.com/features/actions
MIT License
4.91k stars 965 forks source link

It should be easier to force `shell: pwsh` to use a specific PowerShell installation; #2975

Open tig opened 1 year ago

tig commented 1 year ago

It should be easier to force shell: pwsh to use a specific pwsh installation; it seems to always use C:\Program Files\PowerShell\7\pwsh.EXE. I tried shell: C:\Users\runneradmin\.dotnet\tools\pwsh and got an error.

I've found a workaround of having a step install the latest PS using dotnet tool install and changing $env:GITHUB_PATH, but it's clunky.

    - name: HACK - Install Latest PowerShell (so we get v7.3+ that uses .net 7)
      shell: pwsh
      run: |
            dotnet tool install --global PowerShell
            $content = Get-Content -Path $env:GITHUB_PATH
            $HOME + "/.dotnet/tools`r`n" + $content | Set-Content -Path $env:GITHUB_PATH -Encoding utf8

This (or something similar) should work:

shell: $HOME + /.dotnet/tools/pwsh {0}

Originally posted by @tig in https://github.com/actions/runner-images/issues/8754#issuecomment-1796170450

krokofant commented 1 year ago

I would like to bring attention to a related issue with using newer PowerShell versions and that is configuring breaking features. One new default enabled feature as of 7.3 is PSNativeCommandArgumentPassing.

It can be enabled on 7.2 by changing the config, but changing the config requires a restart of powershell. It would be fantastic if this could be solved by the runner, if a feature is demanded to be enabled we update the powershell config, and then start pwsh.

That would make it easier to migrate to newer versions of powershell when 7.4 LTS eventually lands in actions/runner-images.

What I described here is to workaround not having a flexible way of enabling/disabling experimental features in powershell directly.

github-actions[bot] commented 1 week ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 15 days.