Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Stack, GHC and Cabal to Windows Images #874

Merged
merged 17 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions images/win/Windows2016-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,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":[
Expand Down Expand Up @@ -823,6 +835,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":[
Expand Down
24 changes: 24 additions & 0 deletions images/win/Windows2019-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,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":[
Expand Down Expand Up @@ -808,6 +820,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":[
Expand Down
5 changes: 4 additions & 1 deletion images/win/scripts/ImageHelpers/InstallHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions images/win/scripts/Installers/Install-Haskell.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
################################################################################
## File: Install-Haskell.ps1
## Desc: Install Haskell for Windows
################################################################################

# Get last 3 latest versions of GHC
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved
$ChocoVersionsOutput = & choco search ghc --allversions --limit-output
$VersionsList = $ChocoVersionsOutput | Where-Object { $_.StartsWith("ghc|") } | ForEach-Object { $_.TrimStart("ghc|") } `
| ForEach-Object { [Version]::Parse($_) } | Sort-Object -Descending

$MajorMinorVersionsToInstall = $VersionsList | ForEach-Object { [System.Version]::Parse($_.ToString(2)) } `
| Get-Unique | Sort-Object -Descending | Select-Object -First 3

$LatestGhcVersions = $MajorMinorVersionsToInstall | ForEach-Object {
$version = $_
return $VersionsList | Where-Object {
return ($_.Major -eq $version.Major) -and ($_.Minor -eq $version.Minor)
} | Select-Object -First 1
}
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved

# The latest version will be installed as a default
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved
ForEach ($version in $LatestGhcVersions)
{
Write-Host "Installing ghc $version..."
Choco-Install -PackageName ghc -ArgumentList "--version", $version, "-m"
}

Write-Host "Installing cabal..."
Choco-Install -PackageName cabal
20 changes: 20 additions & 0 deletions images/win/scripts/Installers/Install-Stack.ps1
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 -Uri $DownloadUrl
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved

Write-Host "Expand stack archive"
Extract-7Zip -Path $StackArchivePath -DestinationPath $DestinationPath

New-Item -Name "x64.complete" -Path $DestinationPath

Add-MachinePathItem -PathItem $DestinationPath
52 changes: 52 additions & 0 deletions images/win/scripts/Installers/Validate-Haskell.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
################################################################################
## File: Validate-Haskell.ps1
## Desc: Validate Haskell for Windows
################################################################################

# GHC validation
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved
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"
$GhcVersionList = Get-ChildItem -Path $ChocoPackagesPath -Filter "ghc.*" | ForEach-Object { $_.Name.TrimStart("ghc.") }
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved

$GhcVersionsDescription = $GhcVersionList | ForEach-Object {
$DefaultPostfix = if ($DefaultGhcVersion -match $_) { " (default)" } else { "" }
"ghc $($_) $DefaultPostfix `n"
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved
}

$Description = @"
_Version:_
$GhcVersionsDescription<br/>
"@

Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description


# Cabal validation
if ((Get-Command -Name 'cabal'))
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved
{
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
27 changes: 27 additions & 0 deletions images/win/scripts/Installers/Validate-Stack.ps1
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'))
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved
{
Write-Host "stack is on the path"
}
else
{
Write-Host "stack is not on path."
exit 1
}

$StackVersion = $(stack --version --quiet)
dibir-magomedsaygitov marked this conversation as resolved.
Show resolved Hide resolved

# 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