From 8291527d51ad99b569844e612e6aa49dbd736b30 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Fri, 1 Jan 2021 19:10:26 +0200 Subject: [PATCH] Read cabal.haskell-ci by default --- .github/workflows/haskell-ci.yml | 4 ++-- haskell-ci.cabal | 2 +- src/HaskellCI.hs | 20 +++++++++++++++++--- src/HaskellCI/Cli.hs | 28 ++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 7670f2e5..35076876 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -1,6 +1,6 @@ # This GitHub workflow config has been generated by a script via # -# haskell-ci '--config=cabal.haskell-ci' 'github' 'cabal.project' +# haskell-ci 'github' 'cabal.project' # # To regenerate the script (for example after adjusting tested-with) run # @@ -8,7 +8,7 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# REGENDATA ["--config=cabal.haskell-ci","github","cabal.project"] +# REGENDATA ["github","cabal.project"] # name: Haskell-CI on: diff --git a/haskell-ci.cabal b/haskell-ci.cabal index badec4ac..a11b421c 100644 --- a/haskell-ci.cabal +++ b/haskell-ci.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: haskell-ci -version: 0.11.20201230 +version: 0.11.20210101 synopsis: Cabal package script generator for Travis-CI description: Script generator (@haskell-ci@) for [Travis-CI](https://travis-ci.org/) for continuous-integration testing of Haskell Cabal packages. diff --git a/src/HaskellCI.hs b/src/HaskellCI.hs index 4ceea684..ab6b9605 100644 --- a/src/HaskellCI.hs +++ b/src/HaskellCI.hs @@ -138,7 +138,7 @@ travisFromConfigFile travisFromConfigFile args opts path = do gitconfig <- liftIO readGitConfig cabalFiles <- getCabalFiles (optInputType' opts path) path - config' <- maybe (return emptyConfig) readConfigFile (optConfig opts) + config' <- findConfigFile (optConfig opts) let config = optConfigMorphism opts config' pkgs <- T.mapM (configFromCabalFile config) cabalFiles (ghcs, prj) <- case checkVersions (cfgTestedWith config) pkgs of @@ -224,7 +224,7 @@ bashFromConfigFile bashFromConfigFile args opts path = do gitconfig <- liftIO readGitConfig cabalFiles <- getCabalFiles (optInputType' opts path) path - config' <- maybe (return emptyConfig) readConfigFile (optConfig opts) + config' <- findConfigFile (optConfig opts) let config = optConfigMorphism opts config' pkgs <- T.mapM (configFromCabalFile config) cabalFiles (ghcs, prj) <- case checkVersions (cfgTestedWith config) pkgs of @@ -311,7 +311,7 @@ githubFromConfigFile githubFromConfigFile args opts path = do gitconfig <- liftIO readGitConfig cabalFiles <- getCabalFiles (optInputType' opts path) path - config' <- maybe (return emptyConfig) readConfigFile (optConfig opts) + config' <- findConfigFile (optConfig opts) let config = optConfigMorphism opts config' pkgs <- T.mapM (configFromCabalFile config) cabalFiles (ghcs, prj) <- case checkVersions (cfgTestedWith config) pkgs of @@ -367,6 +367,20 @@ regenerateGitHub opts = do noGitHubScript :: IO () noGitHubScript = putStrLn $ "No " ++ fp ++ ", skipping GitHub config regeneration" +------------------------------------------------------------------------------- +-- Config file +------------------------------------------------------------------------------- + +findConfigFile :: MonadIO m => ConfigOpt -> m Config +findConfigFile ConfigOptNo = return emptyConfig +findConfigFile (ConfigOpt fp) = readConfigFile fp +findConfigFile ConfigOptAuto = do + let defaultPath = "cabal.haskell-ci" + exists <- liftIO (doesFileExist defaultPath) + if exists + then readConfigFile defaultPath + else return emptyConfig + ------------------------------------------------------------------------------- -- Patches ------------------------------------------------------------------------------- diff --git a/src/HaskellCI/Cli.hs b/src/HaskellCI/Cli.hs index 877c9cd0..1323c19f 100644 --- a/src/HaskellCI/Cli.hs +++ b/src/HaskellCI/Cli.hs @@ -35,22 +35,20 @@ data Command data Options = Options { optOutput :: Maybe Output - , optConfig :: Maybe FilePath + , optConfig :: ConfigOpt , optCwd :: Maybe FilePath , optInputType :: Maybe InputType , optConfigMorphism :: Config -> Config } -data Output = OutputStdout | OutputFile FilePath - instance Semigroup Options where Options b d c e f <> Options b' d' c' e' f' = - Options (b <|> b') (d <|> d') (c <|> c') (e <|> e') (f' . f) + Options (b <|> b') (d <> d') (c <|> c') (e <|> e') (f' . f) defaultOptions :: Options defaultOptions = Options { optOutput = Nothing - , optConfig = Nothing + , optConfig = ConfigOptAuto , optCwd = Nothing , optInputType = Nothing , optConfigMorphism = id @@ -61,6 +59,18 @@ optionsWithOutputFile fp = defaultOptions { optOutput = Just (OutputFile fp) } +data Output = OutputStdout | OutputFile FilePath + +data ConfigOpt + = ConfigOptAuto + | ConfigOpt FilePath + | ConfigOptNo + deriving (Eq, Show) + +instance Semigroup ConfigOpt where + a <> ConfigOptAuto = a + _ <> b = b + ------------------------------------------------------------------------------- -- InputType ------------------------------------------------------------------------------- @@ -83,11 +93,17 @@ optInputType' opts path = optionsP :: O.Parser Options optionsP = Options <$> O.optional outputP - <*> O.optional (O.strOption (O.long "config" <> O.metavar "CONFIGFILE" <> O.help "Configuration file")) + <*> configOptP <*> O.optional (O.strOption (O.long "cwd" <> O.metavar "Dir" <> O.help "Directory to change to")) <*> O.optional inputTypeP <*> runOptparseGrammar configGrammar +configOptP :: O.Parser ConfigOpt +configOptP = file <|> noconfig <|> pure ConfigOptAuto + where + file = ConfigOpt <$> O.strOption (O.long "config" <> O.metavar "CONFIGFILE" <> O.help "Configuration file") + noconfig = O.flag' ConfigOptNo (O.long "no-config" <> O.help "Don't read configuration file") + outputP :: O.Parser Output outputP = OutputFile <$> O.strOption (O.long "output" <> O.short 'o' <> O.metavar "FILE" <> O.help "Output file") <|>