Skip to content

Commit 8cb06b9

Browse files
authored
Merge branch 'main' into dependabot/bun/knip-6.1.0
2 parents a97ecb1 + 2cbcb6f commit 8cb06b9

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

install.ps1

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ if ($Version -eq "latest") {
109109
try {
110110
$Response = Invoke-RestMethod -Uri $ApiUrl -Headers @{ "Accept" = "application/vnd.github.v3+json" }
111111
$Tag = $Response.tag_name
112+
$ReleaseAssets = $Response.assets | ForEach-Object { $_.name }
112113
} catch {
113114
Write-Output "Install Failed:"
114115
Write-Output " Could not determine the latest release from the GitHub API."
@@ -118,6 +119,18 @@ if ($Version -eq "latest") {
118119
}
119120
} else {
120121
$Tag = $Version
122+
$ApiUrl = "https://api.github.com/repos/${Repo}/releases/tags/${Tag}"
123+
124+
try {
125+
$Response = Invoke-RestMethod -Uri $ApiUrl -Headers @{ "Accept" = "application/vnd.github.v3+json" }
126+
$ReleaseAssets = $Response.assets | ForEach-Object { $_.name }
127+
} catch {
128+
# GitHub API unreachable (blocked, rate-limited, …) — fall back to probing
129+
# candidate artifacts directly with curl.exe HEAD requests. curl.exe ships
130+
# with Windows 10 1803+ and is already used for the binary download below.
131+
Write-Output " GitHub API unavailable ($ApiUrl); falling back to direct artifact probing..."
132+
$ReleaseAssets = $null
133+
}
121134
}
122135

123136
# ── Resolve artifact name with automatic x64 fallback ────────────────────────
@@ -127,6 +140,12 @@ if ($Version -eq "latest") {
127140
# github-code-search-windows-x64-baseline.exe — compatible with any x86-64 CPU
128141
# github-code-search-windows-x64.exe — legacy alias kept for back-compat
129142
# github-code-search-windows-arm64.exe — ARM64
143+
#
144+
# Artifact availability is checked against the GitHub release asset list already
145+
# fetched above — no extra network request needed, and no Invoke-WebRequest
146+
# which triggers a security warning on Windows PowerShell 5.1.
147+
# When the API was unreachable ($ReleaseAssets is $null), we fall back to
148+
# probing candidate URLs with curl.exe HEAD requests instead.
130149

131150
$CandidateTargets = @($Target)
132151
if ($Target -eq "x64-modern") {
@@ -139,22 +158,30 @@ if ($Target -eq "x64-modern") {
139158
$Artifact = $null
140159
foreach ($Candidate in $CandidateTargets) {
141160
$CandidateArtifact = "${BinaryName}-windows-${Candidate}.exe"
142-
$CheckUrl = "https://github.com/${Repo}/releases/download/${Tag}/${CandidateArtifact}"
143-
try {
144-
# -UseBasicParsing is removed in PowerShell 6+ (pwsh); omit it for compat.
145-
$Null = Invoke-WebRequest -Uri $CheckUrl -Method Head -ErrorAction Stop
161+
$Found = $false
162+
if ($null -ne $ReleaseAssets) {
163+
$Found = $ReleaseAssets -contains $CandidateArtifact
164+
} else {
165+
# Fallback: probe via curl.exe HEAD (no Invoke-WebRequest, no PS5.1 warning).
166+
$CheckUrl = "https://github.com/${Repo}/releases/download/${Tag}/${CandidateArtifact}"
167+
$null = curl.exe -fsI $CheckUrl 2>$null
168+
$Found = $LASTEXITCODE -eq 0
169+
}
170+
if ($Found) {
146171
$Artifact = $CandidateArtifact
147172
$Target = $Candidate
148173
break
149-
} catch {
150-
Write-Output " Variant windows-${Candidate} not found in release ${Tag}, trying next..."
151174
}
152175
}
153176

154177
if ($null -eq $Artifact) {
178+
$AvailableWindows = if ($null -ne $ReleaseAssets) { $ReleaseAssets | Where-Object { $_ -like "*windows*" } } else { @() }
155179
Write-Output "Install Failed:"
156180
Write-Output " No compatible Windows binary found for ${Tag}."
157181
Write-Output " Tried: $($CandidateTargets -join ', ')"
182+
if ($AvailableWindows) {
183+
Write-Output " Available Windows assets: $($AvailableWindows -join ', ')"
184+
}
158185
exit 1
159186
}
160187

0 commit comments

Comments
 (0)