Skip to content

Commit a9b92d6

Browse files
Refactor PowerShell installation: update version input handling to only resolve to latest if explicitly set; improve error messaging for empty version input.
1 parent 0ae9ecf commit a9b92d6

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

.github/workflows/Action-Test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,18 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest, windows-latest, macOS-latest]
25-
version: ['', null, 'latest', '7.4.7', '7.5.0'] # '' → should resolve to latest
25+
version: ['latest', '7.4.7', '7.5.0']
2626
runs-on: ${{ matrix.os }}
2727
name: '${{ matrix.os }} - [${{ matrix.version }}]'
2828
steps:
29-
# 1. Checkout the repo so the local action is available
3029
- name: Checkout repo
3130
uses: actions/checkout@v4
3231

33-
# 2. Run the action under test
3432
- name: Action-Test
3533
uses: ./
3634
with:
3735
Version: ${{ matrix.version }}
3836

39-
# 3. Verify the installed PowerShell version
4037
- name: Verify installed version
4138
shell: pwsh
4239
run: |

action.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ inputs:
1212
Version:
1313
description: >
1414
PowerShell version to install (e.g. `7.4.1`).
15-
Use `latest`, `null`, leave it **empty**, or omit the input entirely
16-
to grab the newest stable release automatically.
15+
Set to 'latest' to automatically install the newest stable release.
1716
required: false
18-
default: '' # Empty string → newest release
17+
default: 'latest'
1918

2019
runs:
2120
using: composite
@@ -30,16 +29,20 @@ runs:
3029
3130
echo "Requested version: [$REQUESTED_VERSION]"
3231
33-
# Resolve "" / null / latest → concrete latest version (Bash‑3 safe)
32+
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
3433
case "${REQUESTED_VERSION:-}" in
35-
""|[Ll][Aa][Tt][Ee][Ss][Tt]|[Nn][Uu][Ll][Ll]|~)
34+
[Ll][Aa][Tt][Ee][Ss][Tt])
3635
REQUESTED_VERSION=$(
3736
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
3837
grep '"tag_name"' | head -n1 |
3938
sed -E 's/.*"v?([^"]+)".*/\1/'
4039
)
4140
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
4241
;;
42+
"")
43+
echo "Error: Version input is required (or use 'latest')"
44+
exit 1
45+
;;
4346
esac
4447
4548
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
@@ -87,19 +90,16 @@ runs:
8790
8891
echo "Requested version: [$REQUESTED_VERSION]"
8992
90-
# Resolve "" / null / latest → concrete latest version
91-
if [[ -z "${REQUESTED_VERSION}" || "${REQUESTED_VERSION}" =~ ^[Ll][Aa][Tt][Ee][Ss][Tt]$ || "${REQUESTED_VERSION}" =~ ^[Nn][Uu][Ll][Ll]$ || "${REQUESTED_VERSION}" == "~" ]]; then
93+
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
94+
if [[ "${REQUESTED_VERSION}" =~ ^[Ll][Aa][Tt][Ee][Ss][Tt]$ ]]; then
9295
REQUESTED_VERSION=$(
9396
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
9497
grep '"tag_name"' | head -n1 |
9598
sed -E 's/.*"v?([^"]+)".*/\1/'
9699
)
97100
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
98-
fi
99-
100-
# Validate REQUESTED_VERSION is not empty
101-
if [[ -z "${REQUESTED_VERSION}" ]]; then
102-
echo "Error: Could not determine a valid PowerShell version."
101+
elif [[ -z "${REQUESTED_VERSION}" ]]; then
102+
echo "Error: Version input is required (or use 'latest')"
103103
exit 1
104104
fi
105105
@@ -130,14 +130,15 @@ runs:
130130
REQUESTED_VERSION: ${{ inputs.Version }}
131131
run: |
132132
Write-Host "Requested version: [$REQUESTED_VERSION]"
133-
# Resolve "" / null / latest → concrete latest version
133+
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
134134
$req = $env:REQUESTED_VERSION
135-
if ([string]::IsNullOrWhiteSpace($req) -or
136-
$req.Trim().ToLower() -in @('latest','null','~')) {
137-
135+
if ($req -and $req.Trim().ToLower() -eq 'latest') {
138136
$latest = (Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest').tag_name.TrimStart('v')
139137
Write-Host "Latest stable PowerShell release detected: $latest"
140138
$env:REQUESTED_VERSION = $latest
139+
} elseif ([string]::IsNullOrWhiteSpace($req)) {
140+
Write-Host "Error: Version input is required (or use 'latest')"
141+
exit 1
141142
}
142143
143144
try {

0 commit comments

Comments
 (0)