Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
Expand All @@ -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")) {
Expand Down
Loading