Skip to content

Commit 0eb4174

Browse files
authored
Merge pull request #1342 from json-api-dotnet/pwsh-windows-latest
GitHub Actions: Install latest PowerShell version on Windows
2 parents 68e1854 + cb8f630 commit 0eb4174

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

.github/workflows/build.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,27 @@ 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+
$outputText = dotnet tool search $packageName --take 1
61+
$outputLine = ("" + $outputText)
62+
$indexOfVersionLine = $outputLine.IndexOf($packageName)
63+
$latestVersion = $outputLine.substring($indexOfVersionLine + $packageName.length).trim().split(" ")[0].trim()
64+
65+
Write-Output "Found 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+
set DOWNLOAD_LINK=https://github.com/PowerShell/PowerShell/releases/download/v%POWERSHELL_LATEST_VERSION%/PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi
72+
set OUTPUT_PATH=%RUNNER_TEMP%\PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi
73+
echo Downloading from: %DOWNLOAD_LINK% to: %OUTPUT_PATH%
74+
curl --location --output %OUTPUT_PATH% %DOWNLOAD_LINK%
75+
msiexec.exe /package %OUTPUT_PATH% /quiet USE_MU=1 ENABLE_MU=1 ADD_PATH=1 DISABLE_TELEMETRY=1
6176
- name: Setup PowerShell (macOS)
6277
if: matrix.os == 'macos-latest'
6378
run: |
@@ -160,12 +175,12 @@ jobs:
160175
permissions:
161176
contents: read
162177
steps:
163-
- name: Git checkout
164-
uses: actions/checkout@v4
165178
- name: Setup .NET
166179
uses: actions/setup-dotnet@v3
167180
with:
168181
dotnet-version: 6.0.x
182+
- name: Git checkout
183+
uses: actions/checkout@v4
169184
- name: Restore tools
170185
run: |
171186
dotnet tool restore
@@ -211,14 +226,14 @@ jobs:
211226
permissions:
212227
contents: read
213228
steps:
214-
- name: Git checkout
215-
uses: actions/checkout@v4
216-
with:
217-
fetch-depth: 2
218229
- name: Setup .NET
219230
uses: actions/setup-dotnet@v3
220231
with:
221232
dotnet-version: 6.0.x
233+
- name: Git checkout
234+
uses: actions/checkout@v4
235+
with:
236+
fetch-depth: 2
222237
- name: Restore tools
223238
run: |
224239
dotnet tool restore

0 commit comments

Comments
 (0)