Skip to content

Commit f98a136

Browse files
committed
docs: enhance Windows documentation with retry logic and headers
1 parent 5c81283 commit f98a136

1 file changed

Lines changed: 65 additions & 11 deletions

File tree

docs/windows

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,76 @@ $version = if ($Version) {
7171
if ($version -eq "latest") {
7272
try {
7373
Write-Host "[INFO] Fetching latest version from GitHub..."
74-
$latestRelease = Invoke-RestMethod -Uri "$githubApiUrl/releases/latest" -UseBasicParsing -ErrorAction Stop
75-
$version = $latestRelease.tag_name
76-
Write-Host "[INFO] Latest version: $version"
74+
75+
# Create headers to avoid 403 errors
76+
$headers = @{
77+
'User-Agent' = 'AgbCloud-CLI-Installer/1.0 PowerShell'
78+
'Accept' = 'application/vnd.github.v3+json'
79+
}
80+
81+
# Add timeout and retry logic
82+
$maxRetries = 3
83+
$retryDelay = 2
84+
85+
for ($i = 1; $i -le $maxRetries; $i++) {
86+
try {
87+
Write-Host "[INFO] Attempt $i/$maxRetries to fetch latest release..."
88+
$latestRelease = Invoke-RestMethod -Uri "$githubApiUrl/releases/latest" -Headers $headers -TimeoutSec 30 -ErrorAction Stop
89+
$version = $latestRelease.tag_name
90+
Write-Host "[INFO] Latest version: $version"
91+
break
92+
} catch {
93+
if ($i -eq $maxRetries) {
94+
throw $_
95+
}
96+
Write-Host "[WARN] Attempt $i failed: $($_.Exception.Message). Retrying in $retryDelay seconds..."
97+
Start-Sleep -Seconds $retryDelay
98+
$retryDelay *= 2 # Exponential backoff
99+
}
100+
}
77101
} catch {
78102
Write-Host "[WARN] Could not fetch latest version, trying to get available releases..."
79103
try {
80104
# Try to get all releases and pick the latest available version
81105
Write-Host "[INFO] Trying to fetch all releases..."
82-
$allReleases = Invoke-RestMethod -Uri "$githubApiUrl/releases" -UseBasicParsing -ErrorAction Stop
83-
if ($allReleases -and $allReleases.Count -gt 0) {
84-
# Always use the latest (first) release
85-
$version = $allReleases[0].tag_name
86-
Write-Host "[INFO] Found $($allReleases.Count) release(s), using latest: $version"
87-
} else {
88-
Write-Host "[WARN] No releases found in repository, using fallback v1.0.0"
89-
$version = "v1.0.0"
106+
107+
# Create headers for the fallback request
108+
$headers = @{
109+
'User-Agent' = 'AgbCloud-CLI-Installer/1.0 PowerShell'
110+
'Accept' = 'application/vnd.github.v3+json'
111+
}
112+
113+
# Retry logic for all releases
114+
for ($i = 1; $i -le 3; $i++) {
115+
try {
116+
Write-Host "[INFO] Attempt $i/3 to fetch all releases..."
117+
$allReleases = Invoke-RestMethod -Uri "$githubApiUrl/releases" -Headers $headers -TimeoutSec 30 -ErrorAction Stop
118+
if ($allReleases -and $allReleases.Count -gt 0) {
119+
# Always use the latest (first) release
120+
$version = $allReleases[0].tag_name
121+
Write-Host "[INFO] Found $($allReleases.Count) release(s), using latest: $version"
122+
break
123+
} else {
124+
Write-Host "[WARN] No releases found in repository, using fallback v1.0.0"
125+
$version = "v1.0.0"
126+
break
127+
}
128+
} catch {
129+
if ($i -eq 3) {
130+
Write-Host "[ERROR] Could not fetch release information after 3 attempts: $($_.Exception.Message)"
131+
Write-Host "[INFO] API URL attempted: $githubApiUrl/releases"
132+
Write-Host "[INFO] This might be due to:"
133+
Write-Host " • GitHub API rate limiting (try again later)"
134+
Write-Host " • Network connectivity issues"
135+
Write-Host " • Firewall or proxy restrictions"
136+
Write-Host " • Geographic access restrictions"
137+
Write-Host "[WARN] Using fallback version v1.0.0"
138+
$version = "v1.0.0"
139+
break
140+
}
141+
Write-Host "[WARN] Attempt $i failed, retrying..."
142+
Start-Sleep -Seconds 2
143+
}
90144
}
91145
} catch {
92146
Write-Host "[ERROR] Could not fetch release information: $($_.Exception.Message)"

0 commit comments

Comments
 (0)