version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.6-stretch
    working_directory: /home/circleci/fwdpp
    steps:
      - checkout
      - run: sudo chown -R circleci:circleci *
      - restore_cache:
          key: fwdpp-{{ .Branch }}
      - run:
          name: Checkout submodules
          command: |
            git submodule update --init --recursive 
            # Write out the status for debugging purposes. Are we checked out at tags?
            git submodule status --recursive
      - run:
          name: Install dependencies and set path
          command: |
            sudo apt-get update
            sudo apt-get install libgsl0-dev libboost-*dev lcov
            # way to set path persistently https://circleci.com/docs/2.0/env-vars/#setting-path
            echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV
      - save_cache:
          key: fwdpp-{{ .Branch }}
          paths:
            - "/home/circleci/.local"

      - run:
          name: Compile package
          command: |
              autoreconf --install
              ./configure
              make -j 2

      - run:
          name: Run test suite
          command: |
              make check -j 2

      - run:
          name: Code coverage
          command: |
              make -C testsuite coverage-local

      - run:
          name: Build from make dist and run tests
          command: |
              make dist
              tar xzf fwdpp-0.10.0.tar.gz
              cd fwdpp-0.10.0
              ./configure
              make -j 2
              make check

      - run:
          name: Run example programs
          command: |
              ./examples/wfts_integration_test --N 500 --theta 100 --rho 100 --seed 101 --mu 1e-3 --mean -1  --gc 100  --ansam 10 --sampling_interval 666 --matrix_test
