Skip to content

Commit 2f58ce8

Browse files
committed
Support for weeder step
1 parent 5e5b27d commit 2f58ce8

File tree

7 files changed

+53
-13
lines changed

7 files changed

+53
-13
lines changed

cabal.haskell-ci

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ghc-head: False
2323
-- remove cabal noise from test output
2424
-- cabal-noise: False
2525

26-
-- Build tests. In addition to True and False you may specify
26+
-- Build tests. Alternatively to True and False you may specify
2727
-- a version range, e.g. >= 8.0 to build tests only in some jobs.
2828
tests: True
2929

src/HaskellCI/Auxiliary.hs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ data Auxiliary = Auxiliary
4949
, anyJobUsesPreviewGHC :: Bool
5050
, runHaddock :: Bool
5151
, haddockFlags :: String
52+
, runWeeder :: Bool
5253
}
5354

5455
auxiliary :: Config -> Project URI Void Package -> JobVersions -> Auxiliary
@@ -84,6 +85,8 @@ auxiliary Config {..} prj JobVersions {..} = Auxiliary {..}
8485
ComponentsAll -> " --haddock-all"
8586
ComponentsLibs -> ""
8687

88+
runWeeder = not (equivVersionRanges C.noVersion cfgWeeder)
89+
8790
extraCabalProjectFields :: FilePath -> [C.PrettyField ()]
8891
extraCabalProjectFields rootdir = buildList $ do
8992
-- generate package fields for URI packages.

src/HaskellCI/Config/Grammar.hs

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ configGrammar = Config
9090
^^^ metahelp "RANGE" "Haddock step"
9191
<*> optionalFieldDef "haddock-components" (field @"cfgHaddockComponents") defaultConfig
9292
^^^ metahelp "all|libs" "Haddock components"
93+
<*> rangeField "weeder" (field @"cfgWeeder") defaultConfig
94+
^^^ metahelp "RANGE" "Weeder step"
9395
<*> rangeField "no-tests-no-benchmarks" (field @"cfgNoTestsNoBench") defaultConfig
9496
^^^ metahelp "RANGE" "Build without tests and benchmarks"
9597
<*> rangeField "unconstrained" (field @"cfgUnconstrainted") defaultConfig

src/HaskellCI/Config/Initial.hs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ initialConfig = Config
3737
, cfgBenchmarks = anyVersion
3838
, cfgHaddock = anyVersion
3939
, cfgHaddockComponents = ComponentsAll
40+
, cfgWeeder = anyVersion
4041
, cfgNoTestsNoBench = anyVersion
4142
, cfgUnconstrainted = anyVersion
4243
, cfgHeadHackage = defaultHeadHackage

src/HaskellCI/Config/Type.hs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ data Config = Config
4242
, cfgBenchmarks :: !VersionRange
4343
, cfgHaddock :: !VersionRange
4444
, cfgHaddockComponents :: !Components
45+
, cfgWeeder :: !VersionRange
4546
, cfgNoTestsNoBench :: !VersionRange
4647
, cfgUnconstrainted :: !VersionRange
4748
, cfgHeadHackage :: !VersionRange

src/HaskellCI/GitHub.hs

