Install Stack, GHC and Cabal to Windows Images (#874)

* install stack
* implement logic that gets 3 latest versions of ghc
This commit is contained in:
Dibir Magomedsaygitov
2020-05-15 15:01:45 +03:00
committed by GitHub
parent 89b403d60a
commit 5160bfa626
7 changed files with 196 additions and 1 deletions

View File

@@ -541,6 +541,18 @@
"{{ template_dir }}/scripts/Installers/Install-TypeScript.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-Haskell.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-Stack.ps1"
]
},
{
"type": "powershell",
"scripts":[
@@ -837,6 +849,18 @@
"{{ template_dir }}/scripts/Installers/Validate-TypeScript.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Stack.ps1"
]
},
{
"type": "powershell",
"scripts":[

View File

@@ -520,6 +520,18 @@
"{{ template_dir }}/scripts/Installers/Install-TypeScript.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-Haskell.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-Stack.ps1"
]
},
{
"type": "powershell",
"scripts":[
@@ -822,6 +834,18 @@
"{{ template_dir }}/scripts/Installers/Validate-TypeScript.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Stack.ps1"
]
},
{
"type": "powershell",
"scripts":[

View File

@@ -221,12 +221,15 @@ function Start-DownloadWithRetry
(
[Parameter(Mandatory)]
[string] $Url,
[Parameter(Mandatory)]
[string] $Name,
[string] $DownloadPath = "${env:Temp}",
[int] $Retries = 20
)
if ([String]::IsNullOrEmpty($Name)) {
$Name = [IO.Path]::GetFileName($Url)
}
$filePath = Join-Path -Path $DownloadPath -ChildPath $Name
#Default retry logic for the package.

View File

@@ -0,0 +1,19 @@
################################################################################
## File: Install-Haskell.ps1
## Desc: Install Haskell for Windows
################################################################################
# Get 3 latest versions of GHC
[Version[]] $ChocoVersionsOutput = & choco search ghc --allversions --limit-output | Where-Object { $_.StartsWith("ghc|") } | ForEach-Object { $_.TrimStart("ghc|") }
$MajorMinorGroups = $ChocoVersionsOutput | Sort-Object -Descending | Group-Object { $_.ToString(2) } | Select-Object -First 3
$VersionsList = $MajorMinorGroups | 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"
}
Write-Host "Installing cabal..."
Choco-Install -PackageName cabal

View File

@@ -0,0 +1,20 @@
################################################################################
## File: Install-Stack.ps1
## Desc: Install Stack for Windows
################################################################################
Write-Host "Get the latest Stack version..."
$StackReleasesJson = Invoke-RestMethod "https://api.github.com/repos/commercialhaskell/stack/releases/latest"
$DownloadFilePattern = "windows-x86_64.zip"
$DownloadUrl = $StackReleasesJson.assets | Where-Object { $_.name.EndsWith($DownloadFilePattern) } | Select-Object -ExpandProperty "browser_download_url" -First 1
Write-Host "Download stack archive"
$DestinationPath = Join-Path $Env:AGENT_TOOLSDIRECTORY "stack\x64"
$StackArchivePath = Start-DownloadWithRetry -Url $DownloadUrl
Write-Host "Expand stack archive"
Extract-7Zip -Path $StackArchivePath -DestinationPath $DestinationPath
New-Item -Name "x64.complete" -Path $DestinationPath
Add-MachinePathItem -PathItem $DestinationPath

View File

@@ -0,0 +1,78 @@
################################################################################
## File: Validate-Haskell.ps1
## Desc: Validate Haskell for Windows
################################################################################
# GHC validation
if (Get-Command -Name 'ghc')
{
Write-Host "ghc is on the path"
}
else
{
Write-Host "ghc is not on path."
exit 1
}
$SoftwareName = "ghc"
[String] $DefaultGhcVersion = & ghc --version
$ChocoPackagesPath = Join-Path $env:ChocolateyInstall "lib"
[Array] $GhcVersionList = Get-ChildItem -Path $ChocoPackagesPath -Filter "ghc.*" | ForEach-Object { $_.Name.TrimStart("ghc.") }
# Validation that accurate 3 versions of GHC are installed
if ($GhcVersionList.Count -eq 3)
{
Write-Host "Versions of GHC are accurate"
}
else
{
Write-Host "Versions of GHC not accurate"
exit 1
}
# Validation each of GHC version
ForEach ($version in $GhcVersionList) {
$BinGhcPath = Join-Path $env:ChocolateyInstall "lib\ghc.$version\tools\ghc-$version\bin\ghc.exe"
if ((& $BinGhcPath --version) -match $version)
{
Write-Host "ghc $version is valid"
}
else
{
Write-Host "ghc $version is not valid"
exit 1
}
}
$GhcVersionsDescription = $GhcVersionList | ForEach-Object {
$DefaultPostfix = if ($DefaultGhcVersion -match $_) { " (default)" } else { "" }
"ghc $_ $DefaultPostfix `n"
}
$Description = @"
_Version:_
$GhcVersionsDescription<br/>
"@
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description
# Cabal validation
if (Get-Command -Name 'cabal')
{
Write-Host "cabal is on the path"
}
else
{
Write-Host "cabal is not on path."
exit 1
}
$SoftwareName = "cabal"
$Description = @"
_Version:_ $(cabal --version)<br/>
"@
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description

View File

@@ -0,0 +1,27 @@
################################################################################
## File: Validate-Stack.ps1
## Desc: Validate Stack for Windows
################################################################################
if (Get-Command -Name 'stack')
{
Write-Host "stack is on the path"
}
else
{
Write-Host "stack is not on path."
exit 1
}
$StackVersion = stack --version --quiet
# Adding description of the software to Markdown
$SoftwareName = "Stack"
$Description = @"
_Version:_ $StackVersion<br/>
_Environment:_
* PATH: contains location of stack.exe
"@
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description