Skip to content

Commit dcc3a92

Browse files
retry windows install
1 parent 4146fa5 commit dcc3a92

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

.github/workflows/scripts/windows/swift/install-swift.ps1

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,72 @@
99
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
##
1111
##===----------------------------------------------------------------------===##
12+
13+
# Retry configuration
14+
$MaxRetries = 5
15+
$RetryDelay = 5
16+
17+
function Invoke-WebRequestWithRetry {
18+
param (
19+
[string]$Uri,
20+
[string]$OutFile,
21+
[int]$TimeoutSec = 300
22+
)
23+
24+
$attempt = 1
25+
26+
while ($attempt -le $MaxRetries) {
27+
try {
28+
if ($attempt -gt 1) {
29+
Write-Host "Retry attempt $attempt of $MaxRetries after ${RetryDelay}s delay..."
30+
Start-Sleep -Seconds $RetryDelay
31+
}
32+
33+
# Use -Resume to support partial downloads if the connection drops
34+
Invoke-WebRequest -Uri $Uri -OutFile $OutFile -TimeoutSec $TimeoutSec -UseBasicParsing
35+
36+
Write-Host "Download completed successfully"
37+
return $true
38+
}
39+
catch {
40+
Write-Host "Download failed on attempt $attempt`: $($_.Exception.Message)"
41+
42+
# Clean up partial download if it exists
43+
if (Test-Path $OutFile) {
44+
Remove-Item -Force $OutFile -ErrorAction SilentlyContinue
45+
}
46+
47+
if ($attempt -eq $MaxRetries) {
48+
Write-Host "Download failed after $MaxRetries attempts"
49+
throw
50+
}
51+
}
52+
53+
$attempt++
54+
}
55+
56+
return $false
57+
}
58+
1259
function Install-Swift {
1360
param (
1461
[string]$Url,
1562
[string]$Sha256
1663
)
1764
Set-Variable ErrorActionPreference Stop
1865
Set-Variable ProgressPreference SilentlyContinue
19-
Write-Host -NoNewLine ('Downloading {0} ... ' -f $url)
20-
Invoke-WebRequest -Uri $url -OutFile installer.exe
21-
Write-Host 'SUCCESS'
66+
67+
Write-Host "Downloading $Url ... "
68+
69+
try {
70+
Invoke-WebRequestWithRetry -Uri $Url -OutFile installer.exe
71+
Write-Host 'SUCCESS'
72+
}
73+
catch {
74+
Write-Host "FAILED: $($_.Exception.Message)"
75+
exit 1
76+
}
77+
2278
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $Sha256)
2379
$Hash = Get-FileHash installer.exe -Algorithm sha256
2480
if ($Hash.Hash -eq $Sha256 -or $Sha256 -eq "") {

0 commit comments

Comments
 (0)