From 2a7b393c2c46327530b6f286f467e5dd837aa29f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Jun 2025 08:17:38 +0000 Subject: [PATCH 01/10] Initial plan for issue From aedf25118786d38bfc8cb3e8a2c34f50a3f2e60d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Jun 2025 08:22:30 +0000 Subject: [PATCH 02/10] Implement Windows PowerShell downgrade support using msiexec /f flag Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- action.yml | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index b55c1a6..fd97f09 100644 --- a/action.yml +++ b/action.yml @@ -204,16 +204,41 @@ runs: exit 0 } + # Check if we need to handle a downgrade scenario + $isDowngrade = $false + if ($detected -and $detected -ne $env:REQUESTED_VERSION) { + try { + $detectedVersion = [version]$detected + $requestedVersion = [version]$env:REQUESTED_VERSION + if ($detectedVersion -gt $requestedVersion) { + Write-Host "Downgrade detected: $detected → $($env:REQUESTED_VERSION)" + $isDowngrade = $true + } else { + Write-Host "Upgrade detected: $detected → $($env:REQUESTED_VERSION)" + } + } catch { + Write-Host "Warning: Could not compare versions, proceeding with installation" + } + } + $msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi" $url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi" Write-Host "Downloading from: $url" - Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..." - if (-not (Invoke-WebRequest -Uri $url -OutFile $msi -UseBasicParsing -PassThru)) { Write-Host "Error: Failed to download PowerShell package" exit 1 } - Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait + + Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..." + + if ($isDowngrade) { + # For downgrades, use force reinstall to overwrite the existing version + Write-Host "Using force reinstall for downgrade scenario..." + Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait + } else { + # For upgrades or fresh installs, use regular install + Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait + } Write-Host "Installation complete. PowerShell [$($env:REQUESTED_VERSION)] is now available." From b28e25d9e3b69c9e4abe26df4649d23859fef29c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Jun 2025 08:23:51 +0000 Subject: [PATCH 03/10] Add downgrade test case to validate Windows PowerShell downgrade functionality Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- .github/workflows/Action-Test.yml | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 25565a8..0e4ce56 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -65,3 +65,42 @@ jobs: if ($installed -ne $requested) { throw "Failed: expected $requested but got $installed" } + + ActionTestDowngrade: + runs-on: windows-latest + name: 'Windows Downgrade Test - 7.5.0 → 7.4.7' + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + # First install a higher version (7.5.0) + - name: Install PowerShell 7.5.0 + uses: ./ + with: + Version: 7.5.0 + + - name: Verify 7.5.0 is installed + shell: pwsh + run: | + $installed = ($PSVersionTable.PSVersion).ToString() + Write-Host "Installed PowerShell version: $installed" + if ($installed -ne "7.5.0") { + throw "Failed: expected 7.5.0 but got $installed" + } + Write-Host "7.5.0 installation verified" + + # Now try to downgrade to a lower version (7.4.7) + - name: Downgrade to PowerShell 7.4.7 + uses: ./ + with: + Version: 7.4.7 + + - name: Verify 7.4.7 is installed (downgrade test) + shell: pwsh + run: | + $installed = ($PSVersionTable.PSVersion).ToString() + Write-Host "Installed PowerShell version: $installed" + if ($installed -ne "7.4.7") { + throw "Failed: expected 7.4.7 but got $installed (downgrade failed)" + } + Write-Host "Downgrade test PASSED!" From f646cd37a1b71b8f0224bb4d7fe7af98b6d87299 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Jun 2025 14:46:28 +0000 Subject: [PATCH 04/10] Simplify Windows installation to use msiexec /f for all scenarios Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- action.yml | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/action.yml b/action.yml index fd97f09..3c23f61 100644 --- a/action.yml +++ b/action.yml @@ -204,23 +204,6 @@ runs: exit 0 } - # Check if we need to handle a downgrade scenario - $isDowngrade = $false - if ($detected -and $detected -ne $env:REQUESTED_VERSION) { - try { - $detectedVersion = [version]$detected - $requestedVersion = [version]$env:REQUESTED_VERSION - if ($detectedVersion -gt $requestedVersion) { - Write-Host "Downgrade detected: $detected → $($env:REQUESTED_VERSION)" - $isDowngrade = $true - } else { - Write-Host "Upgrade detected: $detected → $($env:REQUESTED_VERSION)" - } - } catch { - Write-Host "Warning: Could not compare versions, proceeding with installation" - } - } - $msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi" $url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi" Write-Host "Downloading from: $url" @@ -231,14 +214,6 @@ runs: } Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..." - - if ($isDowngrade) { - # For downgrades, use force reinstall to overwrite the existing version - Write-Host "Using force reinstall for downgrade scenario..." - Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait - } else { - # For upgrades or fresh installs, use regular install - Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait - } + Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait Write-Host "Installation complete. PowerShell [$($env:REQUESTED_VERSION)] is now available." From 88f6b91969e73850680a3e5bc37564a186f4e336 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 14 Jun 2025 16:52:09 +0200 Subject: [PATCH 05/10] qwe --- .github/workflows/Action-Test.yml | 39 ------------------------------- 1 file changed, 39 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 0e4ce56..25565a8 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -65,42 +65,3 @@ jobs: if ($installed -ne $requested) { throw "Failed: expected $requested but got $installed" } - - ActionTestDowngrade: - runs-on: windows-latest - name: 'Windows Downgrade Test - 7.5.0 → 7.4.7' - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - # First install a higher version (7.5.0) - - name: Install PowerShell 7.5.0 - uses: ./ - with: - Version: 7.5.0 - - - name: Verify 7.5.0 is installed - shell: pwsh - run: | - $installed = ($PSVersionTable.PSVersion).ToString() - Write-Host "Installed PowerShell version: $installed" - if ($installed -ne "7.5.0") { - throw "Failed: expected 7.5.0 but got $installed" - } - Write-Host "7.5.0 installation verified" - - # Now try to downgrade to a lower version (7.4.7) - - name: Downgrade to PowerShell 7.4.7 - uses: ./ - with: - Version: 7.4.7 - - - name: Verify 7.4.7 is installed (downgrade test) - shell: pwsh - run: | - $installed = ($PSVersionTable.PSVersion).ToString() - Write-Host "Installed PowerShell version: $installed" - if ($installed -ne "7.4.7") { - throw "Failed: expected 7.4.7 but got $installed (downgrade failed)" - } - Write-Host "Downgrade test PASSED!" From 00a357abacf65452fa0864b5c4514eb31254cab9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Jun 2025 15:07:55 +0000 Subject: [PATCH 06/10] Implement version comparison logic for Windows PowerShell downgrade detection Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- action.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 3c23f61..c83610f 100644 --- a/action.yml +++ b/action.yml @@ -204,6 +204,23 @@ runs: exit 0 } + # Check if we need to handle a downgrade scenario + $isDowngrade = $false + if ($detected -and $detected -ne $env:REQUESTED_VERSION) { + try { + $detectedVersion = [version]$detected + $requestedVersion = [version]$env:REQUESTED_VERSION + if ($detectedVersion -gt $requestedVersion) { + Write-Host "Downgrade detected: $detected → $($env:REQUESTED_VERSION)" + $isDowngrade = $true + } else { + Write-Host "Upgrade detected: $detected → $($env:REQUESTED_VERSION)" + } + } catch { + Write-Host "Warning: Could not compare versions, proceeding with regular installation" + } + } + $msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi" $url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi" Write-Host "Downloading from: $url" @@ -214,6 +231,14 @@ runs: } Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..." - Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait + + if ($isDowngrade) { + # For downgrades, use force reinstall to overwrite the existing version + Write-Host "Using force reinstall for downgrade scenario..." + Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait + } else { + # For upgrades or fresh installs, use regular install + Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait + } Write-Host "Installation complete. PowerShell [$($env:REQUESTED_VERSION)] is now available." From 3fe7f7d83ff8df2e72912f4a23fe2d72f81121bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Jun 2025 15:20:01 +0000 Subject: [PATCH 07/10] Add REINSTALL=a parameter to msiexec for Windows PowerShell downgrades Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- .github/workflows/Action-Test.yml | 39 +++++++++++++++++++++++++++++++ action.yml | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 25565a8..0e4ce56 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -65,3 +65,42 @@ jobs: if ($installed -ne $requested) { throw "Failed: expected $requested but got $installed" } + + ActionTestDowngrade: + runs-on: windows-latest + name: 'Windows Downgrade Test - 7.5.0 → 7.4.7' + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + # First install a higher version (7.5.0) + - name: Install PowerShell 7.5.0 + uses: ./ + with: + Version: 7.5.0 + + - name: Verify 7.5.0 is installed + shell: pwsh + run: | + $installed = ($PSVersionTable.PSVersion).ToString() + Write-Host "Installed PowerShell version: $installed" + if ($installed -ne "7.5.0") { + throw "Failed: expected 7.5.0 but got $installed" + } + Write-Host "7.5.0 installation verified" + + # Now try to downgrade to a lower version (7.4.7) + - name: Downgrade to PowerShell 7.4.7 + uses: ./ + with: + Version: 7.4.7 + + - name: Verify 7.4.7 is installed (downgrade test) + shell: pwsh + run: | + $installed = ($PSVersionTable.PSVersion).ToString() + Write-Host "Installed PowerShell version: $installed" + if ($installed -ne "7.4.7") { + throw "Failed: expected 7.4.7 but got $installed (downgrade failed)" + } + Write-Host "Downgrade test PASSED!" diff --git a/action.yml b/action.yml index c83610f..17a6417 100644 --- a/action.yml +++ b/action.yml @@ -235,7 +235,7 @@ runs: if ($isDowngrade) { # For downgrades, use force reinstall to overwrite the existing version Write-Host "Using force reinstall for downgrade scenario..." - Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait + Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart', 'REINSTALL=a' -Wait } else { # For upgrades or fresh installs, use regular install Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait From 55afe33c3a1b7925c9b51d727c282e963f947505 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Jun 2025 16:20:07 +0000 Subject: [PATCH 08/10] Implement uninstall-then-install approach for Windows PowerShell downgrades Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> --- action.yml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 17a6417..5280129 100644 --- a/action.yml +++ b/action.yml @@ -233,9 +233,32 @@ runs: Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..." if ($isDowngrade) { - # For downgrades, use force reinstall to overwrite the existing version - Write-Host "Using force reinstall for downgrade scenario..." - Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart', 'REINSTALL=a' -Wait + # For downgrades, uninstall the existing version first, then install the new one + Write-Host "Downgrade detected - uninstalling existing PowerShell version first..." + + # Find PowerShell installation to uninstall + $uninstallString = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction SilentlyContinue | + Where-Object { $_.DisplayName -like "*PowerShell*" -and $_.Publisher -eq "Microsoft Corporation" } | + Select-Object -First 1 -ExpandProperty UninstallString + + if ($uninstallString) { + Write-Host "Found existing PowerShell installation, uninstalling..." + # Extract the product code from the uninstall string + if ($uninstallString -match '{[0-9A-F-]+}') { + $productCode = $matches[0] + Write-Host "Uninstalling PowerShell with product code: $productCode" + Start-Process msiexec.exe -ArgumentList '/x', $productCode, '/quiet', '/norestart' -Wait + Write-Host "Uninstall completed" + } else { + Write-Host "Warning: Could not extract product code from uninstall string: $uninstallString" + } + } else { + Write-Host "Warning: Could not find PowerShell installation to uninstall" + } + + # Now install the new version + Write-Host "Installing PowerShell [$($env:REQUESTED_VERSION)]..." + Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait } else { # For upgrades or fresh installs, use regular install Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait From c03a8764ff7e5e405285e2969e3161099a127e65 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 14 Jun 2025 23:55:08 +0200 Subject: [PATCH 09/10] Refactor installation logic for PowerShell across platforms to skip installation if the requested version is already installed --- action.yml | 120 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 51 deletions(-) diff --git a/action.yml b/action.yml index 5280129..b79cc2d 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,6 @@ name: Install PowerShell description: | - Install a specific version —or the latest stable version— of PowerShell Core + Install a specific version, or the latest stable version, of PowerShell Core on any GitHub runner (Linux, macOS, Windows). Skips the install if the requested version is already present. author: PSModule @@ -29,7 +29,6 @@ runs: run: | # Install-PowerShell set -e - echo "Requested version: [$REQUESTED_VERSION]" # Only resolve to latest version if explicitly set to 'latest' (case-insensitive) @@ -73,30 +72,26 @@ runs: URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${DEB_NAME}" echo "Downloading from: $URL" wget -q "$URL" -O "$DEB_NAME" - echo "Starting installation of PowerShell [$REQUESTED_VERSION)]..." + echo "Starting installation of PowerShell [$REQUESTED_VERSION]..." sudo dpkg -i "$DEB_NAME" || sudo apt-get -f install -y - echo "Installation complete. PowerShell [$REQUESTED_VERSION] is now available." elif command -v rpm >/dev/null; then # RHEL/Fedora/CentOS based echo "Detected RHEL/Fedora/CentOS based system..." - if [[ "$ARCH" == "aarch64" ]]; then RPM_NAME="powershell-${REQUESTED_VERSION}-1.rh.${ARCH}.rpm" else RPM_NAME="powershell-${REQUESTED_VERSION}-1.rh.x86_64.rpm" fi - URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${RPM_NAME}" echo "Downloading from: $URL" wget -q "$URL" -O "$RPM_NAME" - echo "Starting installation of PowerShell [$REQUESTED_VERSION)]..." + echo "Starting installation of PowerShell [$REQUESTED_VERSION]..." sudo rpm -i "$RPM_NAME" || sudo yum install -y "$RPM_NAME" - echo "Installation complete. PowerShell [$REQUESTED_VERSION] is now available." else echo "Unsupported Linux distribution. Cannot determine package format." exit 1 fi - echo "PowerShell [$REQUESTED_VERSION] installed successfully." + echo "Installation complete. PowerShell [$REQUESTED_VERSION] is now available." - name: Install PowerShell (macOS) if: runner.os == 'macOS' @@ -108,7 +103,6 @@ runs: run: | # Install-PowerShell set -e - echo "Requested version: [$REQUESTED_VERSION]" # Only resolve to latest version if explicitly set to 'latest' (case-insensitive) @@ -151,7 +145,6 @@ runs: URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${PKG_NAME}" echo "Downloading from: $URL" - echo "Starting installation of PowerShell [$REQUESTED_VERSION]..." if ! curl -sSL "$URL" -o "$PKG_NAME"; then @@ -159,7 +152,6 @@ runs: exit 1 fi sudo installer -pkg "$PKG_NAME" -target / - echo "Installation complete. PowerShell [$REQUESTED_VERSION] is now available." - name: Install PowerShell (Windows) @@ -173,7 +165,7 @@ runs: # Install-PowerShell Write-Host "Requested version: [$env:REQUESTED_VERSION]" - # Only resolve to latest version if explicitly set to 'latest' (case-insensitive) + # Resolve 'latest' → concrete version $req = $env:REQUESTED_VERSION if ($req -and $req.Trim().ToLower() -eq 'latest') { $latest = ( @@ -191,12 +183,13 @@ runs: exit 1 } + # Detect currently installed version (if any) + $detected = $null try { $detected = (pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()') Write-Host "Currently installed PowerShell version: $detected" } catch { Write-Host "PowerShell is not currently installed" - $detected = $null } if ($detected -eq $env:REQUESTED_VERSION) { @@ -204,11 +197,11 @@ runs: exit 0 } - # Check if we need to handle a downgrade scenario + # Downgrade detection $isDowngrade = $false if ($detected -and $detected -ne $env:REQUESTED_VERSION) { try { - $detectedVersion = [version]$detected + $detectedVersion = [version]$detected $requestedVersion = [version]$env:REQUESTED_VERSION if ($detectedVersion -gt $requestedVersion) { Write-Host "Downgrade detected: $detected → $($env:REQUESTED_VERSION)" @@ -221,47 +214,72 @@ runs: } } + # If downgrade → fully uninstall current PowerShell 7 + if ($isDowngrade) { + Write-Host "Uninstalling existing PowerShell version before downgrade..." + + # Search both 64-bit and 32-bit uninstall hives + $regPaths = @( + 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', + 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' + ) + + $pwshEntries = Get-ItemProperty -Path $regPaths -ErrorAction SilentlyContinue | + Where-Object { + $_.Publisher -eq 'Microsoft Corporation' -and + $_.DisplayName -like 'PowerShell 7*' -and + $_.DisplayName -notlike '*Preview*' -and + $_.DisplayVersion -and + $_.DisplayVersion.StartsWith($detected) + } + + $targetEntry = $pwshEntries | Select-Object -First 1 + if (-not $targetEntry) { + Write-Host "Warning: Could not find an uninstall entry for PowerShell $detected" + } else { + $uninstallCmd = if ($targetEntry.QuietUninstallString) { + $targetEntry.QuietUninstallString + } else { + $targetEntry.UninstallString + } + + # If the uninstall command is MSI-based and lacks /quiet, add it + if ($uninstallCmd -match 'msiexec') { + if ($uninstallCmd -notmatch '/quiet') { $uninstallCmd += ' /quiet' } + if ($uninstallCmd -notmatch '/norestart') { $uninstallCmd += ' /norestart' } + } + + Write-Host "Running uninstall command:`n$uninstallCmd" + $proc = Start-Process 'cmd.exe' -ArgumentList '/c', $uninstallCmd -Wait -PassThru + if ($proc.ExitCode -ne 0) { + Write-Host "Error: Uninstall failed (exit code $($proc.ExitCode))." + exit 1 + } + + # Double-check removal + try { + $after = (pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()') + if ($after) { + Write-Host "Error: PowerShell is still present ($after) after uninstall. Aborting downgrade." + exit 1 + } + } catch { } + } + } + + # Download requested MSI $msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi" $url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi" Write-Host "Downloading from: $url" - if (-not (Invoke-WebRequest -Uri $url -OutFile $msi -UseBasicParsing -PassThru)) { - Write-Host "Error: Failed to download PowerShell package" - exit 1 - } + $null = Invoke-WebRequest -Uri $url -OutFile $msi -UseBasicParsing -ErrorAction Stop + # Install requested version Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..." - - if ($isDowngrade) { - # For downgrades, uninstall the existing version first, then install the new one - Write-Host "Downgrade detected - uninstalling existing PowerShell version first..." - - # Find PowerShell installation to uninstall - $uninstallString = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction SilentlyContinue | - Where-Object { $_.DisplayName -like "*PowerShell*" -and $_.Publisher -eq "Microsoft Corporation" } | - Select-Object -First 1 -ExpandProperty UninstallString - - if ($uninstallString) { - Write-Host "Found existing PowerShell installation, uninstalling..." - # Extract the product code from the uninstall string - if ($uninstallString -match '{[0-9A-F-]+}') { - $productCode = $matches[0] - Write-Host "Uninstalling PowerShell with product code: $productCode" - Start-Process msiexec.exe -ArgumentList '/x', $productCode, '/quiet', '/norestart' -Wait - Write-Host "Uninstall completed" - } else { - Write-Host "Warning: Could not extract product code from uninstall string: $uninstallString" - } - } else { - Write-Host "Warning: Could not find PowerShell installation to uninstall" - } - - # Now install the new version - Write-Host "Installing PowerShell [$($env:REQUESTED_VERSION)]..." - Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait - } else { - # For upgrades or fresh installs, use regular install - Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait + $msiProcess = Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait -PassThru + if ($msiProcess.ExitCode -ne 0) { + Write-Host "Error: Installation failed (exit code $($msiProcess.ExitCode))." + exit 1 } Write-Host "Installation complete. PowerShell [$($env:REQUESTED_VERSION)] is now available." From 3be96a931e8bea12ee25f318f6758a07476e1ea9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 15 Jun 2025 00:00:42 +0200 Subject: [PATCH 10/10] Fix --- .github/workflows/Action-Test.yml | 39 ------------------------------- 1 file changed, 39 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 0e4ce56..25565a8 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -65,42 +65,3 @@ jobs: if ($installed -ne $requested) { throw "Failed: expected $requested but got $installed" } - - ActionTestDowngrade: - runs-on: windows-latest - name: 'Windows Downgrade Test - 7.5.0 → 7.4.7' - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - # First install a higher version (7.5.0) - - name: Install PowerShell 7.5.0 - uses: ./ - with: - Version: 7.5.0 - - - name: Verify 7.5.0 is installed - shell: pwsh - run: | - $installed = ($PSVersionTable.PSVersion).ToString() - Write-Host "Installed PowerShell version: $installed" - if ($installed -ne "7.5.0") { - throw "Failed: expected 7.5.0 but got $installed" - } - Write-Host "7.5.0 installation verified" - - # Now try to downgrade to a lower version (7.4.7) - - name: Downgrade to PowerShell 7.4.7 - uses: ./ - with: - Version: 7.4.7 - - - name: Verify 7.4.7 is installed (downgrade test) - shell: pwsh - run: | - $installed = ($PSVersionTable.PSVersion).ToString() - Write-Host "Installed PowerShell version: $installed" - if ($installed -ne "7.4.7") { - throw "Failed: expected 7.4.7 but got $installed (downgrade failed)" - } - Write-Host "Downgrade test PASSED!"