-
Notifications
You must be signed in to change notification settings - Fork 1
Allow installing Preview versions of PowerShell #13
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
Changes from all commits
222c5d3
ef2858c
e3bfd0b
65f62d4
3e97e34
359723c
0777397
ca66e82
3b5438e
11284b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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', 'preview', '7.4.7', '7.5.0'] | ||
| runs-on: ${{ matrix.os }} | ||
| name: '${{ matrix.os }} - [${{ matrix.version }}]' | ||
| steps: | ||
|
|
@@ -34,7 +34,8 @@ jobs: | |
| - name: Action-Test | ||
| uses: ./ | ||
| with: | ||
| Version: ${{ matrix.version }} | ||
| Version: ${{ matrix.version == 'preview' && 'latest' || matrix.version }} | ||
| Preview: ${{ matrix.version == 'preview' && 'true' || 'false' }} | ||
|
|
||
| - name: Verify installed version | ||
| shell: pwsh | ||
|
|
@@ -44,8 +45,19 @@ jobs: | |
| # Requested version that came from the matrix | ||
| $requested = '${{ matrix.version }}' | ||
|
|
||
| # When 'preview' → resolve to latest preview release | ||
| if ($requested.Trim().ToLower() -eq 'preview') { | ||
| $releases = Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases' ` | ||
| -Headers @{ | ||
| 'Accept' = 'application/vnd.github+json' | ||
| 'Authorization' = "Bearer $($env:GITHUB_TOKEN)" | ||
| 'X-GitHub-Api-Version' = '2022-11-28' | ||
| } | ||
| $requested = ($releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1).tag_name.TrimStart('v') | ||
| Write-Host "Resolved 'preview' → $requested" | ||
| } | ||
| # When empty / 'null' / 'latest' → resolve to latest stable release | ||
| if ([string]::IsNullOrWhiteSpace($requested) -or | ||
| elseif ([string]::IsNullOrWhiteSpace($requested) -or | ||
| $requested.Trim().ToLower() -in @('latest','null')) { | ||
|
|
||
| $requested = ( | ||
|
|
@@ -60,7 +72,14 @@ jobs: | |
| } | ||
|
|
||
| # Actual version installed by the action | ||
| $installed = ($PSVersionTable.PSVersion).ToString() | ||
| 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()') | ||
| } | ||
|
Comment on lines
+75
to
+81
|
||
|
|
||
| Write-Host "Installed PowerShell version: $installed" | ||
| Write-Host "Expected PowerShell version: $requested" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,10 +11,17 @@ branding: | |||||||||||||||||||
| inputs: | ||||||||||||||||||||
| Version: | ||||||||||||||||||||
| description: | | ||||||||||||||||||||
| PowerShell version to install (e.g. `7.4.1`). | ||||||||||||||||||||
| PowerShell version to install (e.g. `7.4.1` or `7.5.0-preview.1`). | ||||||||||||||||||||
| Defaults to install the latest stable release. | ||||||||||||||||||||
| Use 'latest' for latest stable, or latest preview if Preview is true. | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: 'latest' | ||||||||||||||||||||
| Preview: | ||||||||||||||||||||
| description: | | ||||||||||||||||||||
| Install PowerShell preview build instead of stable. | ||||||||||||||||||||
| When true and Version is 'latest', installs the latest preview release. | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: 'false' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| runs: | ||||||||||||||||||||
| using: composite | ||||||||||||||||||||
|
|
@@ -25,24 +32,39 @@ runs: | |||||||||||||||||||
| working-directory: ${{ github.action_path }} | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| REQUESTED_VERSION: ${{ inputs.Version }} | ||||||||||||||||||||
| PREVIEW: ${{ inputs.Preview }} | ||||||||||||||||||||
| GITHUB_TOKEN: ${{ github.token }} | ||||||||||||||||||||
| run: | | ||||||||||||||||||||
| # Install-PowerShell | ||||||||||||||||||||
| set -e | ||||||||||||||||||||
| echo "Requested version: [$REQUESTED_VERSION]" | ||||||||||||||||||||
| echo "Preview mode: [$PREVIEW]" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Only resolve to latest version if explicitly set to 'latest' (case-insensitive) | ||||||||||||||||||||
| case "${REQUESTED_VERSION:-}" in | ||||||||||||||||||||
| [Ll][Aa][Tt][Ee][Ss][Tt]) | ||||||||||||||||||||
| REQUESTED_VERSION=$( | ||||||||||||||||||||
| curl -s -f \ | ||||||||||||||||||||
| -H "Accept: application/vnd.github+json" \ | ||||||||||||||||||||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||||||||||||||||||||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||||||||||||||||||||
| https://api.github.com/repos/PowerShell/PowerShell/releases/latest | | ||||||||||||||||||||
| jq -r '.tag_name' | sed 's/^v//' | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| echo "Latest stable PowerShell release detected: $REQUESTED_VERSION" | ||||||||||||||||||||
| if [[ "$PREVIEW" == "true" ]]; then | ||||||||||||||||||||
| echo "Fetching latest preview release..." | ||||||||||||||||||||
| REQUESTED_VERSION=$( | ||||||||||||||||||||
| curl -s -f \ | ||||||||||||||||||||
| -H "Accept: application/vnd.github+json" \ | ||||||||||||||||||||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||||||||||||||||||||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||||||||||||||||||||
| https://api.github.com/repos/PowerShell/PowerShell/releases | | ||||||||||||||||||||
| jq -r '[.[] | select(.prerelease == true)] | .[0].tag_name' | sed 's/^v//' | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
Comment on lines
+54
to
+55
|
||||||||||||||||||||
| 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
AI
Feb 10, 2026
There was a problem hiding this comment.
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.
| 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
AI
Feb 10, 2026
There was a problem hiding this comment.
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
AI
Feb 10, 2026
There was a problem hiding this comment.
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).
| $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 | |
| } |
There was a problem hiding this comment.
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 onlypreview.