+25-6
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ makeGitHub
101101
-> Either HsCiError GitHub
102102
makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
103103
let envEnv = Map.fromList
104-
[ ("HCNAME", "${{ matrix.compiler }}") -- e.g. ghc-8.8.4
105-
, ("HCKIND", "${{ matrix.compilerKind }}") -- ghc
106-
, ("HCVER", "${{ matrix.compilerVersion }}") -- 8.8.4
104+
[ ("HCNAME", ghWrapExpr "matrix.compiler") -- e.g. ghc-8.8.4
105+
, ("HCKIND", ghWrapExpr "matrix.compilerKind") -- ghc
106+
, ("HCVER", ghWrapExpr "matrix.compilerVersion") -- 8.8.4
107107
]
108108

109109
-- Validity checks
@@ -536,6 +536,15 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
536536
-- disable-documentation disables docs in deps: https://github.com/haskell/cabal/issues/7462
537537
sh_if range $ "$CABAL v2-haddock --disable-documentation" ++ haddockFlags ++ " $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all"
538538

539+
when runWeeder $
540+
let range = RangeGHC /\ Range cfgWeeder in
541+
let ifCond = ghCompilerVersionArithPredicate allVersions range in
542+
for_ pkgs $ \Pkg{pkgName} -> do
543+
githubUsesIf "weeder" "freckle/weeder-action@v2" ifCond $ buildList $ do
544+
item ("ghc-version", ghWrapExpr "matrix.compilerVersion")
545+
item ("weeder-arguments", "--config $GITHUB_WORKSPACE/source/weeder.toml")
546+
item ("working-directory", ghWrapExpr $ ghEnvContext $ pkgNameDirVariable' pkgName)
547+
539548
-- unconstrained build
540549
unless (equivVersionRanges C.noVersion cfgUnconstrainted) $ githubRun "unconstrained build" $ do
541550
let range = Range cfgUnconstrainted
@@ -590,7 +599,7 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
590599
, ghjSteps = steps
591600
, ghjIf = Nothing
592601
, ghjContainer = Just $ "buildpack-deps:" ++ ubuntuVer
593-
, ghjContinueOnError = Just "${{ matrix.allow-failure }}"
602+
, ghjContinueOnError = Just $ ghWrapExpr "matrix.allow-failure"
594603
, ghjServices = mconcat
595604
[ Map.singleton "postgres" postgresService | cfgPostgres ]
596605
, ghjTimeout = max 10 cfgTimeoutMinutes
@@ -764,10 +773,10 @@ ircJob actionName mainJobName projectName cfg gitconfig = item ("irc", GitHubJob
764773
, Just repo <- parseGitHubRepo url
765774

766775
= Just
767-
$ "${{ always() && (github.repository == '" ++ T.unpack repo ++ "') }}"
776+
$ ghWrapExpr "always() && (github.repository == '" ++ T.unpack repo ++ "')"
768777

769778
| otherwise
770-
= Just "${{ always() }}"
779+
= Just $ ghWrapExpr "always()"
771780
-- Use always() above to ensure that the IRC job will still run even if
772781
-- the build job itself fails (see #437).
773782

@@ -855,3 +864,13 @@ parseGitHubRepo t =
855864
-- runners support.
856865
ghcRunsOnVer :: String
857866
ghcRunsOnVer = "ubuntu-20.04"
867+
868+
ghWrapExpr :: String -> String
869+
ghWrapExpr expr = "${{ " ++ expr ++ " }}"
870+
871+
ghEnvContext :: String -> String
872+
ghEnvContext = ("env." ++)
873+
874+
ghCompilerVersionArithPredicate :: Set CompilerVersion -> CompilerRange -> String
875+
ghCompilerVersionArithPredicate = compilerVersionPredicateImpl $
876+
freeToArith $ ExprConfig ghWrapExpr ghEnvContext

src/HaskellCI/ShVersionRange.hs

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module HaskellCI.ShVersionRange (
22
compilerVersionPredicate,
33
compilerVersionArithPredicate,
4+
compilerVersionPredicateImpl,
5+
freeToArith,
6+
ExprConfig (..),
47
roundDown,
58
) where
69

@@ -21,11 +24,11 @@ import HaskellCI.Compiler
2124
-- >>> import qualified Distribution.Version as C
2225

2326
compilerVersionPredicate :: Set CompilerVersion -> CompilerRange -> String
24-
compilerVersionPredicate = compilerVersionPredicateImpl (toTest . freeToArith) where
27+
compilerVersionPredicate = compilerVersionPredicateImpl (toTest . shFreeToArith) where
2528
toTest expr = "[ " ++ expr ++ " -ne 0 ]"
2629

2730
compilerVersionArithPredicate :: Set CompilerVersion -> CompilerRange -> String
28-
compilerVersionArithPredicate = compilerVersionPredicateImpl freeToArith
31+
compilerVersionArithPredicate = compilerVersionPredicateImpl shFreeToArith
2932

3033
compilerVersionPredicateImpl
3134
:: (Free String -> String)
@@ -197,14 +200,25 @@ roundDown = go S.empty . S.toList where
197200
-- Arithmetic expression
198201
-------------------------------------------------------------------------------
199202

200-
freeToArith :: Free String -> String
201-
freeToArith z
203+
shWrapExpr :: String -> String
204+
shWrapExpr expr = "$((" ++ expr ++ "))"
205+
206+
shFreeToArith :: Free String -> String
207+
shFreeToArith = freeToArith $ ExprConfig shWrapExpr id
208+
209+
data ExprConfig = ExprConfig {
210+
_exprWrap :: String -> String
211+
, _varWrap :: String -> String
212+
}
213+
214+
freeToArith :: ExprConfig -> Free String -> String
215+
freeToArith (ExprConfig exprWrap varWrap) z
202216
| z == top = "1"
203217
| z == bottom = "0"
204-
| otherwise = "$((" ++ go 0 z ++ "))"
218+
| otherwise = exprWrap $ go 0 z
205219
where
206220
go :: Int -> Free String -> String
207-
go _ (Var x) = x
221+
go _ (Var x) = varWrap x
208222
go _ F.Bottom = "1"
209223
go _ F.Top = "0"
210224

0 commit comments

Comments
 (0)