Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Jul 1, 2024
1 parent 08ae157 commit 7ef192a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 62 deletions.
125 changes: 63 additions & 62 deletions src/HaskellCI/Config/Grammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import qualified Distribution.Parsec as C
import qualified Distribution.Pretty as C
import qualified Text.PrettyPrint as PP

import HaskellCI.Cabal
import HaskellCI.Config.Components
import HaskellCI.Config.CopyFields
import HaskellCI.Config.Docspec
Expand All @@ -27,7 +26,7 @@ import HaskellCI.Config.Jobs
import HaskellCI.Config.PackageScope
import HaskellCI.Config.Type
import HaskellCI.Config.Ubuntu
import HaskellCI.Ghcup
import HaskellCI.GrammarDefault
import HaskellCI.Newtypes
import HaskellCI.OptionsGrammar
import HaskellCI.TestedWith
Expand All @@ -37,129 +36,131 @@ import HaskellCI.TestedWith
-------------------------------------------------------------------------------

configGrammar
:: ( OptionsGrammar c g, Applicative (g Config)
, c (Identity PackageScope)
, c (Identity TestedWithJobs)
, c (Identity Ubuntu)
, c (Identity Jobs)
, c (Identity CopyFields)
, c (Identity Version)
, c (Identity Natural)
, c (Identity Components)
, c Env, c CopyFields, c HeadVersion
:: ( OptionsGrammar c g
, c Components
, c CopyFields
, c CopyFields
, c Env
, c HeadVersion
, c Jobs
, c Natural
, c PackageScope
, c TestedWithJobs
, c Ubuntu
, c Version
, c (C.List C.FSep (Identity Installed) Installed)
, Applicative (g DoctestConfig)
, Applicative (g DocspecConfig)
)
=> g Config Config
configGrammar = Config
<$> C.optionalFieldDefAla "cabal-install-version" HeadVersion (field @"cfgCabalInstallVersion") defaultCabalInstallVersion
<$> optionalFieldDefAla "cabal-install-version" HeadVersion (field @"cfgCabalInstallVersion") defaultConfig
^^^ metahelp "VERSION" "cabal-install version for all jobs"
<*> C.optionalField "jobs" (field @"cfgJobs")
<*> optionalField "jobs" (field @"cfgJobs")
^^^ metahelp "JOBS" "jobs (N:M - cabal:ghc)"
<*> C.optionalFieldDef "distribution" (field @"cfgUbuntu") Jammy
<*> optionalFieldDef "distribution" (field @"cfgUbuntu") defaultConfig
^^^ metahelp "DIST" (concat
[ "distribution version ("
, intercalate ", " $ map showUbuntu [minBound..maxBound]
, ")"
])
<*> C.optionalFieldDef "jobs-selection" (field @"cfgTestedWith") TestedWithUniform
<*> optionalFieldDef "jobs-selection" (field @"cfgTestedWith") defaultConfig
^^^ metahelp "uniform|any" "Jobs selection across packages"
<*> rangeField "enabled" (field @"cfgEnabledJobs") defaultConfig
<*> rangeField "enabled" (field @"cfgEnabledJobs") defaultConfig
^^^ metahelp "RANGE" "Restrict jobs selection futher from per package tested-with"
<*> C.optionalFieldDef "copy-fields" (field @"cfgCopyFields") CopyFieldsSome
<*> optionalFieldDef "copy-fields" (field @"cfgCopyFields") defaultConfig
^^^ metahelp "none|some|all" "Copy ? fields from cabal.project fields"
<*> C.monoidalFieldAla "local-ghc-options" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgLocalGhcOptions")
<*> monoidalFieldAla "local-ghc-options" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgLocalGhcOptions")
^^^ metahelp "OPTS" "--ghc-options for local packages"
<*> C.booleanFieldDef "submodules" (field @"cfgSubmodules") False
<*> booleanFieldDef "submodules" (field @"cfgSubmodules") defaultConfig
^^^ help "Clone submodules, i.e. recursively"
<*> C.booleanFieldDef "cache" (field @"cfgCache") True
<*> booleanFieldDef "cache" (field @"cfgCache") defaultConfig
^^^ help "Disable caching"
<*> C.booleanFieldDef "install-dependencies" (field @"cfgInstallDeps") True
<*> booleanFieldDef "install-dependencies" (field @"cfgInstallDeps") defaultConfig
^^^ help "Skip separate dependency installation step"
<*> C.monoidalFieldAla "installed" (C.alaList C.FSep) (field @"cfgInstalled")
<*> monoidalFieldAla "installed" (C.alaList C.FSep) (field @"cfgInstalled")
^^^ metahelp "+/-PKG" "Specify 'constraint: ... installed' packages"
<*> rangeField "tests" (field @"cfgTests") defaultConfig
<*> rangeField "tests" (field @"cfgTests") defaultConfig
^^^ metahelp "RANGE" "Build tests with"
<*> rangeField "run-tests" (field @"cfgRunTests") defaultConfig
<*> rangeField "run-tests" (field @"cfgRunTests") defaultConfig
^^^ metahelp "RANGE" "Run tests with (note: only built tests are run)"
<*> rangeField "benchmarks" (field @"cfgBenchmarks") defaultConfig
<*> rangeField "benchmarks" (field @"cfgBenchmarks") defaultConfig
^^^ metahelp "RANGE" "Build benchmarks"
<*> rangeField "haddock" (field @"cfgHaddock") defaultConfig
<*> rangeField "haddock" (field @"cfgHaddock") defaultConfig
^^^ metahelp "RANGE" "Haddock step"
<*> C.optionalFieldDef "haddock-components" (field @"cfgHaddockComponents") ComponentsAll
<*> optionalFieldDef "haddock-components" (field @"cfgHaddockComponents") defaultConfig
^^^ metahelp "all|libs" "Haddock components"
<*> rangeField "no-tests-no-benchmarks" (field @"cfgNoTestsNoBench") defaultConfig
<*> rangeField "no-tests-no-benchmarks" (field @"cfgNoTestsNoBench") defaultConfig
^^^ metahelp "RANGE" "Build without tests and benchmarks"
<*> rangeField "unconstrained" (field @"cfgUnconstrainted") defaultConfig
<*> rangeField "unconstrained" (field @"cfgUnconstrainted") defaultConfig
^^^ metahelp "RANGE" "Make unconstrained build"
<*> rangeField "head-hackage" (field @"cfgHeadHackage") defaultConfig
<*> rangeField "head-hackage" (field @"cfgHeadHackage") defaultConfig
^^^ metahelp "RANGE" "Use head.hackage repository. Also marks as allow-failures"
<*> C.booleanFieldDef "head-hackage-override" (field @"cfgHeadHackageOverride") True
<*> booleanFieldDef "head-hackage-override" (field @"cfgHeadHackageOverride") defaultConfig
^^^ help "Use :override for head.hackage repository"
<*> C.booleanFieldDef "ghcjs-tests" (field @"cfgGhcjsTests") False
<*> booleanFieldDef "ghcjs-tests" (field @"cfgGhcjsTests") defaultConfig
^^^ help "Run tests with GHCJS (experimental, relies on cabal-plan finding test-suites)"
<*> C.monoidalFieldAla "ghcjs-tools" (C.alaList C.FSep) (field @"cfgGhcjsTools")
<*> monoidalFieldAla "ghcjs-tools" (C.alaList C.FSep) (field @"cfgGhcjsTools")
-- ^^^ metahelp "TOOL" "Additional host tools to install with GHCJS"
<*> C.booleanFieldDef "test-output-direct" (field @"cfgTestOutputDirect") True
<*> booleanFieldDef "test-output-direct" (field @"cfgTestOutputDirect") defaultConfig
^^^ help "Use --test-show-details=direct, may cause problems with build-type: Custom"
<*> C.booleanFieldDef "cabal-check" (field @"cfgCheck") True
<*> booleanFieldDef "cabal-check" (field @"cfgCheck") defaultConfig
^^^ help "Disable cabal check run"
<*> C.monoidalFieldAla "branches" (C.alaList' C.FSep C.Token') (field @"cfgOnlyBranches")
<*> monoidalFieldAla "branches" (C.alaList' C.FSep C.Token') (field @"cfgOnlyBranches")
^^^ metahelp "BRANCH" "Enable builds only for specific branches"
<*> C.monoidalFieldAla "irc-channels" (C.alaList' C.FSep C.Token') (field @"cfgIrcChannels")
<*> monoidalFieldAla "irc-channels" (C.alaList' C.FSep C.Token') (field @"cfgIrcChannels")
^^^ metahelp "IRC" "Enable IRC notifications to given channel (e.g. 'irc.libera.chat#haskell-lens')"
<*> C.freeTextField "irc-nickname" (field @"cfgIrcNickname")
<*> freeTextField "irc-nickname" (field @"cfgIrcNickname")
^^^ metahelp "NICKNAME" "Nickname with which to authenticate to an IRC server. Only used if `irc-channels` are set."
<*> C.freeTextField "irc-password" (field @"cfgIrcPassword")
<*> freeTextField "irc-password" (field @"cfgIrcPassword")
^^^ metahelp "PASSWORD" "Password with which to authenticate to an IRC server. Only used if `irc-channels` are set."
<*> C.booleanFieldDef "irc-if-in-origin-repo" (field @"cfgIrcIfInOriginRepo") False
<*> booleanFieldDef "irc-if-in-origin-repo" (field @"cfgIrcIfInOriginRepo") defaultConfig
^^^ help "Only send IRC notifications if run from the original remote (GitHub Actions only)"
<*> C.booleanFieldDef "email-notifications" (field @"cfgEmailNotifications") True
<*> booleanFieldDef "email-notifications" (field @"cfgEmailNotifications") defaultConfig
^^^ help "Disable email notifications"
<*> C.optionalFieldAla "project-name" C.Token' (field @"cfgProjectName")
<*> optionalFieldAla "project-name" C.Token' (field @"cfgProjectName")
^^^ metahelp "NAME" "Project name (used for IRC notifications), defaults to package name or name of first package listed in cabal.project file"
<*> C.booleanFieldDef "ghc-head" (field @"cfgGhcHead") False
<*> booleanFieldDef "ghc-head" (field @"cfgGhcHead") defaultConfig
^^^ help "Add ghc-head job"
<*> C.booleanFieldDef "postgresql" (field @"cfgPostgres") False
<*> booleanFieldDef "postgresql" (field @"cfgPostgres") defaultConfig
^^^ help "Add postgresql service"
<*> C.booleanFieldDef "google-chrome" (field @"cfgGoogleChrome") False
<*> booleanFieldDef "google-chrome" (field @"cfgGoogleChrome") defaultConfig
^^^ help "Add google-chrome service"
<*> C.monoidalFieldAla "env" Env (field @"cfgEnv")
<*> monoidalFieldAla "env" Env (field @"cfgEnv")
^^^ metahelp "ENV" "Environment variables per job (e.g. `8.0.2:HADDOCK=false`)"
<*> C.optionalFieldDefAla "allow-failures" Range (field @"cfgAllowFailures") noVersion
<*> optionalFieldDefAla "allow-failures" Range (field @"cfgAllowFailures") defaultConfig
^^^ metahelp "JOB" "Allow failures of particular GHC version"
<*> C.booleanFieldDef "last-in-series" (field @"cfgLastInSeries") False
<*> booleanFieldDef "last-in-series" (field @"cfgLastInSeries") defaultConfig
^^^ help "[Discouraged] Assume there are only GHCs last in major series: 8.2.* will match only 8.2.2"
<*> rangeField "linux-jobs" (field @"cfgLinuxJobs") defaultConfig
<*> rangeField "linux-jobs" (field @"cfgLinuxJobs") defaultConfig
^^^ metahelp "RANGE" "Jobs to build on Linux"
<*> rangeField "macos-jobs" (field @"cfgMacosJobs") defaultConfig
<*> rangeField "macos-jobs" (field @"cfgMacosJobs") defaultConfig
^^^ metahelp "RANGE" "Jobs to additionally build with OSX"
<*> C.booleanFieldDef "ghcup-cabal" (field @"cfgGhcupCabal") True
<*> booleanFieldDef "ghcup-cabal" (field @"cfgGhcupCabal") defaultConfig
^^^ help "Use (or don't) ghcup to install cabal"
<*> rangeField "ghcup-jobs" (field @"cfgGhcupJobs") defaultConfig
<*> rangeField "ghcup-jobs" (field @"cfgGhcupJobs") defaultConfig
^^^ metahelp "RANGE" "(Linux) jobs to use ghcup to install tools"
<*> C.optionalFieldDef "ghcup-version" (field @"cfgGhcupVersion") defaultGhcupVersion
<*> optionalFieldDef "ghcup-version" (field @"cfgGhcupVersion") defaultConfig
^^^ metahelp "VERSION" "ghcup version"
<*> C.monoidalFieldAla "apt" (alaSet' C.NoCommaFSep C.Token') (field @"cfgApt")
<*> monoidalFieldAla "apt" (alaSet' C.NoCommaFSep C.Token') (field @"cfgApt")
^^^ metahelp "PKG" "Additional apt packages to install"
<*> C.monoidalFieldAla "travis-patches" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgTravisPatches")
<*> monoidalFieldAla "travis-patches" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgTravisPatches")
^^^ metaActionHelp "PATCH" "file" ".patch files to apply to the generated Travis YAML file"
<*> C.monoidalFieldAla "github-patches" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgGitHubPatches")
<*> monoidalFieldAla "github-patches" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgGitHubPatches")
^^^ metaActionHelp "PATCH" "file" ".patch files to apply to the generated GitHub Actions YAML file"
<*> C.booleanFieldDef "insert-version" (field @"cfgInsertVersion") True
<*> booleanFieldDef "insert-version" (field @"cfgInsertVersion") defaultConfig
^^^ help "Don't insert the haskell-ci version into the generated Travis YAML file"
<*> C.optionalFieldDef "error-missing-methods" (field @"cfgErrorMissingMethods") PackageScopeLocal
<*> optionalFieldDef "error-missing-methods" (field @"cfgErrorMissingMethods") defaultConfig
^^^ metahelp "PKGSCOPE" "Insert -Werror=missing-methods for package scope (none, local, all)"
<*> C.blurFieldGrammar (field @"cfgDoctest") doctestConfigGrammar
<*> C.blurFieldGrammar (field @"cfgDocspec") docspecConfigGrammar
<*> pure [] -- constraint sets
<*> pure [] -- raw project fields
<*> C.freeTextFieldDef "raw-travis" (field @"cfgRawTravis")
<*> freeTextFieldDef "raw-travis" (field @"cfgRawTravis")
^^^ help "Raw travis commands which will be run at the very end of the script"
<*> C.freeTextField "github-action-name" (field @"cfgGitHubActionName")
<*> freeTextField "github-action-name" (field @"cfgGitHubActionName")
^^^ help "The name of GitHub Action"
<*> C.optionalFieldDef "timeout-minutes" (field @"cfgTimeoutMinutes") 60
<*> optionalFieldDef "timeout-minutes" (field @"cfgTimeoutMinutes") defaultConfig
^^^ metahelp "MINUTES" "The maximum number of minutes to let a job run"

-------------------------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions src/HaskellCI/GrammarDefault.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,27 @@ import qualified Distribution.Fields as C

import HaskellCI.OptionsGrammar

blurFieldGrammar :: OptionsGrammar c g => C.ALens' a b -> g b d -> g a d
blurFieldGrammar = C.blurFieldGrammar

monoidalFieldAla :: (OptionsGrammar c g, C.Newtype a b, c b, Monoid a) => C.FieldName -> (a -> b) -> C.ALens' s a -> g s a
monoidalFieldAla = C.monoidalFieldAla

freeTextField :: OptionsGrammar c g => C.FieldName -> C.ALens' s (Maybe String) -> g s (Maybe String)
freeTextField = C.freeTextField

freeTextFieldDef :: OptionsGrammar c g => C.FieldName -> C.ALens' s String -> g s String
freeTextFieldDef = C.freeTextFieldDef

booleanFieldDef :: (OptionsGrammar c g) => C.FieldName -> C.ALens' s Bool -> s -> g s Bool
booleanFieldDef fn l s = C.booleanFieldDef fn l (C.aview l s)

optionalField :: (OptionsGrammar c g, c a) => C.FieldName -> C.ALens' s (Maybe a) -> g s (Maybe a)
optionalField fn l = C.optionalField fn l

optionalFieldAla :: (OptionsGrammar c g, C.Newtype a b, c b) => C.FieldName -> (a -> b) -> C.ALens' s (Maybe a) -> g s (Maybe a)
optionalFieldAla fn pack l = C.optionalFieldAla fn pack l

optionalFieldDef :: (OptionsGrammar c g, c a, Eq a) => C.FieldName -> C.ALens' s a -> s -> g s a
optionalFieldDef fn l s = C.optionalFieldDef fn l (C.aview l s)

Expand Down

0 comments on commit 7ef192a

Please sign in to comment.