Skip to content

Allow installing Preview versions of PowerShell#13

Open
Agriya Khetarpal (agriyakhetarpal) wants to merge 10 commits intoPSModule:mainfrom
agriyakhetarpal:allow-installing-preview-versions
Open

Allow installing Preview versions of PowerShell#13
Agriya Khetarpal (agriyakhetarpal) wants to merge 10 commits intoPSModule:mainfrom
agriyakhetarpal:allow-installing-preview-versions

Conversation

@agriyakhetarpal

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

  • 📖 [Docs]
  • 🪲 [Fix]
  • 🩹 [Patch]
  • ⚠️ [Security fix]
  • 🚀 [Feature]
  • 🌟 [Breaking change]

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

@agriyakhetarpal Agriya Khetarpal (agriyakhetarpal) changed the title Allow "Preview" as an input Allow installing Preview versions of PowerShell Feb 10, 2026
@agriyakhetarpal

I will test this change on my fork and confirm before I mark this as ready for review. Thanks!

@agriyakhetarpal

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!

@agriyakhetarpal

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.

@agriyakhetarpal Agriya Khetarpal (agriyakhetarpal) marked this pull request as ready for review February 10, 2026 01:42
Copilot AI review requested due to automatic review settings February 10, 2026 01:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Preview input 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 Preview is 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.

Comment on lines +54 to +55
jq -r '[.[] | select(.prerelease == true)] | .[0].tag_name' | sed 's/^v//'
)
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +144
jq -r '[.[] | select(.prerelease == true)] | .[0].tag_name' | sed 's/^v//'
)
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
'Authorization' = "Bearer $($env:GITHUB_TOKEN)"
'X-GitHub-Api-Version' = '2022-11-28'
}
$latestPreview = $releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
$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
}

Copilot uses AI. Check for mistakes.
$installed = ($PSVersionTable.PSVersion).ToString()
if ($IsWindows) {
$majorVersion = ($requested -split '[\.-]')[0]
$installDir = if ($requested -match 'preview') { "$majorVersion-preview" } else { $majorVersion }
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$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 }

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +81
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()')
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines 204 to +212
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' `
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@MariusStorhaug
Copy link
Member

Agriya Khetarpal (@agriyakhetarpal) Thank you for the contribution. I'll have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants