Skip to content

Commit

Permalink
Merge pull request #450 from haskell-CI/docspec-2
Browse files Browse the repository at this point in the history
Add cabal-docspec support
  • Loading branch information
phadej authored Dec 30, 2020
2 parents f782267 + 944bcb7 commit 62c5d57
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 18 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ jobs:
rm -f cabal-plan.xz
chmod a+x $HOME/.cabal/bin/cabal-plan
cabal-plan --version
- name: install cabal-docspec
run: |
mkdir -p $HOME/.cabal/bin
curl -sL https://github.com/phadej/cabal-extras/releases/download/cabal-docspec-0.0.0.20201230.1/cabal-docspec-0.0.0.20201230.1.xz > cabal-docspec.xz
echo '18caf4f361fadd978782f08e78f42d21d4f177567419055ffccae19b8214852d cabal-docspec.xz' | sha256sum -c -
xz -d < cabal-docspec.xz > $HOME/.cabal/bin/cabal-docspec
rm -f cabal-docspec.xz
chmod a+x $HOME/.cabal/bin/cabal-docspec
cabal-docspec --version
- name: install doctest
run: |
$CABAL --store-dir=$HOME/.haskell-ci-tools/store v2-install $ARG_COMPILER --ignore-project -j2 doctest --constraint='doctest ^>=0.17'
Expand Down Expand Up @@ -220,6 +229,10 @@ jobs:
doctest --fast -XNoImplicitPrelude -XBangPatterns -XDeriveAnyClass -XDeriveFoldable -XDeriveFunctor -XDeriveGeneric -XDeriveTraversable -XDerivingStrategies -XGeneralizedNewtypeDeriving -XScopedTypeVariables src
cd ${PKGDIR_cabal_install_parsers} || false
doctest --fast src
- name: docspec
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all
cabal-docspec $ARG_COMPILER --verbose --timeout 2
- name: hlint
run: |
if [ $((HCNUMVER >= 81000 && HCNUMVER < 81004)) -ne 0 ] ; then (cd ${PKGDIR_haskell_ci} && hlint -h ${GITHUB_WORKSPACE}/source/.hlint.yaml -XNoImplicitPrelude -XBangPatterns -XDeriveAnyClass -XDeriveFoldable -XDeriveFunctor -XDeriveGeneric -XDeriveTraversable -XDerivingStrategies -XGeneralizedNewtypeDeriving -XScopedTypeVariables src) ; fi
Expand Down
4 changes: 4 additions & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ doctest-options: --fast
-- doctest-version: ==0.13.*
doctest-filter-packages: base-compat-batteries

-- Run cabal-docspec
docspec: True
docspec-options: --verbose --timeout 2

-- macOS job
osx: 8.4.4 8.6.5

