Skip to content

Commit

Permalink
Show a warning if we can't find the hash of the setup file
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Oct 24, 2024
1 parent 5baa27b commit 126988b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,23 @@ runs:
$setupFileName = "setup-$platform.exe"
Invoke-WebRequest "https://cygwin.com/$setupFileName" -OutFile C:\setup.exe
if ('${{ inputs.check-hash }}'.ToLower() -in @('','true', 'yes', '1', 'on')) {
$actualHash = $(Get-FileHash -LiteralPath C:\setup.exe -Algorithm SHA512).Hash
if ('${{ inputs.check-hash }}' -eq 'true') {
$expectedHashLines = $(Invoke-WebRequest -Uri https://cygwin.com/sha512.sum).ToString() -split "`n"
$expectedHash = ''
foreach ($expectedHashLine in $expectedHashLines) {
if ($expectedHashLine -match "^(\S+)\s+(\S+)$") {
$expectedHash = $matches[1]
$expectedFileName = $matches[2]
if ($expectedFileName -ieq $setupFileName) {
if ($expectedHash -ine $actualHash) {
throw "Invalid hash of the downloaded setup!`nExpected: $expectedHashLine`nActual : $actualHash $expectedFileName"
}
Write-Host "The downloaded file has the expected hash ($actualHash)"
}
if ($expectedHashLine.EndsWith(" $setupFileName")) {
$expectedHash = $($expectedHashLine -split '\s+')[0]
break
}
}
if ($expectedHash -eq '') {
Write-Output -InputObject "::warning::Unable to find the hash for the file $setupFileName in https://cygwin.com/sha512.sum"
} else {
$actualHash = $(Get-FileHash -LiteralPath C:\setup.exe -Algorithm SHA512).Hash
if ($actualHash -ine $expectedHash) {
throw "Invalid hash of the downloaded setup!`nExpected: $expectedHash`nActual : $actualHash"
} else {
Write-Output -InputObject "`u{2705} The downloaded file has the expected hash ($expectedHash)"
}
}
}
Expand Down

0 comments on commit 126988b

Please sign in to comment.