Skip to content

Commit c90a33f

Browse files
authored
Merge pull request #456 from haskell-CI/implicit-config
Read cabal.haskell-ci by default
2 parents 62c5d57 + 8291527 commit c90a33f

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# This GitHub workflow config has been generated by a script via
22
#
3-
# haskell-ci '--config=cabal.haskell-ci' 'github' 'cabal.project'
3+
# haskell-ci 'github' 'cabal.project'
44
#
55
# To regenerate the script (for example after adjusting tested-with) run
66
#
77
# haskell-ci regenerate
88
#
99
# For more information, see https://github.com/haskell-CI/haskell-ci
1010
#
11-
# REGENDATA ["--config=cabal.haskell-ci","github","cabal.project"]
11+
# REGENDATA ["github","cabal.project"]
1212
#
1313
name: Haskell-CI
1414
on:

haskell-ci.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: haskell-ci
3-
version: 0.11.20201230
3+
version: 0.11.20210101
44
synopsis: Cabal package script generator for Travis-CI
55
description:
66
Script generator (@haskell-ci@) for [Travis-CI](https://travis-ci.org/) for continuous-integration testing of Haskell Cabal packages.

src/HaskellCI.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ travisFromConfigFile
138138
travisFromConfigFile args opts path = do
139139
gitconfig <- liftIO readGitConfig
140140
cabalFiles <- getCabalFiles (optInputType' opts path) path
141-
config' <- maybe (return emptyConfig) readConfigFile (optConfig opts)
141+
config' <- findConfigFile (optConfig opts)
142142
let config = optConfigMorphism opts config'
143143
pkgs <- T.mapM (configFromCabalFile config) cabalFiles
144144
(ghcs, prj) <- case checkVersions (cfgTestedWith config) pkgs of
@@ -224,7 +224,7 @@ bashFromConfigFile
224224
bashFromConfigFile args opts path = do
225225
gitconfig <- liftIO readGitConfig
226226
cabalFiles <- getCabalFiles (optInputType' opts path) path
227-
config' <- maybe (return emptyConfig) readConfigFile (optConfig opts)
227+
config' <- findConfigFile (optConfig opts)
228228
let config = optConfigMorphism opts config'
229229
pkgs <- T.mapM (configFromCabalFile config) cabalFiles
230230
(ghcs, prj) <- case checkVersions (cfgTestedWith config) pkgs of
@@ -311,7 +311,7 @@ githubFromConfigFile
311311
githubFromConfigFile args opts path = do
312312
gitconfig <- liftIO readGitConfig
313313
cabalFiles <- getCabalFiles (optInputType' opts path) path
314-
config' <- maybe (return emptyConfig) readConfigFile (optConfig opts)
314+
config' <- findConfigFile (optConfig opts)
315315
let config = optConfigMorphism opts config'
316316
pkgs <- T.mapM (configFromCabalFile config) cabalFiles
317317
(ghcs, prj) <- case checkVersions (cfgTestedWith config) pkgs of
@@ -367,6 +367,20 @@ regenerateGitHub opts = do
367367
noGitHubScript :: IO ()
368368
noGitHubScript = putStrLn $ "No " ++ fp ++ ", skipping GitHub config regeneration"
369369

370+
-------------------------------------------------------------------------------
371+
-- Config file
372+
-------------------------------------------------------------------------------
373+
374+
findConfigFile :: MonadIO m => ConfigOpt -> m Config
375+
findConfigFile ConfigOptNo = return emptyConfig
376+
findConfigFile (ConfigOpt fp) = readConfigFile fp
377+
findConfigFile ConfigOptAuto = do
378+
let defaultPath = "cabal.haskell-ci"
379+
exists <- liftIO (doesFileExist defaultPath)
380+
if exists
381+
then readConfigFile defaultPath
382+
else return emptyConfig
383+
370384
-------------------------------------------------------------------------------
371385
-- Patches
372386
-------------------------------------------------------------------------------

src/HaskellCI/Cli.hs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,20 @@ data Command
3535

3636
data Options = Options
3737
{ optOutput :: Maybe Output
38-
, optConfig :: Maybe FilePath
38+
, optConfig :: ConfigOpt
3939
, optCwd :: Maybe FilePath
4040
, optInputType :: Maybe InputType
4141
, optConfigMorphism :: Config -> Config
4242
}
4343

44-
data Output = OutputStdout | OutputFile FilePath
45-
4644
instance Semigroup Options where
4745
Options b d c e f <> Options b' d' c' e' f' =
48-
Options (b <|> b') (d <|> d') (c <|> c') (e <|> e') (f' . f)
46+
Options (b <|> b') (d <> d') (c <|> c') (e <|> e') (f' . f)
4947

5048
defaultOptions :: Options
5149
defaultOptions = Options
5250
{ optOutput = Nothing
53-
, optConfig = Nothing
51+
, optConfig = ConfigOptAuto
5452
, optCwd = Nothing
5553
, optInputType = Nothing
5654
, optConfigMorphism = id
@@ -61,6 +59,18 @@ optionsWithOutputFile fp = defaultOptions
6159
{ optOutput = Just (OutputFile fp)
6260
}
6361

62+
data Output = OutputStdout | OutputFile FilePath
63+
64+
data ConfigOpt
65+
= ConfigOptAuto
66+
| ConfigOpt FilePath
67+
| ConfigOptNo
68+
deriving (Eq, Show)
69+
70+
instance Semigroup ConfigOpt where
71+
a <> ConfigOptAuto = a
72+
_ <> b = b
73+
6474
-------------------------------------------------------------------------------
6575
-- InputType
6676
-------------------------------------------------------------------------------
@@ -83,11 +93,17 @@ optInputType' opts path =
8393
optionsP :: O.Parser Options
8494
optionsP = Options
8595
<$> O.optional outputP
86-
<*> O.optional (O.strOption (O.long "config" <> O.metavar "CONFIGFILE" <> O.help "Configuration file"))
96+
<*> configOptP
8797
<*> O.optional (O.strOption (O.long "cwd" <> O.metavar "Dir" <> O.help "Directory to change to"))
8898
<*> O.optional inputTypeP
8999
<*> runOptparseGrammar configGrammar
90100

101+
configOptP :: O.Parser ConfigOpt
102+
configOptP = file <|> noconfig <|> pure ConfigOptAuto
103+
where
104+
file = ConfigOpt <$> O.strOption (O.long "config" <> O.metavar "CONFIGFILE" <> O.help "Configuration file")
105+
noconfig = O.flag' ConfigOptNo (O.long "no-config" <> O.help "Don't read configuration file")
106+
91107
outputP :: O.Parser Output
92108
outputP =
93109
OutputFile <$> O.strOption (O.long "output" <> O.short 'o' <> O.metavar "FILE" <> O.help "Output file") <|>

0 commit comments

Comments
 (0)