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

History #735

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 haskell-ci.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ library haskell-ci-internal
HaskellCI.Config.Doctest
HaskellCI.Config.Dump
HaskellCI.Config.Empty
HaskellCI.Config.Grammar
HaskellCI.Config.History
HaskellCI.Config.Initial
HaskellCI.Config.Installed
HaskellCI.Config.Jobs
HaskellCI.Config.PackageScope
HaskellCI.Config.Type
HaskellCI.Config.Ubuntu
HaskellCI.Config.Validity
HaskellCI.Diagnostics
Expand All @@ -132,6 +136,7 @@ library haskell-ci-internal
HaskellCI.GitConfig
HaskellCI.GitHub
HaskellCI.GitHub.Yaml
HaskellCI.GrammarDefault
HaskellCI.HeadHackage
HaskellCI.Jobs
HaskellCI.List
Expand Down
3 changes: 0 additions & 3 deletions src/HaskellCI/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import HaskellCI.Prelude

import qualified Distribution.Version as C

defaultCabalInstallVersion :: Maybe Version
defaultCabalInstallVersion = Just (C.mkVersion [3,10])

-- | Convert cabal-install version to a version ghcup understands.
cabalGhcupVersion :: Version -> Version
cabalGhcupVersion ver = case C.versionNumbers ver of
Expand Down
254 changes: 13 additions & 241 deletions src/HaskellCI/Config.hs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/HaskellCI/Config/ConstraintSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module HaskellCI.Config.ConstraintSet where

import HaskellCI.Prelude

import qualified Distribution.FieldGrammar as C
import qualified Distribution.FieldGrammar as C

import HaskellCI.Newtypes
import HaskellCI.OptionsGrammar
Expand Down
16 changes: 8 additions & 8 deletions src/HaskellCI/Config/Docspec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
module HaskellCI.Config.Docspec (
DocspecConfig (..),
docspecConfigGrammar,
defaultDocspecConfig,
) where

import HaskellCI.Prelude

import qualified Distribution.FieldGrammar as C
import qualified Distribution.FieldGrammar as C

import HaskellCI.GrammarDefault
import HaskellCI.OptionsGrammar

data DocspecConfig = DocspecConfig
Expand All @@ -36,15 +38,13 @@ defaultDocspecConfig = DocspecConfig
-- Grammar
-------------------------------------------------------------------------------

docspecConfigGrammar
:: (OptionsGrammar c g, Applicative (g DocspecConfig))
=> g DocspecConfig DocspecConfig
docspecConfigGrammar :: OptionsGrammar c g => g DocspecConfig DocspecConfig
docspecConfigGrammar = DocspecConfig
<$> rangeField "docspec" (field @"cfgDocspecEnabled") (cfgDocspecEnabled defaultDocspecConfig)
<$> rangeField "docspec" (field @"cfgDocspecEnabled") defaultDocspecConfig
^^^ help "Enable Docspec job"
<*> C.monoidalFieldAla "docspec-options" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgDocspecOptions")
<*> monoidalFieldAla "docspec-options" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgDocspecOptions")
^^^ metahelp "OPTS" "Additional Docspec options"
<*> C.optionalFieldDefAla "docspec-url" C.Token' (field @"cfgDocspecUrl") (cfgDocspecUrl defaultDocspecConfig)
<*> optionalFieldDefAla "docspec-url" C.Token' (field @"cfgDocspecUrl") defaultDocspecConfig
^^^ metahelp "URL" "URL to download cabal-docspec"
<*> C.optionalFieldDefAla "docspec-hash" C.Token' (field @"cfgDocspecHash") (cfgDocspecHash defaultDocspecConfig)
<*> optionalFieldDefAla "docspec-hash" C.Token' (field @"cfgDocspecHash") defaultDocspecConfig
^^^ metahelp "HASH" "SHA256 of cabal-docspec"
31 changes: 20 additions & 11 deletions src/HaskellCI/Config/Doctest.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module HaskellCI.Config.Doctest where
module HaskellCI.Config.Doctest (
DoctestConfig (..),
initialDoctestConfig,
doctestConfigGrammar,
) where

import HaskellCI.Prelude

Expand All @@ -10,6 +14,7 @@ import Distribution.Version (majorBoundVersion)
import qualified Distribution.FieldGrammar as C
import qualified Distribution.Types.PackageName as C

import HaskellCI.GrammarDefault
import HaskellCI.OptionsGrammar

data DoctestConfig = DoctestConfig
Expand All @@ -25,24 +30,28 @@ data DoctestConfig = DoctestConfig
-- Default
-------------------------------------------------------------------------------

