Skip to content

Commit 00a357a

Browse files
Implement version comparison logic for Windows PowerShell downgrade detection
Co-authored-by: MariusStorhaug <[email protected]>
1 parent 88f6b91 commit 00a357a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

action.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,23 @@ runs:
204204
exit 0
205205
}
206206
207+
# Check if we need to handle a downgrade scenario
208+
$isDowngrade = $false
209+
if ($detected -and $detected -ne $env:REQUESTED_VERSION) {
210+
try {
211+
$detectedVersion = [version]$detected
212+
$requestedVersion = [version]$env:REQUESTED_VERSION
213+
if ($detectedVersion -gt $requestedVersion) {
214+
Write-Host "Downgrade detected: $detected → $($env:REQUESTED_VERSION)"
215+
$isDowngrade = $true
216+
} else {
217+
Write-Host "Upgrade detected: $detected → $($env:REQUESTED_VERSION)"
218+
}
219+
} catch {
220+
Write-Host "Warning: Could not compare versions, proceeding with regular installation"
221+
}
222+
}
223+
207224
$msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi"
208225
$url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi"
209226
Write-Host "Downloading from: $url"
@@ -214,6 +231,14 @@ runs:
214231
}
215232
216233
Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..."
217-
Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait
234+
235+
if ($isDowngrade) {
236+
# For downgrades, use force reinstall to overwrite the existing version
237+
Write-Host "Using force reinstall for downgrade scenario..."
238+
Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait
239+
} else {
240+
# For upgrades or fresh installs, use regular install
241+
Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait
242+
}
218243
219244
Write-Host "Installation complete. PowerShell [$($env:REQUESTED_VERSION)] is now available."

0 commit comments

Comments
 (0)