Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for weeder step #742

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ benchmarks: True
-- Build haddocks. Accepts booleans or version range.
haddock: True

-- Run weeder. Accepts booleans or version range.
-- Expects 'weeder.toml' to live at the repository root,
-- and the '.hie/' directory to be generated in the repository root.
weeder: True

-- Run cabal check
-- cabal-check: True

Expand Down
3 changes: 3 additions & 0 deletions src/HaskellCI/Auxiliary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data Auxiliary = Auxiliary
, anyJobUsesPreviewGHC :: Bool
, runHaddock :: Bool
, haddockFlags :: String
, runWeeder :: Bool
}

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

runWeeder = not (equivVersionRanges C.noVersion cfgWeeder)

extraCabalProjectFields :: FilePath -> [C.PrettyField ()]
extraCabalProjectFields rootdir = buildList $ do
-- generate package fields for URI packages.
Expand Down
2 changes: 2 additions & 0 deletions src/HaskellCI/Config/Grammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ configGrammar = Config
^^^ metahelp "RANGE" "Haddock step"
<*> optionalFieldDef "haddock-components" (field @"cfgHaddockComponents") defaultConfig
^^^ metahelp "all|libs" "Haddock components"
<*> rangeField "weeder" (field @"cfgWeeder") defaultConfig
^^^ metahelp "RANGE" "Weeder step"
<*> rangeField "no-tests-no-benchmarks" (field @"cfgNoTestsNoBench") defaultConfig
^^^ metahelp "RANGE" "Build without tests and benchmarks"
<*> rangeField "unconstrained" (field @"cfgUnconstrainted") defaultConfig
Expand Down
1 change: 1 addition & 0 deletions src/HaskellCI/Config/Initial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ initialConfig = Config
, cfgBenchmarks = anyVersion
, cfgHaddock = anyVersion
, cfgHaddockComponents = ComponentsAll
, cfgWeeder = noVersion
, cfgNoTestsNoBench = anyVersion
, cfgUnconstrainted = anyVersion
, cfgHeadHackage = defaultHeadHackage
Expand Down
1 change: 1 addition & 0 deletions src/HaskellCI/Config/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data Config = Config
, cfgBenchmarks :: !VersionRange
, cfgHaddock :: !VersionRange
, cfgHaddockComponents :: !Components
, cfgWeeder :: !VersionRange
, cfgNoTestsNoBench :: !VersionRange
, cfgUnconstrainted :: !VersionRange
, cfgHeadHackage :: !VersionRange
Expand Down
19 changes: 19 additions & 0 deletions src/HaskellCI/GitHub.hs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,15 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
-- disable-documentation disables docs in deps: https://github.com/haskell/cabal/issues/7462
sh_if range $ "$CABAL v2-haddock --disable-documentation" ++ haddockFlags ++ " $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all"

when runWeeder $
let range = RangeGHC /\ Range cfgWeeder in
let ifCond = ghCompilerVersionArithPredicate allVersions range in
for_ pkgs $ \Pkg{pkgName} -> do
githubUsesIf "weeder" "freckle/weeder-action@v2" ifCond $ buildList $ do
item ("ghc-version", ghWrapExpr "matrix.compilerVersion")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this working. Comparing strings like 8.10.7 and 8.8.4 with operators like >= wouldn't work as intended.


Add test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing strings like 8.10.7 and 8.8.4 with operators like >= wouldn't work as intended.

The strings get converted to numeric representation before comparison. E.g., with this config:

weeder: >= 9.4 && < 9.8

the resulting comparison is:

${{ env.HCNUMVER >= 90400 && env.HCNUMVER < 90800 }}

And here's a live demonstration featuring coomparison against a number like 9.10.7.

I have also now added a golden test.

item ("weeder-arguments", "--config $GITHUB_WORKSPACE/source/weeder.toml")
item ("working-directory", ghWrapExpr $ ghEnvContext $ pkgNameDirVariable' pkgName)

-- unconstrained build
unless (equivVersionRanges C.noVersion cfgUnconstrainted) $ githubRun "unconstrained build" $ do
let range = Range cfgUnconstrainted
Expand Down Expand Up @@ -855,3 +864,13 @@ parseGitHubRepo t =
-- runners support.
ghcRunsOnVer :: String
ghcRunsOnVer = "ubuntu-20.04"

ghWrapExpr :: String -> String
ghWrapExpr expr = "${{ " ++ expr ++ " }}"

ghEnvContext :: String -> String
ghEnvContext = ("env." ++)

ghCompilerVersionArithPredicate :: Set CompilerVersion -> CompilerRange -> String
ghCompilerVersionArithPredicate = compilerVersionPredicateImpl $
freeToArith $ ExprConfig ghWrapExpr ghEnvContext
26 changes: 20 additions & 6 deletions src/HaskellCI/ShVersionRange.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module HaskellCI.ShVersionRange (
compilerVersionPredicate,
compilerVersionArithPredicate,
compilerVersionPredicateImpl,
freeToArith,
ExprConfig (..),
roundDown,
) where

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

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

compilerVersionArithPredicate :: Set CompilerVersion -> CompilerRange -> String
compilerVersionArithPredicate = compilerVersionPredicateImpl freeToArith
compilerVersionArithPredicate = compilerVersionPredicateImpl shFreeToArith

compilerVersionPredicateImpl
:: (Free String -> String)
Expand Down Expand Up @@ -197,14 +200,25 @@ roundDown = go S.empty . S.toList where
-- Arithmetic expression
-------------------------------------------------------------------------------

freeToArith :: Free String -> String
freeToArith z
shWrapExpr :: String -> String
shWrapExpr expr = "$((" ++ expr ++ "))"

shFreeToArith :: Free String -> String
shFreeToArith = freeToArith $ ExprConfig shWrapExpr id

data ExprConfig = ExprConfig {
_exprWrap :: String -> String
, _varWrap :: String -> String
}

freeToArith :: ExprConfig -> Free String -> String
freeToArith (ExprConfig exprWrap varWrap) z
| z == top = "1"
| z == bottom = "0"
| otherwise = "$((" ++ go 0 z ++ "))"
| otherwise = exprWrap $ go 0 z
where
go :: Int -> Free String -> String
go _ (Var x) = x
go _ (Var x) = varWrap x
go _ F.Bottom = "1"
go _ F.Top = "0"

Expand Down