Skip to content

Commit

Permalink
[Windows] Add checksum validation for MSYS2 (actions#8385)
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-bershel authored Sep 27, 2023
1 parent 77724a9 commit 978a92f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions images/win/scripts/Installers/Install-Msys2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ $origPath = $env:PATH

function Install-Msys2 {
$msys2_release = "https://api.github.com/repos/msys2/msys2-installer/releases/latest"
$msys2Uri = ((Invoke-RestMethod $msys2_release).assets | Where-Object {
$_.name -match "^msys2-x86_64" -and $_.name.EndsWith(".exe") }).browser_download_url

$assets = (Invoke-RestMethod -Uri $msys2_release).assets
$msys2Uri = ($assets | Where-Object { $_.name -match "^msys2-x86_64" -and $_.name.EndsWith(".exe") }).browser_download_url
# Download the latest msys2 x86_64, filename includes release date
Write-Host "Starting msys2 download using $($msys2Uri.split('/')[-1])"
$msys2File = Start-DownloadWithRetry -Url $msys2Uri
Write-Host "Finished download"

#region Supply chain security - Kind
$fileHash = (Get-FileHash -Path $msys2File -Algorithm SHA256).Hash
$hashUrl = ($assets.browser_download_url -match "msys2-checksums.txt") | Select-Object -First 1
$externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*msys2-x86_64*" }).Split(' ')[0]
Use-ChecksumComparison $fileHash $externalHash
#endregion

# extract tar.xz to C:\
Write-Host "Starting msys2 installation"
& $msys2File in --confirm-command --accept-messages --root C:/msys64
Expand Down Expand Up @@ -89,4 +96,4 @@ Install-MingwPackages -Packages $toolsetContent.mingw
$env:PATH = $origPath
Write-Host "`nMSYS2 installation completed"

Invoke-PesterTests -TestFile "MSYS2"
Invoke-PesterTests -TestFile "MSYS2"

0 comments on commit 978a92f

Please sign in to comment.