mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 14:17:22 +00:00
[Windows] Install ghc and cabal using ghcup (#6754)
This commit is contained in:
@@ -26,4 +26,4 @@ function Get-ToolcacheNodeVersions {
|
|||||||
function Get-ToolcacheGoVersions {
|
function Get-ToolcacheGoVersions {
|
||||||
$toolcachePath = Join-Path $env:AGENT_TOOLSDIRECTORY "go"
|
$toolcachePath = Join-Path $env:AGENT_TOOLSDIRECTORY "go"
|
||||||
return Get-ChildItem $toolcachePath -Name | Sort-Object { [Version]$_ }
|
return Get-ChildItem $toolcachePath -Name | Sort-Object { [Version]$_ }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,35 +2,7 @@
|
|||||||
## File: Install-Haskell.ps1
|
## File: Install-Haskell.ps1
|
||||||
## Desc: Install Haskell for Windows
|
## Desc: Install Haskell for Windows
|
||||||
################################################################################
|
################################################################################
|
||||||
|
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
||||||
# Get 3 latest versions of GHC, use OData query for that since choco search has issues https://github.com/chocolatey/choco/issues/2271
|
|
||||||
$ODataQuery = '$filter=(Title eq ''ghc'') and (IsPrerelease eq false)&$orderby=Version desc'
|
|
||||||
$Url = "https://community.chocolatey.org/api/v2/Packages()?$ODataQuery"
|
|
||||||
$ChocoVersionsOutput = [Version[]](Invoke-RestMethod -Uri $Url).properties.Version
|
|
||||||
$LatestMajorMinor = $ChocoVersionsOutput | Group-Object { $_.ToString(2) } | Sort-Object { [Version]$_.Name } | Select-Object -last 3
|
|
||||||
$VersionsList = $LatestMajorMinor | ForEach-Object { $_.Group | Select-Object -First 1 } | Sort-Object
|
|
||||||
|
|
||||||
# The latest version will be installed as a default
|
|
||||||
ForEach ($version in $VersionsList)
|
|
||||||
{
|
|
||||||
Write-Host "Installing ghc $version..."
|
|
||||||
Choco-Install -PackageName ghc -ArgumentList '--version', $version, '-m'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add default version of GHC to path, because choco formula updates path on user level
|
|
||||||
$DefaultGhcVersion = $VersionsList | Select-Object -Last 1
|
|
||||||
$DefaultGhcShortVersion = ([version]$DefaultGhcVersion).ToString(3)
|
|
||||||
$DefaultGhcPath = Join-Path $env:ChocolateyInstall "lib\ghc.$DefaultGhcVersion\tools\ghc-$DefaultGhcShortVersion\bin"
|
|
||||||
# Starting from version 9 haskell installation directory is $env:ChocolateyToolsLocation instead of $env:ChocolateyInstall\lib
|
|
||||||
if ($DefaultGhcShortVersion -notmatch '^[0-8]\.\d+.*')
|
|
||||||
{
|
|
||||||
$DefaultGhcPath = Join-Path $env:ChocolateyToolsLocation "ghc-$DefaultGhcShortVersion\bin"
|
|
||||||
}
|
|
||||||
|
|
||||||
Add-MachinePathItem -PathItem $DefaultGhcPath
|
|
||||||
|
|
||||||
Write-Host 'Installing cabal...'
|
|
||||||
Choco-Install -PackageName cabal
|
|
||||||
|
|
||||||
# install minimal ghcup, utilizing pre-installed msys2 at C:\msys64
|
# install minimal ghcup, utilizing pre-installed msys2 at C:\msys64
|
||||||
Write-Host 'Installing ghcup...'
|
Write-Host 'Installing ghcup...'
|
||||||
@@ -45,4 +17,27 @@ Set-SystemVariable "CABAL_DIR" $cabalDir
|
|||||||
Add-MachinePathItem "$ghcupPrefix\ghcup\bin"
|
Add-MachinePathItem "$ghcupPrefix\ghcup\bin"
|
||||||
Add-MachinePathItem "$cabalDir\bin"
|
Add-MachinePathItem "$cabalDir\bin"
|
||||||
|
|
||||||
|
Update-SessionEnvironment
|
||||||
|
|
||||||
|
# Get 3 latest versions of GHC
|
||||||
|
$Versions = ghcup list -t ghc -r | Where-Object {$_ -notlike "prerelease"}
|
||||||
|
$VersionsOutput = [Version[]]($Versions | ForEach-Object{ $_.Split(' ')[1]; })
|
||||||
|
$LatestMajorMinor = $VersionsOutput | Group-Object { $_.ToString(2) } | Sort-Object { [Version]$_.Name } | Select-Object -last 3
|
||||||
|
$VersionsList = $LatestMajorMinor | ForEach-Object { $_.Group | Select-Object -Last 1 } | Sort-Object
|
||||||
|
|
||||||
|
# The latest version will be installed as a default
|
||||||
|
ForEach ($version in $VersionsList)
|
||||||
|
{
|
||||||
|
Write-Host "Installing ghc $version..."
|
||||||
|
ghcup install ghc $version
|
||||||
|
ghcup set ghc $version
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add default version of GHC to path
|
||||||
|
$DefaultGhcVersion = $VersionsList | Select-Object -Last 1
|
||||||
|
ghcup set ghc $DefaultGhcVersion
|
||||||
|
|
||||||
|
Write-Host 'Installing cabal...'
|
||||||
|
ghcup install cabal latest
|
||||||
|
|
||||||
Invoke-PesterTests -TestFile 'Haskell'
|
Invoke-PesterTests -TestFile 'Haskell'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Describe "Haskell" {
|
Describe "Haskell" {
|
||||||
$chocoPackagesPath = Join-Path $env:ChocolateyInstall "lib"
|
$ghcPackagesPath = "c:\ghcup\ghc"
|
||||||
[array]$ghcVersionList = Get-ChildItem -Path $chocoPackagesPath -Filter "ghc.*" | ForEach-Object { $_.Name.TrimStart("ghc.") }
|
[array]$ghcVersionList = Get-ChildItem -Path $ghcPackagesPath -Filter "*" | ForEach-Object { $_.Name.Trim() }
|
||||||
$ghcCount = $ghcVersionList.Count
|
$ghcCount = $ghcVersionList.Count
|
||||||
$defaultGhcVersion = $ghcVersionList | Sort-Object {[Version]$_} | Select-Object -Last 1
|
$defaultGhcVersion = $ghcVersionList | Sort-Object {[Version]$_} | Select-Object -Last 1
|
||||||
$ghcDefaultCases = @{
|
$ghcDefaultCases = @{
|
||||||
@@ -11,12 +11,7 @@ Describe "Haskell" {
|
|||||||
$ghcTestCases = $ghcVersionList | ForEach-Object {
|
$ghcTestCases = $ghcVersionList | ForEach-Object {
|
||||||
$ghcVersion = $_
|
$ghcVersion = $_
|
||||||
$ghcShortVersion = ([version]$ghcVersion).ToString(3)
|
$ghcShortVersion = ([version]$ghcVersion).ToString(3)
|
||||||
$binGhcPath = Join-Path $chocoPackagesPath "ghc.$ghcVersion\tools\ghc-$ghcShortVersion\bin\ghc.exe"
|
$binGhcPath = Join-Path $ghcPackagesPath "$ghcShortVersion\bin\ghc.exe"
|
||||||
# The most recent GHC versions installation directory is $env:ChocolateyToolsLocation instead of $env:ChocolateyInstall\lib
|
|
||||||
if (-not (Test-Path $binGhcPath))
|
|
||||||
{
|
|
||||||
$binGhcPath = Join-Path $env:ChocolateyToolsLocation "ghc-$ghcShortVersion\bin\ghc.exe"
|
|
||||||
}
|
|
||||||
@{
|
@{
|
||||||
ghcVersion = $ghcVersion
|
ghcVersion = $ghcVersion
|
||||||
ghcShortVersion = $ghcShortVersion
|
ghcShortVersion = $ghcShortVersion
|
||||||
@@ -60,4 +55,8 @@ Describe "Haskell" {
|
|||||||
It "ghcup is installed" {
|
It "ghcup is installed" {
|
||||||
"ghcup --version" | Should -ReturnZeroExitCode
|
"ghcup --version" | Should -ReturnZeroExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "ghcup can access msys2" {
|
||||||
|
"ghcup run --mingw-path -- pacman --version" | Should -ReturnZeroExitCode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user