Skip to content

Commit 8688e56

Browse files
fix: Always verify via subprocess on Windows and prepend install dir to GITHUB_PATH
After MSI install on Windows, the running shell may still resolve the pre-installed pwsh from PATH. Two fixes: 1. action.yml: Append the install directory to GITHUB_PATH so that subsequent 'shell: pwsh' steps in the consumer's workflow resolve to the version we just installed (critical for preview builds whose 7-preview dir is not on the runner's default PATH, but also defensive for stable upgrades). 2. Action-Test.yml: Verification step now always launches pwsh from the known install directory on Windows (both stable and prerelease), instead of relying on $PSVersionTable from the current shell.
1 parent eb32a65 commit 8688e56

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

.github/workflows/Action-Test.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,19 @@ jobs:
7171
Write-Host "Resolved 'latest' → $requested"
7272
}
7373
74-
# For prerelease versions on Windows, launch the installed pwsh to get the version
75-
# because the current shell may not be the version we just installed.
76-
$isPrerelease = $requested -match '-'
77-
if ($IsWindows -and $isPrerelease) {
74+
# On Windows, always verify by launching pwsh from the known install directory.
75+
# This avoids relying on PATH resolution, which may still point to the pre-installed
76+
# version if the runner's environment hasn't refreshed after the MSI install.
77+
if ($IsWindows) {
78+
$isPrerelease = $requested -match '-'
7879
$majorVersion = ($requested -split '[\.-]')[0]
79-
$installDir = "$majorVersion-preview"
80+
$installDir = if ($isPrerelease) { "$majorVersion-preview" } else { $majorVersion }
8081
$pwshPath = "$env:ProgramFiles\PowerShell\$installDir\pwsh.exe"
82+
Write-Host "Windows: verifying via subprocess at $pwshPath"
8183
if (Test-Path $pwshPath) {
8284
$installed = (& $pwshPath -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()')
8385
} else {
86+
Write-Host "Warning: Expected pwsh not found at $pwshPath, falling back to `$PSVersionTable"
8487
$installed = ($PSVersionTable.PSVersion).ToString()
8588
}
8689
} else {

action.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,19 @@ runs:
332332
}
333333
334334
Write-Host "Installation complete. PowerShell [$($env:REQUESTED_VERSION)] is now available."
335+
336+
# Add the install directory to GITHUB_PATH so subsequent `shell: pwsh` steps
337+
# resolve to the version we just installed — even for preview builds whose
338+
# install directory (7-preview) is not on the runner's default PATH.
339+
$isPrerelease = $env:REQUESTED_VERSION -match '-'
340+
$installDir = if ($isPrerelease) {
341+
"$env:ProgramFiles\PowerShell\7-preview"
342+
} else {
343+
"$env:ProgramFiles\PowerShell\7"
344+
}
345+
if (Test-Path $installDir) {
346+
Write-Host "Adding install directory to GITHUB_PATH: $installDir"
347+
Add-Content -Path $env:GITHUB_PATH -Value $installDir
348+
} else {
349+
Write-Host "Warning: Expected install directory not found: $installDir"
350+
}

0 commit comments

Comments
 (0)