Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
version: ['latest', '7.4.7', '7.5.0']
version: ['latest', '7.4.7', '7.5.0', '7.6.0-preview.6']
runs-on: ${{ matrix.os }}
name: '${{ matrix.os }} - [${{ matrix.version }}]'
steps:
Expand Down Expand Up @@ -59,8 +59,21 @@ jobs:
Write-Host "Resolved 'latest' β†’ $requested"
}

# Actual version installed by the action
$installed = ($PSVersionTable.PSVersion).ToString()
# For prerelease versions on Windows, launch the installed pwsh to get the version
# because the current shell may not be the version we just installed.
$isPrerelease = $requested -match '-'
if ($IsWindows -and $isPrerelease) {
$majorVersion = ($requested -split '[\.-]')[0]
$installDir = "$majorVersion-preview"
$pwshPath = "$env:ProgramFiles\PowerShell\$installDir\pwsh.exe"
if (Test-Path $pwshPath) {
$installed = (& $pwshPath -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')
} else {
$installed = ($PSVersionTable.PSVersion).ToString()
}
} else {
$installed = ($PSVersionTable.PSVersion).ToString()
}
Write-Host "Installed PowerShell version: $installed"
Write-Host "Expected PowerShell version: $requested"

Comment thread
MariusStorhaug marked this conversation as resolved.
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

A cross‑platform GitHub Action that installs a specific **PowerShellΒ Core** versionβ€”or the latest stable releaseβ€”on any GitHub‑hosted runner
(Linux, macOS, or Windows). The action automatically skips installation when the requested version is already present.
Prerelease versions (e.g. `7.6.0-preview.6`, `7.5.0-rc.1`) are also supported.

## Usage

Expand All @@ -25,11 +26,20 @@ jobs:
Write-Host "Using PowerShell $($PSVersionTable.PSVersion)"
```

### Installing a prerelease version

```yaml
- name: Install PowerShell Preview
uses: PSModule/install-powershell@v1
with:
Version: 7.6.0-preview.6
```

## Inputs

| Input | Required | Default | Description |
| ----- | -------- | ------- | ----------- |
| `Version` | `false` | `latest` | Desired PowerShellΒ Core version (e.g. `7.4.1`). Use `latest` to install the newest stable release. |
| `Version` | `false` | `latest` | Desired PowerShell Core version (e.g. `7.4.1`, `7.6.0-preview.6`). Use `latest` to install the newest stable release. Prerelease versions are supported. |

## Secrets

Expand All @@ -43,7 +53,8 @@ This action does **not** generate any outputs.

* **Version resolution**
If `Version` is set to `latest` (case‑insensitive), the action queries the GitHubβ€―API for the newest stable release tag in the
`PowerShell/PowerShell` repository and substitutes that version.
`PowerShell/PowerShell` repository and substitutes that version. Prerelease version strings (e.g. `7.6.0-preview.6`) are passed
through directly.

* **Skip logic**
Before installing, the action checks the current runner to see whether the requested version is already available
Expand Down
18 changes: 13 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ branding:
inputs:
Version:
description: |
PowerShell version to install (e.g. `7.4.1`).
PowerShell version to install (e.g. `7.4.1` or `7.6.0-preview.6`).
Defaults to install the latest stable release.
Prerelease versions are supported (e.g. `7.6.0-preview.6`, `7.5.0-rc.1`).
required: false
default: 'latest'

Expand Down Expand Up @@ -198,14 +199,20 @@ runs:
}

# Downgrade detection
# Strip prerelease suffix for [version] comparison (e.g. '7.6.0-preview.6' β†’ '7.6.0')
$isDowngrade = $false
if ($detected -and $detected -ne $env:REQUESTED_VERSION) {
try {
$detectedVersion = [version]$detected
$requestedVersion = [version]$env:REQUESTED_VERSION
$detectedBase = ($detected -split '-')[0]
$requestedBase = ($env:REQUESTED_VERSION -split '-')[0]
$detectedVersion = [version]$detectedBase
$requestedVersion = [version]$requestedBase
if ($detectedVersion -gt $requestedVersion) {
Write-Host "Downgrade detected: $detected β†’ $($env:REQUESTED_VERSION)"
$isDowngrade = $true
} elseif ($detectedVersion -eq $requestedVersion -and $detected -ne $env:REQUESTED_VERSION) {
# Same base version but different prerelease label, treat as a reinstall
Write-Host "Version change detected (same base, different label): $detected β†’ $($env:REQUESTED_VERSION)"
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
} else {
Write-Host "Upgrade detected: $detected β†’ $($env:REQUESTED_VERSION)"
}
Expand All @@ -224,13 +231,14 @@ runs:
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)

$isDetectedPreview = $detected -match '-preview|\-rc'
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
$pwshEntries = Get-ItemProperty -Path $regPaths -ErrorAction SilentlyContinue |
Where-Object {
$_.Publisher -eq 'Microsoft Corporation' -and
$_.DisplayName -like 'PowerShell 7*' -and
$_.DisplayName -notlike '*Preview*' -and
$(if ($isDetectedPreview) { $_.DisplayName -like '*Preview*' } else { $_.DisplayName -notlike '*Preview*' }) -and
$_.DisplayVersion -and
$_.DisplayVersion.StartsWith($detected)
$_.DisplayVersion.StartsWith(($detected -split '-')[0])
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated

$targetEntry = $pwshEntries | Select-Object -First 1
Expand Down