Skip to content

Commit f6ff12f

Browse files
Refactor action.yml: streamline description formatting, enhance error handling, and improve detected version display for Windows installation.
1 parent e05baed commit f6ff12f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

action.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: Install PowerShell
2-
description: |
3-
Install a specific version of PowerShell Core on any GitHub runner (Linux, macOS, Windows).
4-
Handles install, downgrade, or forced reinstall.
2+
description: Install a specific version of PowerShell Core on any GitHub runner (Linux, macOS, Windows). Handles install, downgrade, or forced reinstall.
53
author: PSModule
64
branding:
75
icon: terminal
@@ -66,6 +64,7 @@ runs:
6664
shell: bash
6765
run: |
6866
set -e
67+
6968
echo "Detecting existing PowerShell on macOS…"
7069
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
7170
echo "Detected version: ${DETECTED_VERSION:-<none>}"
@@ -105,29 +104,42 @@ runs:
105104
shell: powershell
106105
run: |
107106
Write-Host "Detecting existing PowerShell on Windows…"
108-
try { $detected = (pwsh -NoLogo -NoProfile -Command "$PSVersionTable.PSVersion.ToString()") } catch { $detected = $null }
109-
Write-Host "Detected version: $($detected ?? '<none>')"
107+
try {
108+
$detected = (pwsh -NoLogo -NoProfile -Command "$PSVersionTable.PSVersion.ToString()")
109+
} catch {
110+
$detected = $null
111+
}
112+
113+
if ($null -eq $detected -or $detected -eq '') {
114+
$detectedDisplay = '<none>'
115+
} else {
116+
$detectedDisplay = $detected
117+
}
118+
Write-Host "Detected version: $detectedDisplay"
110119
Write-Host "Requested version: $env:REQUESTED_VERSION"
111120
Write-Host "Reinstall flag: $env:REINSTALL"
112121
113122
if (-not $detected) {
114123
$decision = 'install'
115124
} elseif ($detected -eq $env:REQUESTED_VERSION) {
116-
$decision = ($env:REINSTALL -eq 'true') ? 'reinstall' : 'skip'
125+
if ($env:REINSTALL -eq 'true') {
126+
$decision = 'reinstall'
127+
} else {
128+
$decision = 'skip'
129+
}
117130
} else {
118131
$decision = 'uninstall-install'
119132
}
120133
Write-Host "Decision: $decision"
121134
122135
if ($decision -eq 'skip') {
123136
Write-Host 'Skipping installation on Windows (exact version present).'
124-
}
125-
else {
137+
} else {
126138
Write-Host 'Uninstalling any existing PowerShell…'
127139
winget uninstall --id Microsoft.PowerShell -e --silent | Out-Null
128140
Write-Host "Installing PowerShell $env:REQUESTED_VERSION…"
129141
$msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi"
130142
$url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi"
131143
Invoke-WebRequest $url -OutFile $msi
132-
Start-Process msiexec.exe -ArgumentList "/i", $msi, "/quiet", "/norestart" -Wait
144+
Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait
133145
}

0 commit comments

Comments
 (0)