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