From e8a4dd04de1687ade396dd7878d605459aae6815 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Tue, 12 May 2020 19:08:41 +0300 Subject: [PATCH 01/13] install stack --- images/win/Windows2016-Azure.json | 12 +++++++++ images/win/Windows2019-Azure.json | 12 +++++++++ .../scripts/ImageHelpers/InstallHelpers.ps1 | 5 +++- .../win/scripts/Installers/Install-Stack.ps1 | 19 +++++++++++++ .../win/scripts/Installers/Validate-Stack.ps1 | 27 +++++++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 images/win/scripts/Installers/Install-Stack.ps1 create mode 100644 images/win/scripts/Installers/Validate-Stack.ps1 diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index 506073423489..bfb117b7d8e7 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -533,6 +533,12 @@ "{{ template_dir }}/scripts/Installers/Install-TypeScript.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" + ] + }, { "type": "powershell", "scripts":[ @@ -823,6 +829,12 @@ "{{ template_dir }}/scripts/Installers/Validate-TypeScript.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" + ] + }, { "type": "powershell", "scripts":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index 2a89973efbd7..545aeb9f7e5f 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -512,6 +512,12 @@ "{{ template_dir }}/scripts/Installers/Install-TypeScript.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" + ] + }, { "type": "powershell", "scripts":[ @@ -808,6 +814,12 @@ "{{ template_dir }}/scripts/Installers/Validate-TypeScript.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" + ] + }, { "type": "powershell", "scripts":[ diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 8ec49e0d4b43..0cf44fb07ca1 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -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. diff --git a/images/win/scripts/Installers/Install-Stack.ps1 b/images/win/scripts/Installers/Install-Stack.ps1 new file mode 100644 index 000000000000..410c25f96c37 --- /dev/null +++ b/images/win/scripts/Installers/Install-Stack.ps1 @@ -0,0 +1,19 @@ +################################################################################ +## 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" +$DownloadUrl = $StackReleasesJson.assets | Where-Object { $_.name.EndsWith("windows-x86_64.zip") } | 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 + +Write-Host "Expand stack archive" +Extract-7Zip -Path $StackArchivePath -DestinationPath $DestinationPath + +New-Item -Name "x64.complete" -Path $DestinationPath + +Add-MachinePathItem -PathItem $DestinationPath \ No newline at end of file diff --git a/images/win/scripts/Installers/Validate-Stack.ps1 b/images/win/scripts/Installers/Validate-Stack.ps1 new file mode 100644 index 000000000000..60b80700b1a3 --- /dev/null +++ b/images/win/scripts/Installers/Validate-Stack.ps1 @@ -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
+_Environment:_ +* PATH: contains location of stack.exe +"@ + +Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description From 82de2bd2ae35f5006389f5ed72be5713b2729be4 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Tue, 12 May 2020 19:23:07 +0300 Subject: [PATCH 02/13] small fix --- images/win/scripts/Installers/Install-Stack.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-Stack.ps1 b/images/win/scripts/Installers/Install-Stack.ps1 index 410c25f96c37..172c706f273c 100644 --- a/images/win/scripts/Installers/Install-Stack.ps1 +++ b/images/win/scripts/Installers/Install-Stack.ps1 @@ -5,7 +5,8 @@ Write-Host "Get the latest Stack version..." $StackReleasesJson = Invoke-RestMethod "https://api.github.com/repos/commercialhaskell/stack/releases/latest" -$DownloadUrl = $StackReleasesJson.assets | Where-Object { $_.name.EndsWith("windows-x86_64.zip") } | Select-Object -ExpandProperty "browser_download_url" -First 1 +$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" From ff84dd94b2c8cac2e3bf850ba611a6a465d689ab Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 10:47:59 +0300 Subject: [PATCH 03/13] install haskell --- images/win/Windows2016-Azure.json | 12 ++++ images/win/Windows2019-Azure.json | 12 ++++ .../scripts/Installers/Install-Haskell.ps1 | 17 ++++++ .../scripts/Installers/Validate-Haskell.ps1 | 57 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 images/win/scripts/Installers/Install-Haskell.ps1 create mode 100644 images/win/scripts/Installers/Validate-Haskell.ps1 diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index bfb117b7d8e7..719f6b47a77d 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -539,6 +539,12 @@ "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1" + ] + }, { "type": "powershell", "scripts":[ @@ -835,6 +841,12 @@ "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1" + ] + }, { "type": "powershell", "scripts":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index 545aeb9f7e5f..617bfb255ede 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -518,6 +518,12 @@ "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1" + ] + }, { "type": "powershell", "scripts":[ @@ -820,6 +826,12 @@ "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1" + ] + }, { "type": "powershell", "scripts":[ diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 new file mode 100644 index 000000000000..6592be7172b0 --- /dev/null +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -0,0 +1,17 @@ +################################################################################ +## File: Install-Haskell.ps1 +## Desc: Install Haskell for Windows +################################################################################ + + +# The latest version will be installed as a default +$GhcVersions = @('8.6.5', '8.8.3', '8.10.1') + +ForEach ($version in $GhcVersions) +{ + Write-Host "Installing ghc $version..." + Choco-Install -PackageName ghc -ArgumentList "--version", $version, "-m" +} + +Write-Host "Installing cabal..." +Choco-Install -PackageName cabal diff --git a/images/win/scripts/Installers/Validate-Haskell.ps1 b/images/win/scripts/Installers/Validate-Haskell.ps1 new file mode 100644 index 000000000000..7e212ea34833 --- /dev/null +++ b/images/win/scripts/Installers/Validate-Haskell.ps1 @@ -0,0 +1,57 @@ +################################################################################ +## 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] $GhcVersion =(ghc --version).TrimStart("The Glorious Glasgow Haskell Compilation System, version") +$GhcVersionList =Get-ChildItem -Path (Join-Path $env:ChocolateyInstall “lib”) | Where { $_.Name -match "ghc.*" } | Select-Object -ExpandProperty Name | ForEach-Object {$_.TrimStart("ghc.")} +$GhcVersions = "" + +ForEach($version in $GhcVersionList) +{ + if ($version -match $GhcVersion) { + $GhcVersions += "ghc version $($version) - (default) `n" + } + else { + $GhcVersions += "ghc version $($version)`n" + } +} + +$Description = @" +_Version:_ +$GhcVersions
+"@ + +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)
+"@ + +Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description \ No newline at end of file From 3537c9c6f10bc01931da8835b3e12ea3f10ed709 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 10:52:11 +0300 Subject: [PATCH 04/13] typo fix --- images/win/scripts/Installers/Validate-Haskell.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/images/win/scripts/Installers/Validate-Haskell.ps1 b/images/win/scripts/Installers/Validate-Haskell.ps1 index 7e212ea34833..05807b83a9c7 100644 --- a/images/win/scripts/Installers/Validate-Haskell.ps1 +++ b/images/win/scripts/Installers/Validate-Haskell.ps1 @@ -4,7 +4,7 @@ ################################################################################ # GHC validation -if((Get-Command -Name 'ghc')) +if ((Get-Command -Name 'ghc')) { Write-Host "ghc is on the path" } @@ -21,10 +21,12 @@ $GhcVersions = "" ForEach($version in $GhcVersionList) { - if ($version -match $GhcVersion) { + if ($version -match $GhcVersion) + { $GhcVersions += "ghc version $($version) - (default) `n" } - else { + else + { $GhcVersions += "ghc version $($version)`n" } } @@ -38,7 +40,7 @@ Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $ # Cabal validation -if((Get-Command -Name 'cabal')) +if ((Get-Command -Name 'cabal')) { Write-Host "cabal is on the path" } From f70338971fa0be05fea1bebff0dabd7b40adae82 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 11:18:47 +0300 Subject: [PATCH 05/13] update haskell validation --- images/win/Windows2016-Azure.json | 8 +++---- images/win/Windows2019-Azure.json | 8 +++---- .../scripts/Installers/Validate-Haskell.ps1 | 21 +++++++------------ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index 719f6b47a77d..29f66a78d3d3 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -536,13 +536,13 @@ { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" + "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1" ] }, { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1" + "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" ] }, { @@ -838,13 +838,13 @@ { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" + "{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1" ] }, { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1" + "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" ] }, { diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index 617bfb255ede..49f7eacb0752 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -515,13 +515,13 @@ { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" + "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1" ] }, { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-Haskell.ps1" + "{{ template_dir }}/scripts/Installers/Install-Stack.ps1" ] }, { @@ -823,13 +823,13 @@ { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" + "{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1" ] }, { "type": "powershell", "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Haskell.ps1" + "{{ template_dir }}/scripts/Installers/Validate-Stack.ps1" ] }, { diff --git a/images/win/scripts/Installers/Validate-Haskell.ps1 b/images/win/scripts/Installers/Validate-Haskell.ps1 index 05807b83a9c7..22fe3961a424 100644 --- a/images/win/scripts/Installers/Validate-Haskell.ps1 +++ b/images/win/scripts/Installers/Validate-Haskell.ps1 @@ -15,25 +15,18 @@ else } $SoftwareName = "ghc" -[String] $GhcVersion =(ghc --version).TrimStart("The Glorious Glasgow Haskell Compilation System, version") -$GhcVersionList =Get-ChildItem -Path (Join-Path $env:ChocolateyInstall “lib”) | Where { $_.Name -match "ghc.*" } | Select-Object -ExpandProperty Name | ForEach-Object {$_.TrimStart("ghc.")} -$GhcVersions = "" +[String] $DefaultGhcVersion = & ghc --version +$ChocoPackagesPath = Join-Path $env:ChocolateyInstall "lib" +$GhcVersionList = Get-ChildItem -Path $ChocoPackagesPath -Filter "ghc.*" | ForEach-Object { $_.Name.TrimStart("ghc.") } -ForEach($version in $GhcVersionList) -{ - if ($version -match $GhcVersion) - { - $GhcVersions += "ghc version $($version) - (default) `n" - } - else - { - $GhcVersions += "ghc version $($version)`n" - } +$GhcVersionsDescription = $GhcVersionList | ForEach-Object { + $DefaultPostfix = if ($DefaultGhcVersion -match $_) { " (default)" } else { "" } + "ghc $($_) $DefaultPostfix `n" } $Description = @" _Version:_ -$GhcVersions
+$GhcVersionsDescription
"@ Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description From 7caeb3ce17507a3312528c2cc45379c11122ef7d Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 17:44:12 +0300 Subject: [PATCH 06/13] implement logic that gets 3 latest versions of ghc --- .../win/scripts/Installers/Install-Haskell.ps1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 index 6592be7172b0..914a74390b6f 100644 --- a/images/win/scripts/Installers/Install-Haskell.ps1 +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -3,11 +3,23 @@ ## Desc: Install Haskell for Windows ################################################################################ +# Get last 3 latest versions of GHC +[Array] $ChocoVersionsOutput = & choco search ghc --allversions --limit-output +$RawVersionsList = $ChocoVersionsOutput | Where-Object { $_.StartsWith("ghc|") } | ForEach-Object { $_.TrimStart("ghc|") } +$VersionsList = $RawVersionsList | ForEach-Object { [Version]::Parse($_) } | Sort-Object -Descending -# The latest version will be installed as a default -$GhcVersions = @('8.6.5', '8.8.3', '8.10.1') +$MajorMinorVersions = $VersionsList | ForEach-Object { [System.Version]::Parse($_.ToString(2)) } | Get-Unique +$MajorMinorVersionsToInstall = $MajorMinorVersions | 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 +} -ForEach ($version in $GhcVersions) +# The latest version will be installed as a default +ForEach ($version in $LatestGhcVersions) { Write-Host "Installing ghc $version..." Choco-Install -PackageName ghc -ArgumentList "--version", $version, "-m" From b5a1b6917a33aa8975096786272bf077b9520af5 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 18:08:17 +0300 Subject: [PATCH 07/13] minor fix --- images/win/scripts/Installers/Install-Haskell.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 index 914a74390b6f..663da4ac58f9 100644 --- a/images/win/scripts/Installers/Install-Haskell.ps1 +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -4,7 +4,7 @@ ################################################################################ # Get last 3 latest versions of GHC -[Array] $ChocoVersionsOutput = & choco search ghc --allversions --limit-output +$ChocoVersionsOutput = & choco search ghc --allversions --limit-output $RawVersionsList = $ChocoVersionsOutput | Where-Object { $_.StartsWith("ghc|") } | ForEach-Object { $_.TrimStart("ghc|") } $VersionsList = $RawVersionsList | ForEach-Object { [Version]::Parse($_) } | Sort-Object -Descending From b70898ef6de2fcaebccf43183346c5864abe2560 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 18:47:09 +0300 Subject: [PATCH 08/13] minor fix --- images/win/scripts/Installers/Install-Haskell.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 index 663da4ac58f9..7437b1507751 100644 --- a/images/win/scripts/Installers/Install-Haskell.ps1 +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -8,8 +8,7 @@ $ChocoVersionsOutput = & choco search ghc --allversions --limit-output $RawVersionsList = $ChocoVersionsOutput | Where-Object { $_.StartsWith("ghc|") } | ForEach-Object { $_.TrimStart("ghc|") } $VersionsList = $RawVersionsList | ForEach-Object { [Version]::Parse($_) } | Sort-Object -Descending -$MajorMinorVersions = $VersionsList | ForEach-Object { [System.Version]::Parse($_.ToString(2)) } | Get-Unique -$MajorMinorVersionsToInstall = $MajorMinorVersions | Sort-Object -Descending | Select-Object -First 3 +$MajorMinorVersionsToInstall = $VersionsList | ForEach-Object { [System.Version]::Parse($_.ToString(2)) } | Get-Unique | Sort-Object -Descending | Select-Object -First 3 $LatestGhcVersions = $MajorMinorVersionsToInstall | ForEach-Object { $version = $_ From 07b8b6754d924beced4e60b109667fd594f55d18 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 18:49:16 +0300 Subject: [PATCH 09/13] minor fix --- images/win/scripts/Installers/Install-Haskell.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 index 7437b1507751..2773759b4c4a 100644 --- a/images/win/scripts/Installers/Install-Haskell.ps1 +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -5,8 +5,8 @@ # Get last 3 latest versions of GHC $ChocoVersionsOutput = & choco search ghc --allversions --limit-output -$RawVersionsList = $ChocoVersionsOutput | Where-Object { $_.StartsWith("ghc|") } | ForEach-Object { $_.TrimStart("ghc|") } -$VersionsList = $RawVersionsList | ForEach-Object { [Version]::Parse($_) } | Sort-Object -Descending +$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 From fd902f204f613b46acdd2d25eea241738af460cb Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Wed, 13 May 2020 18:51:15 +0300 Subject: [PATCH 10/13] minor fix --- images/win/scripts/Installers/Install-Haskell.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 index 2773759b4c4a..8dbf1b27ebdc 100644 --- a/images/win/scripts/Installers/Install-Haskell.ps1 +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -8,7 +8,8 @@ $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 +$MajorMinorVersionsToInstall = $VersionsList | ForEach-Object { [System.Version]::Parse($_.ToString(2)) } ` +| Get-Unique | Sort-Object -Descending | Select-Object -First 3 $LatestGhcVersions = $MajorMinorVersionsToInstall | ForEach-Object { $version = $_ From fd0ec23b7c08f518ce1dc8356d8ba3d4358f2a7e Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Thu, 14 May 2020 15:06:53 +0300 Subject: [PATCH 11/13] simplify validation part and minor fixes --- .../scripts/Installers/Install-Haskell.ps1 | 20 ++++--------- .../win/scripts/Installers/Install-Stack.ps1 | 2 +- .../scripts/Installers/Validate-Haskell.ps1 | 29 +++++++++++++++++-- .../win/scripts/Installers/Validate-Stack.ps1 | 4 +-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 index 8dbf1b27ebdc..c162819d1f11 100644 --- a/images/win/scripts/Installers/Install-Haskell.ps1 +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -3,23 +3,13 @@ ## Desc: Install Haskell for Windows ################################################################################ -# Get last 3 latest versions of GHC -$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 -} +# 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 } # The latest version will be installed as a default -ForEach ($version in $LatestGhcVersions) +ForEach ($version in $VersionsList) { Write-Host "Installing ghc $version..." Choco-Install -PackageName ghc -ArgumentList "--version", $version, "-m" diff --git a/images/win/scripts/Installers/Install-Stack.ps1 b/images/win/scripts/Installers/Install-Stack.ps1 index 172c706f273c..6996ac7f62c6 100644 --- a/images/win/scripts/Installers/Install-Stack.ps1 +++ b/images/win/scripts/Installers/Install-Stack.ps1 @@ -10,7 +10,7 @@ $DownloadUrl = $StackReleasesJson.assets | Where-Object { $_.name.EndsWith($Down Write-Host "Download stack archive" $DestinationPath = Join-Path $Env:AGENT_TOOLSDIRECTORY "stack\x64" -$StackArchivePath = Start-DownloadWithRetry -Uri $DownloadUrl +$StackArchivePath = Start-DownloadWithRetry -Url $DownloadUrl Write-Host "Expand stack archive" Extract-7Zip -Path $StackArchivePath -DestinationPath $DestinationPath diff --git a/images/win/scripts/Installers/Validate-Haskell.ps1 b/images/win/scripts/Installers/Validate-Haskell.ps1 index 22fe3961a424..e506344b213f 100644 --- a/images/win/scripts/Installers/Validate-Haskell.ps1 +++ b/images/win/scripts/Installers/Validate-Haskell.ps1 @@ -4,7 +4,7 @@ ################################################################################ # GHC validation -if ((Get-Command -Name 'ghc')) +if (Get-Command -Name 'ghc') { Write-Host "ghc is on the path" } @@ -17,7 +17,32 @@ else $SoftwareName = "ghc" [String] $DefaultGhcVersion = & ghc --version $ChocoPackagesPath = Join-Path $env:ChocolateyInstall "lib" -$GhcVersionList = Get-ChildItem -Path $ChocoPackagesPath -Filter "ghc.*" | ForEach-Object { $_.Name.TrimStart("ghc.") } +[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 { "" } diff --git a/images/win/scripts/Installers/Validate-Stack.ps1 b/images/win/scripts/Installers/Validate-Stack.ps1 index 60b80700b1a3..d24d89546150 100644 --- a/images/win/scripts/Installers/Validate-Stack.ps1 +++ b/images/win/scripts/Installers/Validate-Stack.ps1 @@ -3,7 +3,7 @@ ## Desc: Validate Stack for Windows ################################################################################ -if((Get-Command -Name 'stack')) +if (Get-Command -Name 'stack') { Write-Host "stack is on the path" } @@ -13,7 +13,7 @@ else exit 1 } -$StackVersion = $(stack --version --quiet) +$StackVersion = stack --version --quiet # Adding description of the software to Markdown $SoftwareName = "Stack" From 79c24966b81121f3c8c39284f6146a7e4cd7fd07 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Thu, 14 May 2020 21:05:26 +0300 Subject: [PATCH 12/13] minor fixes --- images/win/scripts/Installers/Validate-Haskell.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/Installers/Validate-Haskell.ps1 b/images/win/scripts/Installers/Validate-Haskell.ps1 index e506344b213f..6d47daad830c 100644 --- a/images/win/scripts/Installers/Validate-Haskell.ps1 +++ b/images/win/scripts/Installers/Validate-Haskell.ps1 @@ -37,7 +37,8 @@ ForEach ($version in $GhcVersionList) { { Write-Host "ghc $version is valid" } - else { + else + { Write-Host "ghc $version is not valid" exit 1 } @@ -46,7 +47,7 @@ ForEach ($version in $GhcVersionList) { $GhcVersionsDescription = $GhcVersionList | ForEach-Object { $DefaultPostfix = if ($DefaultGhcVersion -match $_) { " (default)" } else { "" } - "ghc $($_) $DefaultPostfix `n" + "ghc $_ $DefaultPostfix `n" } $Description = @" @@ -58,7 +59,7 @@ Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $ # Cabal validation -if ((Get-Command -Name 'cabal')) +if (Get-Command -Name 'cabal') { Write-Host "cabal is on the path" } From 8ffd5cd28c85c30fb8e2ee7930b54a3e671f577e Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov Date: Thu, 14 May 2020 21:33:50 +0300 Subject: [PATCH 13/13] fix versions order --- images/win/scripts/Installers/Install-Haskell.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-Haskell.ps1 b/images/win/scripts/Installers/Install-Haskell.ps1 index c162819d1f11..19483fd7d7fd 100644 --- a/images/win/scripts/Installers/Install-Haskell.ps1 +++ b/images/win/scripts/Installers/Install-Haskell.ps1 @@ -6,7 +6,7 @@ # 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 } +$VersionsList = $MajorMinorGroups | ForEach-Object { $_.Group | Select-Object -First 1 } | Sort-Object # The latest version will be installed as a default ForEach ($version in $VersionsList)