From 5deb32b2c07c2e82f2289cae51e3ac6c763756cd Mon Sep 17 00:00:00 2001 From: joneshf Date: Sun, 29 Jul 2018 12:19:06 -0700 Subject: [PATCH] Separate the compile stage from testing Might be overkill for this small of a workflow. Good to get practice with circleci and Make. --- .circleci/config.yml | 44 +++++++++++++++++++++++++++++++------------- Makefile | 31 +++++++++++++++++++------------ 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cfc1c3f..aa2817e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,30 @@ version: 2 jobs: + compile: + docker: + - image: haskell:8.2.2 + steps: + - checkout + - restore_cache: + keys: + - v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }} + - v1-stack-{{ checksum "package.yaml" }}- + - v1-stack- + name: Restoring stack cache + - run: + name: Compile + command: make build + - presist_to_workspace: + root: dist + paths: + - '*' + - save_cache: + key: v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }} + name: Caching stack + paths: + - .stack-work + - /root/.stack + sdist: docker: - image: haskell:8.2.2 @@ -20,25 +45,18 @@ jobs: - image: haskell:8.2.2 steps: - checkout - - restore_cache: - keys: - - v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }} - - v1-stack-{{ checksum "package.yaml" }}- - - v1-stack- - name: Restoring stack cache + - attach_workspace: + at: dist - run: name: Test command: make test - - save_cache: - key: v1-stack-{{ checksum "package.yaml" }}-{{ checksum "stack.yaml" }} - name: Caching stack - paths: - - .stack-work - - /root/.stack workflows: version: 2 base: jobs: + - compile - sdist - - test + - test: + requires: + - compile diff --git a/Makefile b/Makefile index 79dc7fb..e8eb0b4 100644 --- a/Makefile +++ b/Makefile @@ -8,14 +8,31 @@ STACK_WORK ?= .stack-work VERBOSITY ?= warn CABAL_FILE := $(PROJECT_NAME).cabal +DOC_TEST := $(DIST)/build/doc-test/doc-test GHCID := $(BIN)/ghcid STACK_FLAGS := --verbosity $(VERBOSITY) -.DEFAULT_GOAL := build +.DEFAULT_GOAL := $(EMPTY)/build $(BIN) $(DIST) $(EMPTY): mkdir -p $@ +$(CABAL_FILE): package.yaml + # `stack` has no way to run `hpack` directly. + # We can run `hpack` indirectly with little overhead. + $(STACK) $(STACK_FLAGS) build --dry-run + +$(DOC_TEST): $(EMPTY)/build golden/**/*.json + $@ + +$(EMPTY)/build: $(EMPTY)/stack-setup README.md Setup.hs package.yaml stack.yaml src/**/*.hs test/**/*.hs | $(DIST) + $(STACK) $(STACK_FLAGS) build --no-run-tests --test + cp -R $$($(STACK) $(STACK_FLAGS) path --dist-dir)/build $(DIST)/build + touch $@ + +$(EMPTY)/doc-test: $(EMPTY)/build + touch $@ + $(EMPTY)/stack-setup: | $(EMPTY) $(STACK) $(STACK_FLAGS) setup touch $@ @@ -23,15 +40,6 @@ $(EMPTY)/stack-setup: | $(EMPTY) $(GHCID): $(EMPTY)/stack-setup | $(BIN) $(STACK) $(STACK_FLAGS) install ghcid --local-bin-path $(BIN) -$(CABAL_FILE): package.yaml - # `stack` has no way to run `hpack` directly. - # We can run `hpack` indirectly with little overhead. - $(STACK) $(STACK_FLAGS) build --dry-run - -.PHONY: build -build: $(EMPTY)/stack-setup - $(STACK) $(STACK_FLAGS) build --no-run-tests --test - .PHONY: cabal-check cabal-check: $(CABAL_FILE) $(CABAL) check @@ -49,8 +57,7 @@ sdist: cabal-check | $(DIST) $(CABAL) sdist .PHONY: test -test: build - $(STACK) $(STACK_FLAGS) test +test: $(DOC_TEST) .PHONY: upload-hackage upload-hackage: sdist