version: 2.1

executors:
  aebuilder:
    docker:
      - image: aeternity/builder
        user: builder
    working_directory: ~/aesophia

jobs:
  verify_rebar_lock:
    executor: aebuilder
    steps:
      - checkout
      - run:
          name: Ensure lock file is up-to-date
          command: |
            ./rebar3 upgrade
            git diff --quiet -- rebar.lock || (echo "rebar.lock is not up-to-date" && exit 1)
  build:
    executor: aebuilder
    steps:
      - checkout
      - restore_cache:
          keys:
            - dialyzer-cache-v2-{{ .Branch }}-{{ .Revision }}
            - dialyzer-cache-v2-{{ .Branch }}-
            - dialyzer-cache-v2-
      - run:
          name: Build
          command: ./rebar3 compile
      - run:
          name: Static Analysis
          command: ./rebar3 dialyzer
      - run:
          name: Eunit
          command: ./rebar3 eunit
      - run:
          name: Common Tests
          command: ./rebar3 ct
      - save_cache:
          key: dialyzer-cache-v2-{{ .Branch }}-{{ .Revision }}
          paths:
            - _build/default/rebar3_20.3.8_plt
      - store_artifacts:
          path: _build/test/logs

workflows:
  version: 2
  build_test:
    jobs:
      - build
      - verify_rebar_lock
