Skip to content

Commit 86739b0

Browse files
Enhance PowerShell installation scripts with improved version detection and error handling
1 parent 8554dee commit 86739b0

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

action.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ runs:
5050
esac
5151
5252
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
53+
if [[ -n "$DETECTED_VERSION" ]]; then
54+
echo "Currently installed PowerShell version: $DETECTED_VERSION"
55+
else
56+
echo "PowerShell is not currently installed"
57+
fi
58+
5359
if [[ "$DETECTED_VERSION" == "$REQUESTED_VERSION" ]]; then
5460
echo "PowerShell $DETECTED_VERSION already installed. Skipping."
5561
exit 0
@@ -116,6 +122,12 @@ runs:
116122
esac
117123
118124
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
125+
if [[ -n "$DETECTED_VERSION" ]]; then
126+
echo "Currently installed PowerShell version: $DETECTED_VERSION"
127+
else
128+
echo "PowerShell is not currently installed"
129+
fi
130+
119131
if [[ "$DETECTED_VERSION" == "$REQUESTED_VERSION" ]]; then
120132
echo "PowerShell $DETECTED_VERSION already installed. Skipping."
121133
exit 0
@@ -143,7 +155,8 @@ runs:
143155
REQUESTED_VERSION: ${{ inputs.Version }}
144156
GITHUB_TOKEN: ${{ github.token }}
145157
run: |
146-
Write-Host "Requested version: [$REQUESTED_VERSION]"
158+
Write-Host "Requested version: [$env:REQUESTED_VERSION]"
159+
147160
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
148161
$req = $env:REQUESTED_VERSION
149162
if ($req -and $req.Trim().ToLower() -eq 'latest') {
@@ -164,19 +177,22 @@ runs:
164177
165178
try {
166179
$detected = (pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')
180+
Write-Host "Currently installed PowerShell version: $detected"
167181
} catch {
182+
Write-Host "PowerShell is not currently installed"
168183
$detected = $null
169184
}
170185
171-
Write-Host "Detected PowerShell version: $detected"
172-
Write-Host "Requested PowerShell version: $env:REQUESTED_VERSION"
173-
174186
if ($detected -eq $env:REQUESTED_VERSION) {
175187
Write-Host "PowerShell $detected already installed. Skipping."
176188
exit 0
177189
}
178190
179191
$msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi"
180192
$url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi"
181-
Invoke-WebRequest -Uri $url -OutFile $msi -UseBasicParsing
193+
Write-Host "Downloading from: $url"
194+
if (-not (Invoke-WebRequest -Uri $url -OutFile $msi -UseBasicParsing -PassThru)) {
195+
Write-Host "Error: Failed to download PowerShell package"
196+
exit 1
197+
}
182198
Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait

0 commit comments

Comments
 (0)