version: 2

variables:
  update_conda: &update_conda
    run:
      name: Update conda
      command: conda update --yes conda
  export_shortcuts: &export_shortcuts
    run:
      name: Export shortcuts 
      command: |
        # for no good reason the wrong version of pytest is choosen by default...
        echo 'export PYTEST=$(conda info --base)/envs/bpnet/bin/pytest' >> $BASH_ENV
        echo 'export HDF5_USE_FILE_LOCKING=FALSE' >> $BASH_ENV
  install_bpnet_env: &install_bpnet_env
    run:
      name: Install bpnet enviroment
      command: |
        conda env create -f conda-env.yml
  run_tests: &run_tests
    run:
      name: Run tests
      command: |
        source activate bpnet
        mkdir test-reports
        $PYTEST --cov=bpnet/ tests/ --disable-warnings --no-cov-on-fail --junitxml=test-reports/junit.xml
      no_output_timeout: 15m
  run_coveralls: &run_coveralls
    run:
      name: run coveralls
      command: |
        source activate bpnet
        coveralls || true
  store_test_results: &store_test_results
    store_test_results:
      path: test-reports
  store_test_artifacts: &store_test_artifacts
    store_artifacts:
      path: test-reports
      destination: test-reports


jobs:
  test-py36:
    docker:
      - image: continuumio/anaconda3:5.0.1
    working_directory: ~/repo
    steps:
      - checkout
      - *update_conda
      - *install_bpnet_env
      - *export_shortcuts
      - *run_tests
      # - *run_coveralls
      - *store_test_results
      - *store_test_artifacts

  build-deploy-docs:
    docker:
      - image: continuumio/anaconda3:5.0.1
    working_directory: ~/repo
    steps:
      # - add_ssh_keys:
      #     fingerprints:
      #       - e3:44:16:ec:72:df:ae:59:82:c2:ee:57:4a:52:71:aa
      - checkout
      - run:
          name: Install pip bpnet
          command: pip install -e .
      - run:
          name: Install build deps
          # use custom pydoc-markdown
          command: pip install nbconvert mkdocs git+https://github.com/kipoi/pydoc-markdown@master
      - run:
          name: Build docs
          command: |
            cd docs/
            mkdir -p theme_dir/img/ipynb/
            ./render_ipynb.bash
            pydocmd build
      - run:
          name: Deploy docs
          command: .circleci/deploy_docs.bash

workflows:
  version: 2

  test:
    jobs:
      - test-py36
      # - build-deploy-docs:
      #     requires:
      #       - test-py36
      #     filters:
      #       branches:
      #         only:
      #           - master
      #           - test_deployment_script