Expand Down
3 changes: 2 additions & 1 deletion haskell-ci.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: haskell-ci
version: 0.11.20201227
version: 0.11.20201230
synopsis: Cabal package script generator for Travis-CI
description:
Script generator (@haskell-ci@) for [Travis-CI](https://travis-ci.org/) for continuous-integration testing of Haskell Cabal packages.
Expand Down Expand Up @@ -77,6 +77,7 @@ library haskell-ci-internal
HaskellCI.Config
HaskellCI.Config.ConstraintSet
HaskellCI.Config.CopyFields
HaskellCI.Config.Docspec
HaskellCI.Config.Doctest
HaskellCI.Config.Dump
HaskellCI.Config.Folds
Expand Down
3 changes: 3 additions & 0 deletions src/HaskellCI/Auxiliary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import HaskellCI.Compiler
import HaskellCI.Config
import HaskellCI.Config.CopyFields
import HaskellCI.Config.Doctest
import HaskellCI.Config.Docspec
import HaskellCI.Jobs
import HaskellCI.List
import HaskellCI.Package
Expand All @@ -37,6 +38,7 @@ data Auxiliary = Auxiliary
, uris :: [URI]
, projectName :: String
, doctestEnabled :: Bool
, docspecEnabled :: Bool
, hasTests :: CompilerRange
, hasLibrary :: Bool
, extraCabalProjectFields :: [C.PrettyField ()]
Expand All @@ -51,6 +53,7 @@ auxiliary Config {..} prj JobVersions {..} = Auxiliary {..}
projectName = fromMaybe (pkgName $ Prelude.head pkgs) cfgProjectName

doctestEnabled = any (maybeGHC False (`C.withinRange` cfgDoctestEnabled cfgDoctest)) versions
docspecEnabled = any (maybeGHC False (`C.withinRange` cfgDocspecEnabled cfgDocspec)) versions

testShowDetails
| cfgTestOutputDirect = " --test-show-details=direct"
Expand Down
26 changes: 10 additions & 16 deletions src/HaskellCI/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import qualified Text.PrettyPrint as PP
import HaskellCI.Config.ConstraintSet
import HaskellCI.Config.CopyFields
import HaskellCI.Config.Doctest
import HaskellCI.Config.Docspec
import HaskellCI.Config.Folds
import HaskellCI.Config.HLint
import HaskellCI.Config.Installed
Expand Down Expand Up @@ -84,6 +85,7 @@ data Config = Config
, cfgInsertVersion :: !Bool
, cfgErrorMissingMethods :: !PackageScope
, cfgDoctest :: !DoctestConfig
, cfgDocspec :: !DocspecConfig
, cfgHLint :: !HLintConfig
, cfgConstraintSets :: [ConstraintSet]
, cfgRawProject :: [C.PrettyField ()]
Expand All @@ -101,21 +103,9 @@ emptyConfig = Config
, cfgUbuntu = Xenial
, cfgTestedWith = TestedWithUniform
, cfgCopyFields = CopyFieldsSome
, cfgDoctest = DoctestConfig
{ cfgDoctestEnabled = noVersion
, cfgDoctestOptions = []
, cfgDoctestVersion = defaultDoctestVersion
, cfgDoctestFilterEnvPkgs = []
, cfgDoctestFilterSrcPkgs = []
}
, cfgHLint = HLintConfig
{ cfgHLintEnabled = False
, cfgHLintJob = HLintJobLatest
, cfgHLintYaml = Nothing
, cfgHLintVersion = defaultHLintVersion
, cfgHLintOptions = []
, cfgHLintDownload = True
}
, cfgDoctest = defaultDoctestConfig
, cfgDocspec = defaultDocspecConfig
, cfgHLint = defaultHLintConfig
, cfgLocalGhcOptions = []
, cfgConstraintSets = []
, cfgSubmodules = False
Expand Down Expand Up @@ -160,7 +150,10 @@ emptyConfig = Config
-------------------------------------------------------------------------------

configGrammar
:: (OptionsGrammar g, Applicative (g Config), Applicative (g DoctestConfig), Applicative (g HLintConfig))
:: ( OptionsGrammar g, Applicative (g Config)
, Applicative (g DoctestConfig)
, Applicative (g DocspecConfig)
, Applicative (g HLintConfig))
=> g Config Config
configGrammar = Config
<$> C.optionalFieldDefAla "cabal-install-version" HeadVersion (field @"cfgCabalInstallVersion") defaultCabalInstallVersion
Expand Down Expand Up @@ -242,6 +235,7 @@ configGrammar = Config
<*> C.optionalFieldDef "error-missing-methods" (field @"cfgErrorMissingMethods") PackageScopeLocal
^^^ metahelp "PKGSCOPE" "Insert -Werror=missing-methods for package scope (none, local, all)"
<*> C.blurFieldGrammar (field @"cfgDoctest") doctestConfigGrammar
<*> C.blurFieldGrammar (field @"cfgDocspec") docspecConfigGrammar
<*> C.blurFieldGrammar (field @"cfgHLint") hlintConfigGrammar
<*> pure [] -- constraint sets
<*> pure [] -- raw project fields
Expand Down
48 changes: 48 additions & 0 deletions src/HaskellCI/Config/Docspec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module HaskellCI.Config.Docspec where

import HaskellCI.Prelude

import qualified Distribution.FieldGrammar as C
import qualified Distribution.Parsec.Newtypes as C

import HaskellCI.OptionsGrammar

data DocspecConfig = DocspecConfig
{ cfgDocspecEnabled :: !VersionRange
, cfgDocspecOptions :: [String]
, cfgDocspecUrl :: String
, cfgDocspecHash :: String
}
deriving (Show, Generic, Binary)

-------------------------------------------------------------------------------
-- Default
-------------------------------------------------------------------------------

defaultDocspecConfig :: DocspecConfig
defaultDocspecConfig = DocspecConfig
{ cfgDocspecEnabled = noVersion
, cfgDocspecOptions = []
, cfgDocspecUrl = "https://github.com/phadej/cabal-extras/releases/download/cabal-docspec-0.0.0.20201230.1/cabal-docspec-0.0.0.20201230.1.xz"
, cfgDocspecHash = "18caf4f361fadd978782f08e78f42d21d4f177567419055ffccae19b8214852d"
}

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

docspecConfigGrammar
:: (OptionsGrammar g, Applicative (g DocspecConfig))
=> g DocspecConfig DocspecConfig
docspecConfigGrammar = DocspecConfig
<$> rangeField "docspec" (field @"cfgDocspecEnabled") noVersion
^^^ help "Enable Docspec job"
<*> C.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)
^^^ metahelp "URL" "URL to download cabal-docspec"
<*> C.optionalFieldDefAla "docspec-hash" C.Token' (field @"cfgDocspecHash") (cfgDocspecHash defaultDocspecConfig)
^^^ metahelp "HASH" "SHA256 of cabal-docspec"
13 changes: 13 additions & 0 deletions src/HaskellCI/Config/Doctest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@ data DoctestConfig = DoctestConfig
}
deriving (Show, Generic, Binary)

