Skip to content

GitHub Actions: Install latest PowerShell version on Windows #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,27 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
dotnet tool install --global PowerShell
- name: Find latest PowerShell version (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$packageName = "powershell"
$outputText = dotnet tool search $packageName --take 1
$outputLine = ("" + $outputText)
$indexOfVersionLine = $outputLine.IndexOf($packageName)
$latestVersion = $outputLine.substring($indexOfVersionLine + $packageName.length).trim().split(" ")[0].trim()

Write-Output "Found PowerShell version: $latestVersion"
Write-Output "POWERSHELL_LATEST_VERSION=$latestVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Setup PowerShell (Windows)
if: matrix.os == 'windows-latest'
shell: cmd
run: |
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
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
set DOWNLOAD_LINK=https://github.com/PowerShell/PowerShell/releases/download/v%POWERSHELL_LATEST_VERSION%/PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi
set OUTPUT_PATH=%RUNNER_TEMP%\PowerShell-%POWERSHELL_LATEST_VERSION%-win-x64.msi
echo Downloading from: %DOWNLOAD_LINK% to: %OUTPUT_PATH%
curl --location --output %OUTPUT_PATH% %DOWNLOAD_LINK%
msiexec.exe /package %OUTPUT_PATH% /quiet USE_MU=1 ENABLE_MU=1 ADD_PATH=1 DISABLE_TELEMETRY=1
- name: Setup PowerShell (macOS)
if: matrix.os == 'macos-latest'
run: |
Expand Down Expand Up @@ -160,12 +175,12 @@ jobs:
permissions:
contents: read
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Git checkout
uses: actions/checkout@v4
- name: Restore tools
run: |
dotnet tool restore
Expand Down Expand Up @@ -211,14 +226,14 @@ jobs:
permissions:
contents: read
steps:
- name: Git checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Git checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Restore tools
run: |
dotnet tool restore
Expand Down