Skip to content

Commit 63b8b4d

Browse files
authored
fix(install): fail the PowerShell installer when the version check exits non-zero (#2391)
1 parent f455e8e commit 63b8b4d

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

packages/docs-web/public/install.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ function Main {
284284
Write-Info "Verifying installation..."
285285
try {
286286
$versionOutput = & $destBinary version 2>&1
287+
if ($LASTEXITCODE -ne 0) {
288+
Write-Err "Installed binary failed its version check (exit $LASTEXITCODE):"
289+
Write-Host $versionOutput
290+
exit 1
291+
}
287292
Write-Host $versionOutput
288293
Write-Ok "Installation complete!"
289294
} catch {

scripts/install.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ function Main {
284284
Write-Info "Verifying installation..."
285285
try {
286286
$versionOutput = & $destBinary version 2>&1
287+
if ($LASTEXITCODE -ne 0) {
288+
Write-Err "Installed binary failed its version check (exit $LASTEXITCODE):"
289+
Write-Host $versionOutput
290+
exit 1
291+
}
287292
Write-Host $versionOutput
288293
Write-Ok "Installation complete!"
289294
} catch {

scripts/test-install.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ assert_equals() {
2020
[ "$expected" = "$actual" ] || fail "$description: expected $expected, got $actual"
2121
}
2222

23+
assert_powershell_version_guard() {
24+
local powershell_installer="$1"
25+
26+
awk '
27+
/# --- Verify installation ---/ { in_verification = 1; next }
28+
/# --- Getting started ---/ { exit }
29+
!in_verification { next }
30+
/\$versionOutput = & \$destBinary version 2>&1/ { invoked = 1; next }
31+
invoked && /if \(\$LASTEXITCODE -ne 0\)/ { guarded = 1; next }
32+
guarded && /exit 1/ { exits_on_failure = 1; next }
33+
exits_on_failure && /Write-Ok "Installation complete!"/ { reports_success = 1 }
34+
END {
35+
exit !(invoked && guarded && exits_on_failure && reports_success)
36+
}
37+
' "$powershell_installer" \
38+
|| fail "PowerShell installer must fail a non-zero version check before reporting success"
39+
}
40+
2341
make_platform_mocks() {
2442
local os="$1"
2543
local arch="$2"
@@ -137,6 +155,7 @@ cmp -s "$installer" "$repo_root/packages/docs-web/public/install" \
137155
# PATH-corrupting installer to Windows users while the repo copy was fixed. #2339.
138156
cmp -s "$repo_root/scripts/install.ps1" "$repo_root/packages/docs-web/public/install.ps1" \
139157
|| fail "public install.ps1 mirror differs from scripts/install.ps1"
158+
assert_powershell_version_guard "$repo_root/scripts/install.ps1"
140159

141160
mock_dir="$tmp_dir/install-mocks"
142161
install_dir="$tmp_dir/install-bin"

0 commit comments

Comments
 (0)