-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install Stack, GHC and Cabal to Windows Images (#874)
* install stack * implement logic that gets 3 latest versions of ghc
- Loading branch information
1 parent
89b403d
commit 5160bfa
Showing
7 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |