Skip to content

Commit

Permalink
Merge pull request #456 from haskell-CI/implicit-config
Browse files Browse the repository at this point in the history
Read cabal.haskell-ci by default
  • Loading branch information
phadej authored Jan 1, 2021
2 parents 62c5d57 + 8291527 commit c90a33f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 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
#
# haskell-ci regenerate
#
# 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:
Expand Down
2 changes: 1 addition & 1 deletion haskell-ci.cabal
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 17 additions & 3 deletions src/HaskellCI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
-------------------------------------------------------------------------------
Expand Down
28 changes: 22 additions & 6 deletions src/HaskellCI/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
-------------------------------------------------------------------------------
Expand All @@ -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") <|>
Expand Down

0 comments on commit c90a33f

Please sign in to comment.