From c44053d70d2d9b5e34894d818c00ecba8555728b Mon Sep 17 00:00:00 2001 From: Brandon Chinn Date: Mon, 23 Nov 2020 10:45:43 -0800 Subject: [PATCH 1/4] Add CI --- .circleci/config.yml | 165 +++++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 + 2 files changed, 167 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..b0a9f7f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,165 @@ +version: 2.1 + +executors: + ubuntu: + parameters: + stack_yaml: + type: string + default: stack.yaml + latest: + type: boolean + default: false + + docker: + - image: cimg/base:2020.01 + shell: /bin/bash -eux -o pipefail + environment: + STACK_YAML: << parameters.stack_yaml >> + CI_LATEST: <<# parameters.latest >>1<> + +commands: + install_stack: + steps: + - run: + name: Install stack + command: | + sudo apt-get update + curl -sSL https://get.haskellstack.org/ | sh + stack --version + + with_stack_cache: + parameters: + install_deps: + type: steps + + steps: + - run: + name: Build cache key + command: | + mkdir -p .ci + stack --version | tee .ci/stack-key.txt + echo "${STACK_YAML}" | tee -a .ci/stack-key.txt + shasum "${STACK_YAML}" | tee -a .ci/stack-key.txt + - restore_cache: + keys: + - v0-{{ .Environment.CIRCLE_JOB }}-{{ checksum ".ci/stack-key.txt" }}-{{ checksum "package.yaml" }} + - v0-{{ .Environment.CIRCLE_JOB }}-{{ checksum ".ci/stack-key.txt" }} + - << parameters.install_deps >> + - save_cache: + key: v0-{{ .Environment.CIRCLE_JOB }}-{{ checksum ".ci/stack-key.txt" }}-{{ checksum "package.yaml" }} + paths: + - ~/.stack + - .stack-work + + install_stack_deps: + steps: + - with_stack_cache: + install_deps: + - run: + name: Build external dependencies + command: stack build --test --only-dependencies + +jobs: + lint: + executor: ubuntu + steps: + - checkout + - install_stack + - with_stack_cache: + install_deps: + - run: + name: Build linters + command: stack build hlint stylish-haskell + - run: + name: Install Python + command: sudo apt-get install -y python + - run: + name: Install pre-commit + command: curl https://pre-commit.com/install-local.py | python - + - run: + name: Run pre-commit + command: pre-commit run --all-files -v --show-diff-on-failure + ENVIRONMENT: + SKIP: no-commit-to-branch + + run_build_and_test: + parameters: + stack_yaml: + type: string + default: stack.yaml + latest: + type: boolean + default: false + + executor: + name: ubuntu + stack_yaml: << parameters.stack_yaml >> + latest: << parameters.latest >> + + steps: + - checkout + - install_stack + - install_stack_deps + - run: + name: Build + command: | + STACK_ARGS=( + --test + --no-run-tests + <<# parameters.latest >>--coverage<> + ) + stack build "${STACK_ARGS[@]}" + - run: + name: Check Cabal file up to date + command: git diff --exit-code *.cabal + - run: + name: Test + command: | + STACK_ARGS=( + --test + <<# parameters.latest >>--coverage<> + ) + stack build "${STACK_ARGS[@]}" + + haddock: + executor: ubuntu + steps: + - checkout + - install_stack + - install_stack_deps + - run: + name: Build haddock + command: stack haddock --no-haddock-deps + - run: + name: Bundle haddock docs + command: | + mkdir -p .ci/ + tar czf .ci/haddock-docs.tar.gz -C "$(find .stack-work/dist -regex '.*/doc/html/[^/]*')" . + - store_artifacts: + path: .ci/haddock-docs.tar.gz + +workflows: + version: 2 + + build_and_test: + jobs: + - lint + - haddock + - run_build_and_test: + name: test_latest + latest: true + - run_build_and_test: + name: test_ghc_8.10 + stack_yaml: stack-ghc-8.10.yaml + - run_build_and_test: + name: test_ghc_8.8 + stack_yaml: stack-ghc-8.8.yaml + - run_build_and_test: + name: test_ghc_8.6 + stack_yaml: stack-ghc-8.6.yaml + - run_build_and_test: + name: test_ghc_8.4 + stack_yaml: stack-ghc-8.4.yaml + - run_build_and_test: + name: test_ghc_8.2 + stack_yaml: stack-ghc-8.2.yaml diff --git a/.gitignore b/.gitignore index 62d3643..c3cc0d9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .DS_Store .stack-work/ + +.ci/ From 2b3967009ee2456805e0755220b0ab60f9920d79 Mon Sep 17 00:00:00 2001 From: Brandon Chinn Date: Mon, 23 Nov 2020 10:59:04 -0800 Subject: [PATCH 2/4] Add coverage --- .circleci/config.yml | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b0a9f7f..9f24757 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,8 @@ version: 2.1 +orbs: + codecov: codecov/codecov@1.0.2 + executors: ubuntu: parameters: @@ -51,14 +54,6 @@ commands: - ~/.stack - .stack-work - install_stack_deps: - steps: - - with_stack_cache: - install_deps: - - run: - name: Build external dependencies - command: stack build --test --only-dependencies - jobs: lint: executor: ubuntu @@ -99,7 +94,17 @@ jobs: steps: - checkout - install_stack - - install_stack_deps + - with_stack_cache: + install_deps: + - run: + name: Build external dependencies + command: stack build --test --only-dependencies + - when: + condition: << parameters.latest >> + steps: + - run: + name: Install hpc-lcov + command: stack install hpc-lcov - run: name: Build command: | @@ -120,13 +125,25 @@ jobs: <<# parameters.latest >>--coverage<> ) stack build "${STACK_ARGS[@]}" + - when: + condition: << parameters.latest >> + steps: + - run: + name: Run hpc-lcov + command: hpc-lcov + - codecov/upload: + file: lcov.info haddock: executor: ubuntu steps: - checkout - install_stack - - install_stack_deps + - with_stack_cache: + install_deps: + - run: + name: Build external dependencies + command: stack build --test --only-dependencies - run: name: Build haddock command: stack haddock --no-haddock-deps From 742d2cda2a2f9b890e603fdea56865b7a5f9e26a Mon Sep 17 00:00:00 2001 From: Brandon Chinn Date: Mon, 23 Nov 2020 11:34:09 -0800 Subject: [PATCH 3/4] Install lint binaries directly --- .circleci/config.yml | 28 +++++++++++++++++++++------- .pre-commit-config.yaml | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9f24757..1f81ef8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,15 +59,29 @@ jobs: executor: ubuntu steps: - checkout - - install_stack - - with_stack_cache: - install_deps: - - run: - name: Build linters - command: stack build hlint stylish-haskell + - run: + name: Install hlint + command: | + HLINT_ARCHIVE="hlint-${HLINT_VERSION}-x86_64-linux.tar.gz" + curl -sSLO "https://github.com/ndmitchell/hlint/releases/download/v${HLINT_VERSION}/${HLINT_ARCHIVE}" + mkdir -p ~/.local/bin/ + tar xzf "${HLINT_ARCHIVE}" -C ~/.local/bin/ --strip-components=1 "hlint-${HLINT_VERSION}/hlint" + environment: + HLINT_VERSION: 3.2.2 + - run: + name: Install stylish-haskell + command: | + STYLISH_ARCHIVE="stylish-haskell-v${STYLISH_VERSION}-linux-x86_64.tar.gz" + curl -sSLO "https://github.com/jaspervdj/stylish-haskell/releases/download/v${STYLISH_VERSION}/${STYLISH_ARCHIVE}" + mkdir -p ~/.local/bin/ + tar xzf "${STYLISH_ARCHIVE}" -C ~/.local/bin/ --strip-components=1 "stylish-haskell-v${STYLISH_VERSION}-linux-x86_64/stylish-haskell" + environment: + STYLISH_VERSION: 0.12.2.0 - run: name: Install Python - command: sudo apt-get install -y python + command: | + sudo apt-get update + sudo apt-get install -y python - run: name: Install pre-commit command: curl https://pre-commit.com/install-local.py | python - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a75225d..84e2dea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,9 +12,9 @@ repos: name: hlint language: system files: '\.hs$' - entry: stack exec -- hlint + entry: hlint - id: stylish-haskell name: stylish-haskell language: system files: '\.hs$' - entry: stack exec -- stylish-haskell -i + entry: stylish-haskell -i From ae0ae00bddc9dc38eaba6f88ec24d6cf1d03f984 Mon Sep 17 00:00:00 2001 From: Brandon Chinn Date: Mon, 23 Nov 2020 12:09:16 -0800 Subject: [PATCH 4/4] Fix lint --- src/Database/Persist/Monad.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Persist/Monad.hs b/src/Database/Persist/Monad.hs index 1a39119..3b80f33 100644 --- a/src/Database/Persist/Monad.hs +++ b/src/Database/Persist/Monad.hs @@ -34,7 +34,7 @@ import Control.Monad.Reader (ReaderT, ask, lift, local, runReaderT) import Data.Pool (Pool) import Data.Proxy (Proxy(..)) import Data.Text (Text) -import Data.Typeable ((:~:)(..), Typeable, eqT, typeRep) +import Data.Typeable (Typeable, eqT, typeRep, (:~:)(..)) import Database.Persist (Entity, Filter, Key, PersistRecordBackend, SelectOpt) import Database.Persist.Sql (Migration, SqlBackend, runSqlPool) import qualified Database.Persist.Sql as Persist