Files
runner-images/images/windows/scripts/build/Install-Stack.ps1
Vasilii Polikarpov 5ed2615017 [Windows] Cleanup various scripts (#8942)
* Use Resolve-GithubReleaseAssetUrl more widely

* Add the Get-ChecksumFromUrl function

* Sort exported functions and add docs

* Remove alias and fix typo

* Fix kind checksum url and syntax

* Fix checksums url for gh cli and msys2

* [Windows] Cleanup various scripts

* Add spaces after type specifications

* Rename the Take-Part function
2023-12-04 10:50:53 +01:00

36 lines
1.3 KiB
PowerShell

################################################################################
## File: Install-Stack.ps1
## Desc: Install Stack for Windows
## Supply chain security: Stack - checksum validation
################################################################################
Write-Host "Get the latest Stack version..."
$version = (Get-GithubReleasesByVersion -Repo "commercialhaskell/stack" -Version "latest" -WithAssetsOnly).version
$downloadUrl = Resolve-GithubReleaseAssetUrl `
-Repo "commercialhaskell/stack" `
-Version $version `
-UrlMatchPattern "stack-*-windows-x86_64.zip"
Write-Host "Download stack archive"
$StackToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY "stack\$version"
$DestinationPath = Join-Path $StackToolcachePath "x64"
$StackArchivePath = Invoke-DownloadWithRetry $downloadUrl
#region Supply chain security - Stack
$externalHash = Get-ChecksumFromUrl -Type "SHA256" `
-Url "$downloadUrl.sha256" `
-FileName (Split-Path $downloadUrl -Leaf)
Test-FileChecksum $StackArchivePath -ExpectedSHA256Sum $externalHash
#endregion
Write-Host "Expand stack archive"
Expand-7ZipArchive -Path $StackArchivePath -DestinationPath $DestinationPath
New-Item -Name "x64.complete" -Path $StackToolcachePath
Add-MachinePathItem -PathItem $DestinationPath
Invoke-PesterTests -TestFile "Tools" -TestName "Stack"