@@ -68,33 +68,44 @@ runs:
68
68
$setupExe = "$vol\setup.exe"
69
69
$setupFileName = "setup-$platform.exe"
70
70
71
- $maxRetries = 5
72
- $retryCount = 0
73
- $success = $false
74
- $delay = 2
75
-
76
- while (-not $success -and $retryCount -lt $maxRetries) {
77
- try {
78
- Invoke-WebRequest -Uri "https://cygwin.com/$setupFileName" -OutFile $setupExe
79
- $success = $true
80
- } catch {
81
- Write-Output "Attempt $($retryCount + 1) failed. Retrying..."
82
- Start-Sleep -Seconds $delay
83
- $retryCount++
84
- $delay += $delay
71
+ function Invoke-WebRequest-With-Retry {
72
+ param (
73
+ $Uri,
74
+ $OutFile
75
+ )
76
+
77
+ $maxRetries = 5
78
+ $retryCount = 0
79
+ $success = $false
80
+ $delay = 2
81
+
82
+ while (-not $success -and $retryCount -lt $maxRetries) {
83
+ try {
84
+ Invoke-WebRequest -Uri $Uri -OutFile $OutFile
85
+ $success = $true
86
+ } catch [System.Net.WebException] {
87
+ Write-Output "Attempt $($retryCount + 1) failed. Retrying..."
88
+ Start-Sleep -Seconds $delay
89
+ $retryCount++
90
+ $delay += $delay
91
+ }
85
92
}
86
- }
87
93
88
- if (-not $success) {
89
- throw "Failed to download $setupFileName after $maxRetries attempts."
94
+ if (-not $success) {
95
+ throw "Failed to download $setupFileName after $maxRetries attempts."
96
+ }
90
97
}
91
98
99
+ Invoke-WebRequest-With-Retry "https://cygwin.com/$setupFileName" $setupExe
100
+
92
101
if ((Get-Item -LiteralPath $setupExe).Length -eq 0) {
93
102
throw "The downloaded setup has a zero length!"
94
103
}
95
104
96
105
if ('${{ inputs.check-hash }}' -eq 'true') {
97
- $expectedHashLines = $(Invoke-WebRequest -Uri https://cygwin.com/sha512.sum).ToString() -split "`n"
106
+ $hashFile = "$vol\sha512.sum"
107
+ Invoke-WebRequest-With-Retry https://cygwin.com/sha512.sum $hashFile
108
+ $expectedHashLines = Get-Content $hashFile
98
109
$expectedHash = ''
99
110
foreach ($expectedHashLine in $expectedHashLines) {
100
111
if ($expectedHashLine.EndsWith(" $setupFileName")) {
0 commit comments