diff --git a/action.yml b/action.yml index efad135..9af86f1 100644 --- a/action.yml +++ b/action.yml @@ -52,8 +52,7 @@ runs: $platform = $platform -replace '^i686$', 'x86' # validate that platform is one of the expected values if (($platform -ne 'x86') -and ($platform -ne 'x86_64')) { - echo "unknown platform $platform" - exit 1 + throw "Unknown platform $platform." } $vol = '${{ inputs.work-vol }}' @@ -68,13 +67,45 @@ runs: $setupExe = "$vol\setup.exe" $setupFileName = "setup-$platform.exe" - Invoke-WebRequest "https://cygwin.com/$setupFileName" -OutFile $setupExe + + function Invoke-WebRequest-With-Retry { + param ( + $Uri, + $OutFile + ) + + $maxRetries = 5 + $retryCount = 0 + $success = $false + $delay = 2 + + while (-not $success -and $retryCount -lt $maxRetries) { + try { + Invoke-WebRequest -Uri $Uri -OutFile $OutFile + $success = $true + } catch [System.Net.WebException] { + Write-Output "Attempt $($retryCount + 1) failed. Retrying..." + Start-Sleep -Seconds $delay + $retryCount++ + $delay += $delay + } + } + + if (-not $success) { + throw "Failed to download $setupFileName after $maxRetries attempts." + } + } + + Invoke-WebRequest-With-Retry "https://cygwin.com/$setupFileName" $setupExe + if ((Get-Item -LiteralPath $setupExe).Length -eq 0) { throw "The downloaded setup has a zero length!" } if ('${{ inputs.check-hash }}' -eq 'true') { - $expectedHashLines = $(Invoke-WebRequest -Uri https://cygwin.com/sha512.sum).ToString() -split "`n" + $hashFile = "$vol\sha512.sum" + Invoke-WebRequest-With-Retry https://cygwin.com/sha512.sum $hashFile + $expectedHashLines = Get-Content $hashFile $expectedHash = '' foreach ($expectedHashLine in $expectedHashLines) { if ($expectedHashLine.EndsWith(" $setupFileName")) {