Skip to content

Commit ddd52b1

Browse files
Refactor PowerShell installation: improve comments for clarity; standardize version resolution logic across platforms.
1 parent 45bce54 commit ddd52b1

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

action.yml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Install PowerShell
22
description: >
3-
Install a specific version —or the latest stable version— of PowerShell Core
3+
Install a specific version —or the latest stable version— of PowerShell Core
44
on any GitHub runner (Linux, macOS, Windows).
55
Skips the install if the requested version is already present.
66
author: PSModule
@@ -15,7 +15,7 @@ inputs:
1515
Use `latest`, `null`, leave it **empty**, or omit the input entirely
1616
to grab the newest stable release automatically.
1717
required: false
18-
default: ''
18+
default: '' # Empty string → newest release
1919

2020
runs:
2121
using: composite
@@ -28,15 +28,17 @@ runs:
2828
run: |
2929
set -e
3030
31-
# Resolve empty / 'null' / 'latest' to a concrete version number
32-
lower_req="$(printf '%s' "$REQUESTED_VERSION" | tr '[:upper:]' '[:lower:]')"
33-
if [[ -z "$REQUESTED_VERSION" || "$lower_req" == "latest" || "$lower_req" == "null" ]]; then
34-
REQUESTED_VERSION=$(
35-
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest \
36-
| grep -oP '"tag_name":\s*"\K([^"]+)' | sed 's/^v//'
37-
)
38-
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
39-
fi
31+
# Resolve "" / null / latest → concrete latest version (Bash‑3 safe)
32+
case "${REQUESTED_VERSION:-}" in
33+
""|[Ll][Aa][Tt][Ee][Ss][Tt]|[Nn][Uu][Ll][Ll]|~)
34+
REQUESTED_VERSION=$(
35+
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
36+
grep '"tag_name"' | head -n1 |
37+
sed -E 's/.*"v?([^"]+)".*/\1/'
38+
)
39+
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
40+
;;
41+
esac
4042
4143
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
4244
if [[ "$DETECTED_VERSION" == "$REQUESTED_VERSION" ]]; then
@@ -81,15 +83,16 @@ runs:
8183
run: |
8284
set -e
8385
86+
# Resolve "" / null / latest → concrete latest version (Bash‑3 safe)
8487
case "${REQUESTED_VERSION:-}" in
85-
"" | [Ll][Aa][Tt][Ee][Ss][Tt] | [Nn][Uu][Ll][Ll])
86-
REQUESTED_VERSION=$(
87-
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
88-
grep '"tag_name"' | head -n1 |
89-
sed -E 's/.*"v?([^"]+)".*/\1/'
90-
)
91-
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
92-
;;
88+
""|[Ll][Aa][Tt][Ee][Ss][Tt]|[Nn][Uu][Ll][Ll]|~)
89+
REQUESTED_VERSION=$(
90+
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
91+
grep '"tag_name"' | head -n1 |
92+
sed -E 's/.*"v?([^"]+)".*/\1/'
93+
)
94+
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
95+
;;
9396
esac
9497
9598
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
@@ -118,10 +121,10 @@ runs:
118121
env:
119122
REQUESTED_VERSION: ${{ inputs.Version }}
120123
run: |
121-
# Resolve empty / 'null' / 'latest' to a concrete version number
124+
# Resolve "" / null / latestconcrete latest version
122125
$req = $env:REQUESTED_VERSION
123126
if ([string]::IsNullOrWhiteSpace($req) -or
124-
($req.Trim().ToLower() -in @('latest','null'))) {
127+
$req.Trim().ToLower() -in @('latest','null','~')) {
125128
126129
$latest = (Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest').tag_name.TrimStart('v')
127130
Write-Host "Latest stable PowerShell release detected: $latest"

0 commit comments

Comments
 (0)