Skip to content

Commit

Permalink
[Windows] Switch to use OData query instead of choco search for ghc i…
Browse files Browse the repository at this point in the history
…nstallation (actions#3458)

* Switch to use OData query instead of choco search

* Simplify the logic
  • Loading branch information
miketimofeev authored May 27, 2021
1 parent f9f82b7 commit f7e0e8b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions images/win/scripts/Installers/Install-Haskell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
## Desc: Install Haskell for Windows
################################################################################

# Get 3 latest versions of GHC
[Version[]] $ChocoVersionsOutput = & choco search ghc --allversions | Where-Object { $_.StartsWith('ghc ') -and $_ -match 'Approved' } | ForEach-Object { [regex]::matches($_, '\d+(\.\d+){2,}').value }
$MajorMinorGroups = $ChocoVersionsOutput | Sort-Object -Descending | Group-Object { $_.ToString(2) } | Select-Object -First 3
$VersionsList = $MajorMinorGroups | ForEach-Object { $_.Group | Select-Object -First 1 } | Sort-Object
# Get 3 latest versions of GHC, use OData query for that since choco search has issues https://github.com/chocolatey/choco/issues/2271
$ODataQuery = '$filter=(Title eq ''ghc'') and (IsPrerelease eq false)&$orderby=Version desc'
$Url = "https://community.chocolatey.org/api/v2/Packages()?$ODataQuery"
$ChocoVersionsOutput = [Version[]](Invoke-RestMethod -Uri $Url).properties.Version
$LatestMajorMinor = $ChocoVersionsOutput | Group-Object { $_.ToString(2) } | Sort-Object { [Version]$_.Name } | Select-Object -last 3
$VersionsList = $LatestMajorMinor | ForEach-Object { $_.Group | Select-Object -First 1 } | Sort-Object

# The latest version will be installed as a default
ForEach ($version in $VersionsList)
Expand Down

0 comments on commit f7e0e8b

Please sign in to comment.