Skip to content

Commit

Permalink
Install Stack, GHC and Cabal to Windows Images (#874)
Browse files Browse the repository at this point in the history
* install stack
* implement logic that gets 3 latest versions of ghc
  • Loading branch information
dibir-magomedsaygitov authored May 15, 2020
1 parent 89b403d commit 5160bfa
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 1 deletion.
24 changes: 24 additions & 0 deletions images/win/Windows2016-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":[
Expand Down Expand Up @@ -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":[
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 @@ -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":[
Expand Down Expand Up @@ -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":[
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
19 changes: 19 additions & 0 deletions images/win/scripts/Installers/Install-Haskell.ps1
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
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 -Url $DownloadUrl

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

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

Add-MachinePathItem -PathItem $DestinationPath
78 changes: 78 additions & 0 deletions images/win/scripts/Installers/Validate-Haskell.ps1
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
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')
{
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

0 comments on commit 5160bfa

Please sign in to comment.