diff options
| author | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
| commit | dcef0b65069fb38fd0f6c4382353167f603ebff1 (patch) | |
| tree | 45954ffe308c3dd056e6af4f734e6d2af89e5856 /deps/discord-haskell/.github/workflows/parseVersions.hs | |
Initial commit
Diffstat (limited to 'deps/discord-haskell/.github/workflows/parseVersions.hs')
| -rw-r--r-- | deps/discord-haskell/.github/workflows/parseVersions.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/deps/discord-haskell/.github/workflows/parseVersions.hs b/deps/discord-haskell/.github/workflows/parseVersions.hs new file mode 100644 index 0000000..3302f17 --- /dev/null +++ b/deps/discord-haskell/.github/workflows/parseVersions.hs @@ -0,0 +1,34 @@ +-- Small script to use the Cabal library to parse the Tested-With stanza +-- from discord-haskell.cabal, and output to stdout in a JSON friendly list. +module Main where + +import Prelude hiding (readFile) +import Data.ByteString (readFile) +import Data.List (intersperse) +import Data.Maybe (maybeToList) +import Distribution.Compiler (CompilerFlavor(GHC)) +import Distribution.PackageDescription.Parsec (parseGenericPackageDescriptionMaybe) +import Distribution.Pretty (pretty) +import Distribution.Types.GenericPackageDescription (GenericPackageDescription(packageDescription)) +import Distribution.Types.PackageDescription (PackageDescription(testedWith)) +import Distribution.Types.Version (versionNumbers) +import Distribution.Types.VersionRange.Internal (VersionRange(ThisVersion)) +import Text.PrettyPrint (render, brackets, comma, doubleQuotes) + +main = do + bs <- readFile "discord-haskell.cabal" + let mbVersions = testedWith . packageDescription <$> parseGenericPackageDescriptionMaybe bs + -- e.g. mbVersions = Just [(GHC,ThisVersion (mkVersion [8,10,7])),(GHC,ThisVersion (mkVersion [9,2])),(GHC,ThisVersion (mkVersion [9,4,1]))] + let versions = concat $ maybeToList mbVersions + -- e.g. versions = [(GHC,ThisVersion (mkVersion [8,10,7])),(GHC,ThisVersion (mkVersion [9,2])),(GHC,ThisVersion (mkVersion [9,4,1]))] + let ghcVersions = + [ ghcVersion + | (flavor, versionRange) <- versions + -- Filter only GHC + , GHC == flavor + -- Filter only to exact matches: "== VERSION" + , let (ThisVersion ghcVersion) = versionRange + ] + -- e.g. ghcVersions = [mkVersion [8,10,7],mkVersion [9,2],mkVersion [9,4,1]] + let prettyVersions = brackets $ mconcat $ intersperse comma $ map (doubleQuotes . pretty) ghcVersions + putStrLn $ render prettyVersions |