defaultDoctestVersion :: VersionRange
defaultDoctestVersion = majorBoundVersion (mkVersion [0,22,0])
initialDoctestConfig :: DoctestConfig
initialDoctestConfig = DoctestConfig
{ cfgDoctestEnabled = noVersion
, cfgDoctestOptions = []
, cfgDoctestVersion = majorBoundVersion (mkVersion [0,22,0])
, cfgDoctestFilterEnvPkgs = []
, cfgDoctestFilterSrcPkgs = []
}

-------------------------------------------------------------------------------
-- Grammar
-------------------------------------------------------------------------------

doctestConfigGrammar
:: (OptionsGrammar c g, Applicative (g DoctestConfig))
=> g DoctestConfig DoctestConfig
doctestConfigGrammar :: OptionsGrammar c g => g DoctestConfig DoctestConfig
doctestConfigGrammar = DoctestConfig
<$> rangeField "doctest" (field @"cfgDoctestEnabled") noVersion
<$> rangeField "doctest" (field @"cfgDoctestEnabled") initialDoctestConfig
^^^ help "Enable Doctest job"
<*> C.monoidalFieldAla "doctest-options" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgDoctestOptions")
<*> monoidalFieldAla "doctest-options" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgDoctestOptions")
^^^ metahelp "OPTS" "Additional Doctest options"
<*> C.optionalFieldDef "doctest-version" (field @"cfgDoctestVersion") defaultDoctestVersion
<*> optionalFieldDef "doctest-version" (field @"cfgDoctestVersion") initialDoctestConfig
^^^ metahelp "RANGE" "Doctest version"
<*> C.monoidalFieldAla "doctest-filter-packages" (C.alaList C.NoCommaFSep) (field @"cfgDoctestFilterEnvPkgs")
<*> monoidalFieldAla "doctest-filter-packages" (C.alaList C.NoCommaFSep) (field @"cfgDoctestFilterEnvPkgs")
^^^ metahelp "PKGS" "Filter packages from .ghc.environment file"
<*> C.monoidalFieldAla "doctest-skip" (C.alaList C.NoCommaFSep) (field @"cfgDoctestFilterSrcPkgs")
<*> monoidalFieldAla "doctest-skip" (C.alaList C.NoCommaFSep) (field @"cfgDoctestFilterSrcPkgs")
^^^ metahelp "PKGS" "Skip doctests for these packages"
2 changes: 1 addition & 1 deletion src/HaskellCI/Config/Dump.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FunctionalDependencies #-}
module HaskellCI.Config.Dump where

import HaskellCI.Prelude
Expand Down
4 changes: 2 additions & 2 deletions src/HaskellCI/Config/Empty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module HaskellCI.Config.Empty where

import HaskellCI.Prelude

import qualified Distribution.FieldGrammar as C
import qualified Distribution.Fields as C
import qualified Distribution.FieldGrammar as C
import qualified Distribution.Fields as C

import HaskellCI.OptionsGrammar

Expand Down
183 changes: 183 additions & 0 deletions src/HaskellCI/Config/Grammar.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module HaskellCI.Config.Grammar where

import HaskellCI.Prelude

import qualified Data.Map as M
import qualified Distribution.Compat.CharParsing as C
import qualified Distribution.Compat.Newtype as C
import qualified Distribution.FieldGrammar as C
import qualified Distribution.Parsec as C
import qualified Distribution.Pretty as C
import qualified Text.PrettyPrint as PP

import HaskellCI.Config.Components
import HaskellCI.Config.CopyFields
import HaskellCI.Config.Docspec
import HaskellCI.Config.Doctest
import HaskellCI.Config.History
import HaskellCI.Config.Installed
import HaskellCI.Config.Jobs
import HaskellCI.Config.PackageScope
import HaskellCI.Config.Type
import HaskellCI.Config.Ubuntu
import HaskellCI.GrammarDefault
import HaskellCI.Newtypes
import HaskellCI.OptionsGrammar
import HaskellCI.TestedWith

-------------------------------------------------------------------------------
-- Grammar
-------------------------------------------------------------------------------

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

-------------------------------------------------------------------------------
-- Env
-------------------------------------------------------------------------------

newtype Env = Env (M.Map Version String)
deriving anyclass (C.Newtype (M.Map Version String))

instance C.Parsec Env where
parsec = Env . M.fromList <$> C.parsecLeadingCommaList p where
p = do
v <- C.parsec
_ <- C.char ':'
s <- C.munch1 $ \c -> c /= ','
return (v, s)

instance C.Pretty Env where
pretty (Env m) = PP.fsep . PP.punctuate PP.comma . map p . M.toList $ m where
p (v, s) = C.pretty v PP.<> PP.colon PP.<> PP.text s
Loading
Loading