Skip to content

Commit 53344d0

Browse files
authored
Merge pull request #44 from serokell/martoon/smart-progress-option
Disable progress bar in CI automatically
2 parents be03fa9 + 0d6e619 commit 53344d0

5 files changed

Lines changed: 37 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
Unreleased
88
==========
99

10+
0.1.2
11+
=======
12+
13+
* [#44](https://github.com/serokell/xrefcheck/pull/44)
14+
+ Decide whether to show progress bar by default depending on `CI` env variable.
15+
+ Added `--progress` option.
16+
1017
0.1.1.2
1118
=======
1219

exec/Main.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Xrefcheck.Config
1616
import Xrefcheck.Progress
1717
import Xrefcheck.Scan
1818
import Xrefcheck.Scanners
19+
import Xrefcheck.System
1920
import Xrefcheck.Verify
2021

2122
formats :: FormatsSupport
@@ -39,14 +40,17 @@ defaultAction Options{..} = do
3940
Just configPath -> do
4041
readConfig configPath
4142

42-
repoInfo <- allowRewrite oShowProgressBar $ \rw -> do
43+
withinCI <- askWithinCI
44+
let showProgressBar = oShowProgressBar ?: not withinCI
45+
46+
repoInfo <- allowRewrite showProgressBar $ \rw -> do
4347
let fullConfig = addTraversalOptions (cTraversal config) oTraversalOptions
4448
gatherRepoInfo rw formats fullConfig root
4549

4650
when oVerbose $
4751
fmtLn $ "=== Repository data ===\n\n" <> indentF 2 (build repoInfo)
4852

49-
verifyRes <- allowRewrite oShowProgressBar $ \rw ->
53+
verifyRes <- allowRewrite showProgressBar $ \rw ->
5054
verifyRepo rw (cVerification config) oMode root repoInfo
5155
case verifyErrors verifyRes of
5256
Nothing ->

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
spec-version: 0.31.0
66

77
name: xrefcheck
8-
version: 0.1.1.2
8+
version: 0.1.2
99
github: serokell/xrefcheck
1010
license: MPL-2.0
1111
license-file: LICENSE

src/Xrefcheck/CLI.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Xrefcheck.CLI
1818
) where
1919

2020
import Data.Version (showVersion)
21-
import Options.Applicative (Parser, ReadM, command, eitherReader, execParser, fullDesc, help,
21+
import Options.Applicative (Parser, ReadM, command, eitherReader, execParser, flag', fullDesc, help,
2222
helper, hsubparser, info, infoOption, long, metavar, option, progDesc,
2323
short, strOption, switch, value)
2424
import Paths_xrefcheck (version)
@@ -50,7 +50,7 @@ data Options = Options
5050
, oRoot :: FilePath
5151
, oMode :: VerifyMode
5252
, oVerbose :: Bool
53-
, oShowProgressBar :: Bool
53+
, oShowProgressBar :: Maybe Bool
5454
, oTraversalOptions :: TraversalOptions
5555
}
5656

@@ -99,9 +99,16 @@ optionsParser = do
9999
short 'v' <>
100100
long "verbose" <>
101101
help "Report repository scan and verification details."
102-
oShowProgressBar <- fmap not . switch $
103-
long "no-progress" <>
104-
help "Do not display progress bar during verification."
102+
oShowProgressBar <- asum
103+
[ flag' (Just True) $
104+
long "progress" <>
105+
help "Display progress bar during verification. \
106+
\This is enabled by default unless `CI` env var is set to true."
107+
, flag' (Just False) $
108+
long "no-progress" <>
109+
help "Do not display progress bar during verification."
110+
, pure Nothing
111+
]
105112
oTraversalOptions <- traversalOptionsParser
106113
return Options{..}
107114

src/Xrefcheck/System.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
module Xrefcheck.System
77
( readingSystem
8+
, askWithinCI
89
, RelGlobPattern (..)
910
, bindGlobPattern
1011
) where
1112

1213
import Data.Aeson (FromJSON (..), withText)
14+
import qualified Data.Char as C
1315
import GHC.IO.Unsafe (unsafePerformIO)
1416
import System.Directory (canonicalizePath)
17+
import System.Environment (lookupEnv)
1518
import System.FilePath ((</>))
1619
import qualified System.FilePath.Glob as Glob
1720

@@ -20,6 +23,14 @@ import qualified System.FilePath.Glob as Glob
2023
readingSystem :: IO a -> a
2124
readingSystem = unsafePerformIO
2225

26+
-- | Heuristics to check whether we are running within CI.
27+
-- Check the respective env variable which is usually set in all CIs.
28+
askWithinCI :: IO Bool
29+
askWithinCI = lookupEnv "CI" <&> \case
30+
Just "1" -> True
31+
Just (map C.toLower -> "true") -> True
32+
_ -> False
33+
2334
-- | Glob pattern relative to repository root.
2435
newtype RelGlobPattern = RelGlobPattern FilePath
2536

0 commit comments

Comments
 (0)