Skip to content

Commit 988ed22

Browse files
committed
GitHub Actions: Install latest PowerShell version on Windows
1 parent 68e1854 commit 988ed22

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,24 @@ jobs:
5252
if: matrix.os == 'ubuntu-latest'
5353
run: |
5454
dotnet tool install --global PowerShell
55+
- name: Find latest PowerShell version (Windows)
56+
if: matrix.os == 'windows-latest'
57+
shell: pwsh
58+
run: |
59+
$packageName = "powershell"
60+
$output = dotnet tool search $packageName --take 1
61+
$outputAsSingleLine = ("" + $output)
62+
$indexOfVersionLine = $outputAsSingleLine.IndexOf($packageName)
63+
$latestVersion = $outputAsSingleLine.substring($indexOfVersionLine + $packageName.length).trim().split(" ")[0].trim()
64+
65+
Write-Output "Using PowerShell version: $latestVersion"
66+
Write-Output "POWERSHELL_LATEST_VERSION=$latestVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
5567
- name: Setup PowerShell (Windows)
5668
if: matrix.os == 'windows-latest'
5769
shell: cmd
5870
run: |
59-
curl --location --output "%RUNNER_TEMP%\PowerShell-7.3.6-win-x64.msi" https://github.com/PowerShell/PowerShell/releases/download/v7.3.6/PowerShell-7.3.6-win-x64.msi
60-
msiexec.exe /package "%RUNNER_TEMP%\PowerShell-7.3.6-win-x64.msi" /quiet USE_MU=1 ENABLE_MU=1 ADD_PATH=1 DISABLE_TELEMETRY=1
71+
curl --location --output "%RUNNER_TEMP%\PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi" https://github.com/PowerShell/PowerShell/releases/download/latest/PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi
72+
msiexec.exe /package "%RUNNER_TEMP%\PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi" /quiet USE_MU=1 ENABLE_MU=1 ADD_PATH=1 DISABLE_TELEMETRY=1
6173
- name: Setup PowerShell (macOS)
6274
if: matrix.os == 'macos-latest'
6375
run: |

0 commit comments

Comments
 (0)