# Modeled on https://circleci.com/docs/2.0/language-haskell/
version: 2.1
jobs:
  build:
    docker:
      - image: "fpco/stack-build:lts"
    steps:
      - "checkout"
      - restore_cache:
          # Read about caching dependencies: https://circleci.com/docs/2.0/caching/
          name: "Restore Cached Dependencies"
          keys:
            - paymentserver-haskell-v1-{{ checksum "stack.yaml" }}-{{ checksum "PaymentServer.cabal" }}
            - paymentserver-haskell-v1-{{ checksum "stack.yaml" }}
      - run:
          name: "Resolve/Update Dependencies"
          command: "stack --no-terminal setup"
      - run:
          name: "Run tests"
          command: "stack --no-terminal test --coverage"
      - run:
          name: "Install executable"
          command: "stack --no-terminal install"
      - save_cache:
          name: "Cache Dependencies"
          key: cci-demo-haskell-v1-{{ checksum "stack.yaml" }}-{{ checksum "PaymentServer.cabal" }}
          paths:
            - "/root/.stack"
            - ".stack-work"
      - store_artifacts:
          # Upload executable
          path: "~/.local/bin/PaymentServer-exe"
          destination: "PaymentServer-exe"
