@@ -68,33 +68,44 @@ runs:
6868 $setupExe = "$vol\setup.exe"
6969 $setupFileName = "setup-$platform.exe"
7070
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+ }
8592 }
86- }
8793
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+ }
9097 }
9198
99+ Invoke-WebRequest-With-Retry "https://cygwin.com/$setupFileName" $setupExe
100+
92101 if ((Get-Item -LiteralPath $setupExe).Length -eq 0) {
93102 throw "The downloaded setup has a zero length!"
94103 }
95104
96105 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
98109 $expectedHash = ''
99110 foreach ($expectedHashLine in $expectedHashLines) {
100111 if ($expectedHashLine.EndsWith(" $setupFileName")) {
0 commit comments