@@ -68,33 +68,45 @@ runs:
6868 $setupExe = "$vol\setup.exe"
6969 $setupFileName = "setup-$platform.exe"
7070
71- $maxRetries = 5
72- $retryCount = 0
73- $success = $false
71+ function Invoke-WebRequest-With-Retry {
72+ param (
73+ $Uri,
74+ $OutFile
75+ )
76+
77+ $maxRetries = 5
78+ $retryCount = 0
79+ $delay = 2
80+ $success = $false
7481 $delay = 2
7582
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
83+ while (-not $success -and $retryCount -lt $maxRetries) {
84+ try {
85+ Invoke-WebRequest -Uri $Uri -OutFile $OutFile
86+ $success = $true
87+ } catch [System.Net.WebException] {
88+ Write-Output "Attempt $($retryCount + 1) failed. Retrying..."
89+ Start-Sleep -Seconds $delay
90+ $retryCount++
91+ $delay += $delay
92+ }
8593 }
86- }
8794
88- if (-not $success) {
89- throw "Failed to download $setupFileName after $maxRetries attempts."
95+ if (-not $success) {
96+ throw "Failed to download $setupFileName after $maxRetries attempts."
97+ }
9098 }
9199
100+ Invoke-WebRequest-With-Retry "https://cygwin.com/bad/$setupFileName" $setupExe
101+
92102 if ((Get-Item -LiteralPath $setupExe).Length -eq 0) {
93103 throw "The downloaded setup has a zero length!"
94104 }
95105
96106 if ('${{ inputs.check-hash }}' -eq 'true') {
97- $expectedHashLines = $(Invoke-WebRequest -Uri https://cygwin.com/sha512.sum).ToString() -split "`n"
107+ $hashFile = "$vol\sha512.sum"
108+ Invoke-WebRequest-With-Retry https://cygwin.com/sha512.sum $hashFile
109+ $expectedHashLines = Get-Content $hashFile
98110 $expectedHash = ''
99111 foreach ($expectedHashLine in $expectedHashLines) {
100112 if ($expectedHashLine.EndsWith(" $setupFileName")) {
0 commit comments