-------------------------------------------------------------------------------
-- Default
-------------------------------------------------------------------------------

defaultDoctestVersion :: VersionRange
defaultDoctestVersion = majorBoundVersion (mkVersion [0,17])

defaultDoctestConfig :: DoctestConfig
defaultDoctestConfig = DoctestConfig
{ cfgDoctestEnabled = noVersion
, cfgDoctestOptions = []
, cfgDoctestVersion = defaultDoctestVersion
, cfgDoctestFilterEnvPkgs = []
, cfgDoctestFilterSrcPkgs = []
}

-------------------------------------------------------------------------------
-- Grammar
-------------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions src/HaskellCI/Config/HLint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,23 @@ data HLintConfig = HLintConfig
}
deriving (Show, Generic, Binary)

-------------------------------------------------------------------------------
-- Default
-------------------------------------------------------------------------------

defaultHLintVersion :: VersionRange
defaultHLintVersion = withinVersion (mkVersion [3,2])

defaultHLintConfig :: HLintConfig
defaultHLintConfig = HLintConfig
{ cfgHLintEnabled = False
, cfgHLintJob = HLintJobLatest
, cfgHLintYaml = Nothing
, cfgHLintVersion = defaultHLintVersion
, cfgHLintOptions = []
, cfgHLintDownload = True
}

-------------------------------------------------------------------------------
-- HLintJob
-------------------------------------------------------------------------------
Expand Down
21 changes: 20 additions & 1 deletion src/HaskellCI/GitHub.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import HaskellCI.Auxiliary
import HaskellCI.Compiler
import HaskellCI.Config
import HaskellCI.Config.ConstraintSet
import HaskellCI.Config.Docspec
import HaskellCI.Config.Doctest
import HaskellCI.Config.HLint
import HaskellCI.Config.Installed
-- import HaskellCI.Config.Jobs
import HaskellCI.Config.PackageScope
import HaskellCI.GitConfig
import HaskellCI.GitHub.Yaml
Expand Down Expand Up @@ -190,6 +190,17 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
sh "chmod a+x $HOME/.cabal/bin/cabal-plan"
sh "cabal-plan --version"

when docspecEnabled $ githubRun "install cabal-docspec" $ do
let hash = cfgDocspecHash cfgDocspec
url = cfgDocspecUrl cfgDocspec
sh "mkdir -p $HOME/.cabal/bin"
sh $ "curl -sL " ++ url ++ " > cabal-docspec.xz"
sh $ "echo '" ++ hash ++ " cabal-docspec.xz' | sha256sum -c -"
sh "xz -d < cabal-docspec.xz > $HOME/.cabal/bin/cabal-docspec"
sh "rm -f cabal-docspec.xz"
sh "chmod a+x $HOME/.cabal/bin/cabal-docspec"
sh "cabal-docspec --version"

when doctestEnabled $ githubRun "install doctest" $ do
let range = Range (cfgDoctestEnabled cfgDoctest) /\ doctestJobVersionRange
sh_if range "$CABAL --store-dir=$HOME/.haskell-ci-tools/store v2-install $ARG_COMPILER --ignore-project -j2 doctest --constraint='doctest ^>=0.17'"
Expand Down Expand Up @@ -346,6 +357,14 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
change_dir_if vr $ pkgNameDirVariable pkgName
sh_if vr $ "doctest " ++ doctestOptions ++ " " ++ args'

-- docspec
when docspecEnabled $ githubRun "docspec" $ do
let docspecOptions = cfgDocspecOptions cfgDocspec
let range = Range (cfgDocspecEnabled cfgDocspec)
-- we need to rebuild, if tests screwed something.
sh_if range "$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all"
sh_if range $ unwords $ "cabal-docspec $ARG_COMPILER" : docspecOptions

-- hlint
when (cfgHLintEnabled cfgHLint) $ githubRun "hlint" $ do
let "" <+> ys = ys
Expand Down

0 comments on commit 62c5d57

Please sign in to comment.