Skip to content

Commit 4a23a7e

Browse files
🚀 [Feature]: Support installing prerelease PowerShell versions
- Update action input description to document prerelease version support - Fix Windows downgrade detection to handle prerelease version strings by stripping the prerelease suffix before casting to [version] - Fix Windows uninstall registry filter to match Preview display names when uninstalling a preview build - Add prerelease version (7.6.0-preview.6) to test workflow matrix - Update test verification to detect preview installs on Windows (preview builds install to a separate directory) - Update README with prerelease documentation and usage example Closes #15
1 parent d8fbe1f commit 4a23a7e

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

.github/workflows/Action-Test.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest, windows-latest, macOS-latest]
25-
version: ['latest', '7.4.7', '7.5.0']
25+
version: ['latest', '7.4.7', '7.5.0', '7.6.0-preview.6']
2626
runs-on: ${{ matrix.os }}
2727
name: '${{ matrix.os }} - [${{ matrix.version }}]'
2828
steps:
@@ -59,8 +59,21 @@ jobs:
5959
Write-Host "Resolved 'latest' → $requested"
6060
}
6161
62-
# Actual version installed by the action
63-
$installed = ($PSVersionTable.PSVersion).ToString()
62+
# For prerelease versions on Windows, launch the installed pwsh to get the version
63+
# because the current shell may not be the version we just installed.
64+
$isPrerelease = $requested -match '-'
65+
if ($IsWindows -and $isPrerelease) {
66+
$majorVersion = ($requested -split '[\.-]')[0]
67+
$installDir = "$majorVersion-preview"
68+
$pwshPath = "$env:ProgramFiles\PowerShell\$installDir\pwsh.exe"
69+
if (Test-Path $pwshPath) {
70+
$installed = (& $pwshPath -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')
71+
} else {
72+
$installed = ($PSVersionTable.PSVersion).ToString()
73+
}
74+
} else {
75+
$installed = ($PSVersionTable.PSVersion).ToString()
76+
}
6477
Write-Host "Installed PowerShell version: $installed"
6578
Write-Host "Expected PowerShell version: $requested"
6679

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

67
## Usage
78

@@ -25,11 +26,20 @@ jobs:
2526
Write-Host "Using PowerShell $($PSVersionTable.PSVersion)"
2627
```
2728
29+
### Installing a prerelease version
30+
31+
```yaml
32+
- name: Install PowerShell Preview
33+
uses: PSModule/install-powershell@v1
34+
with:
35+
Version: 7.6.0-preview.6
36+
```
37+
2838
## Inputs
2939
3040
| Input | Required | Default | Description |
3141
| ----- | -------- | ------- | ----------- |
32-
| `Version` | `false` | `latest` | Desired PowerShell Core version (e.g. `7.4.1`). Use `latest` to install the newest stable release. |
42+
| `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. |
3343

3444
## Secrets
3545

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

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

4859
* **Skip logic**
4960
Before installing, the action checks the current runner to see whether the requested version is already available

action.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ branding:
1111
inputs:
1212
Version:
1313
description: |
14-
PowerShell version to install (e.g. `7.4.1`).
14+
PowerShell version to install (e.g. `7.4.1` or `7.6.0-preview.6`).
1515
Defaults to install the latest stable release.
16+
Prerelease versions are supported (e.g. `7.6.0-preview.6`, `7.5.0-rc.1`).
1617
required: false
1718
default: 'latest'
1819

@@ -198,14 +199,20 @@ runs:
198199
}
199200
200201
# Downgrade detection
202+
# Strip prerelease suffix for [version] comparison (e.g. '7.6.0-preview.6' → '7.6.0')
201203
$isDowngrade = $false
202204
if ($detected -and $detected -ne $env:REQUESTED_VERSION) {
203205
try {
204-
$detectedVersion = [version]$detected
205-
$requestedVersion = [version]$env:REQUESTED_VERSION
206+
$detectedBase = ($detected -split '-')[0]
207+
$requestedBase = ($env:REQUESTED_VERSION -split '-')[0]
208+
$detectedVersion = [version]$detectedBase
209+
$requestedVersion = [version]$requestedBase
206210
if ($detectedVersion -gt $requestedVersion) {
207211
Write-Host "Downgrade detected: $detected → $($env:REQUESTED_VERSION)"
208212
$isDowngrade = $true
213+
} elseif ($detectedVersion -eq $requestedVersion -and $detected -ne $env:REQUESTED_VERSION) {
214+
# Same base version but different prerelease label, treat as a reinstall
215+
Write-Host "Version change detected (same base, different label): $detected → $($env:REQUESTED_VERSION)"
209216
} else {
210217
Write-Host "Upgrade detected: $detected → $($env:REQUESTED_VERSION)"
211218
}
@@ -224,13 +231,14 @@ runs:
224231
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
225232
)
226233
234+
$isDetectedPreview = $detected -match '-preview|\-rc'
227235
$pwshEntries = Get-ItemProperty -Path $regPaths -ErrorAction SilentlyContinue |
228236
Where-Object {
229237
$_.Publisher -eq 'Microsoft Corporation' -and
230238
$_.DisplayName -like 'PowerShell 7*' -and
231-
$_.DisplayName -notlike '*Preview*' -and
239+
$(if ($isDetectedPreview) { $_.DisplayName -like '*Preview*' } else { $_.DisplayName -notlike '*Preview*' }) -and
232240
$_.DisplayVersion -and
233-
$_.DisplayVersion.StartsWith($detected)
241+
$_.DisplayVersion.StartsWith(($detected -split '-')[0])
234242
}
235243
236244
$targetEntry = $pwshEntries | Select-Object -First 1

0 commit comments

Comments
 (0)