-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParseCabalFile.hs
36 lines (31 loc) · 1.13 KB
/
ParseCabalFile.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
import Data.ByteString qualified as BS
import Data.List (intercalate)
import Distribution.Package (packageVersion)
import Distribution.PackageDescription.Parsec (parseGenericPackageDescriptionMaybe)
import Distribution.Version (versionNumbers)
import System.Environment (getArgs)
import System.IO (hPutStrLn, stderr, stdout)
main :: IO ()
main = do
cabalFile <-
getArgs >>= \case
[cabalFile] -> return cabalFile
_ -> errorWithoutStackTrace "Expected exactly one argument: CABAL_FILE"
cabalFileContents <- BS.readFile cabalFile
packageDesc <-
maybe (errorWithoutStackTrace "Could not parse cabal file") return $
parseGenericPackageDescriptionMaybe cabalFileContents
output
[ ("version", intercalate "." . map show . versionNumbers . packageVersion $ packageDesc)
]
output :: [(String, String)] -> IO ()
output = mapM_ (uncurry output')
where
output' key value = do
let kv = key ++ "=" ++ value
-- log to stderr
hPutStrLn stderr $ "Setting: " ++ kv
-- output to stdout into $GITHUB_OUTPUT
hPutStrLn stdout kv