Allow installing Preview versions of PowerShell#13
Allow installing Preview versions of PowerShell#13Agriya Khetarpal (agriyakhetarpal) wants to merge 10 commits intoPSModule:mainfrom
Conversation
|
I will test this change on my fork and confirm before I mark this as ready for review. Thanks! |
|
Okay so all workflows are working besides the Windows-Preview one. I have no clue why it fails and the last commit I pushed is a desolate attempt to fix it with Claude (I have to disclose it responsibly). I'm not sure if it will work. Perhaps you may know the nitty-gritties for the Preview edition and can assist here! |
|
Okay, all green in agriyakhetarpal#1! Much thanks to Claude, I was able to get over the last hurdle, and then the rest was easy to fix. That said, I don't know if this is the right solution, though. It works with the v7.x series, but we aren't testing with v6.x and v8.x isn't even out yet. |
There was a problem hiding this comment.
Pull request overview
Adds support for installing PowerShell preview/prerelease builds via the action, including the ability to resolve “latest preview” when Version: latest is combined with a new Preview input.
Changes:
- Add
Previewinput to the composite action and propagate it into all OS install steps. - Update “latest” version resolution to optionally pick the latest prerelease from GitHub Releases when
Previewis enabled. - Extend CI workflow matrix to exercise preview installs and update verification logic.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
action.yml |
Adds Preview input and modifies “latest” resolution logic to fetch the latest prerelease when requested. |
.github/workflows/Action-Test.yml |
Adds a preview matrix entry and adjusts verification to validate preview installs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| jq -r '[.[] | select(.prerelease == true)] | .[0].tag_name' | sed 's/^v//' | ||
| ) |
There was a problem hiding this comment.
The preview-version resolution uses jq ... | .[0].tag_name without guarding for cases where no prerelease is returned (or when the newest prerelease isn’t first / is a draft). If this yields null, the action will proceed with REQUESTED_VERSION=null and fail later with a confusing 404. Consider filtering out drafts, sorting by published_at, and explicitly erroring when no prerelease is found.
| jq -r '[.[] | select(.prerelease == true)] | .[0].tag_name' | sed 's/^v//' | |
| ) | |
| jq -r '[.[] | select(.prerelease == true and .draft != true)] | sort_by(.published_at) | last | .tag_name // empty' | sed 's/^v//' | |
| ) | |
| if [[ -z "$REQUESTED_VERSION" ]]; then | |
| echo "Error: No preview releases found for PowerShell. Cannot resolve 'latest' preview version." | |
| exit 1 | |
| fi |
| jq -r '[.[] | select(.prerelease == true)] | .[0].tag_name' | sed 's/^v//' | ||
| ) |
There was a problem hiding this comment.
Same issue as Linux: preview resolution via /releases + jq ... .[0].tag_name can produce null (no prereleases) or pick the wrong prerelease if ordering/drafts change. Add filtering/sorting and a clear error when no preview release is found.
| jq -r '[.[] | select(.prerelease == true)] | .[0].tag_name' | sed 's/^v//' | |
| ) | |
| jq -r '[.[] | select(.prerelease == true and .draft == false)] | sort_by(.created_at) | reverse | .[0].tag_name' | sed 's/^v//' | |
| ) | |
| if [[ -z "$REQUESTED_VERSION" || "$REQUESTED_VERSION" == "null" ]]; then | |
| echo "Error: No preview PowerShell release found when resolving 'latest' preview." | |
| exit 1 | |
| fi |
| 'Authorization' = "Bearer $($env:GITHUB_TOKEN)" | ||
| 'X-GitHub-Api-Version' = '2022-11-28' | ||
| } | ||
| $latestPreview = $releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1 |
There was a problem hiding this comment.
If GitHub returns no prerelease items, $latestPreview will be $null and $latestPreview.tag_name.TrimStart('v') will throw. Add an explicit null-check and fail with a clear error message (and consider excluding draft releases and sorting by published_at).
| $latestPreview = $releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1 | |
| $latestPreview = $releases ` | |
| | Where-Object { $_.prerelease -eq $true -and -not $_.draft } ` | |
| | Sort-Object -Property published_at -Descending ` | |
| | Select-Object -First 1 | |
| if (-not $latestPreview -or -not $latestPreview.tag_name) { | |
| Write-Error "No non-draft preview releases found for PowerShell. Cannot resolve 'latest' preview version." | |
| exit 1 | |
| } |
| $installed = ($PSVersionTable.PSVersion).ToString() | ||
| if ($IsWindows) { | ||
| $majorVersion = ($requested -split '[\.-]')[0] | ||
| $installDir = if ($requested -match 'preview') { "$majorVersion-preview" } else { $majorVersion } |
There was a problem hiding this comment.
Windows verification treats a prerelease install as preview only when the version string contains preview. GitHub prereleases can also be -rc.N (or other labels), which would be installed into the preview side-by-side location but this logic would look in the stable directory. Consider detecting prerelease more generally (e.g., any SemVer pre-release -...) rather than matching only preview.
| $installDir = if ($requested -match 'preview') { "$majorVersion-preview" } else { $majorVersion } | |
| # Treat any SemVer prerelease (e.g., "-preview.1", "-rc.1") as a preview install | |
| $isPreRelease = $requested -match '^\d+(?:\.\d+){1,2}-' | |
| $installDir = if ($isPreRelease) { "$majorVersion-preview" } else { $majorVersion } |
| if ($IsWindows) { | ||
| $majorVersion = ($requested -split '[\.-]')[0] | ||
| $installDir = if ($requested -match 'preview') { "$majorVersion-preview" } else { $majorVersion } | ||
| $installed = (& "$env:ProgramFiles\PowerShell\$installDir\pwsh.exe" -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()') | ||
| } else { | ||
| $installed = (pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()') | ||
| } |
There was a problem hiding this comment.
The Windows branch verifies the installed version by invoking a hard-coded install path instead of the pwsh on PATH. This means the workflow may pass even if the action doesn’t make the requested version the default pwsh (which is what users rely on via shell: pwsh). Consider asserting what pwsh resolves to (or have the action export/update PATH and verify that behavior).
| Write-Host "Requested version: [$env:REQUESTED_VERSION]" | ||
| Write-Host "Preview mode: [$env:PREVIEW]" | ||
|
|
||
| # Resolve 'latest' → concrete version | ||
| $req = $env:REQUESTED_VERSION | ||
| if ($req -and $req.Trim().ToLower() -eq 'latest') { | ||
| $latest = ( | ||
| Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest' ` | ||
| -Headers @{ | ||
| 'Accept' = 'application/vnd.github+json' | ||
| 'Authorization' = "Bearer $($env:GITHUB_TOKEN)" | ||
| 'X-GitHub-Api-Version' = '2022-11-28' | ||
| } | ||
| ).tag_name.TrimStart('v') | ||
| Write-Host "Latest stable PowerShell release detected: $latest" | ||
| if ($env:PREVIEW -eq 'true') { | ||
| Write-Host "Fetching latest preview release..." | ||
| $releases = Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases' ` |
There was a problem hiding this comment.
On Windows, preview/prerelease builds are typically installed side-by-side (e.g., under a *-preview directory) rather than replacing the stable install. This action still relies on pwsh from PATH for detection and for user steps (shell: pwsh), so it may continue using the stable pwsh even after installing a preview. Consider explicitly updating PATH (or exposing the installed pwsh path as an output) when Preview is enabled so subsequent steps reliably use the requested build.
|
Agriya Khetarpal (@agriyakhetarpal) Thank you for the contribution. I'll have a look. |
Description
Hi! Thanks a lot for writing this action! Apologies for this unsolicited feature PR – I wanted a way to install a Preview version of the action, and considering it wasn't much work, I thought I'd put it up and see if you like it.
Type of change
Checklist