language: python

# To automatically push to anaconda cloud tag a relase in the git repository
# git tag -a v0.2.3 -m 'Version with working conda installer'
# git push --tags


jobs:
  include:
    - name: "linux"
      os: linux
      language: python
      python: 3.7           # this works for Linux but is ignored on macOS or Windows
      before_install:
        # To make sure travis can read the GIT_DESCRIBE_TAG properly we need to force an unshallow fetch
        - git fetch --unshallow
        # Install the latest version of Miniconda
        - wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
        - chmod +x miniconda.sh
        - ./miniconda.sh -b
        - pwd
        - export PATH=/home/travis/miniconda3/bin:$PATH
        - conda update --yes conda  # Update CONDA without command line prompt     
      env:
        - CC=gcc-5
        - CXX=g++-5
    - name: "osx"
      os: osx
      language: sh
      before_cache:
        - brew cleanup
      cache:
        directories:
          - $HOME/Library/Caches/Homebrew
          - /usr/local/Homebrew
      addons:
        homebrew:
          packages: python3
      before_install:
        # To make sure travis can read the GIT_DESCRIBE_TAG properly we need to force an unshallow fetch
        - git fetch --unshallow
        # Install the latest version of Miniconda
        - wget http://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh
        - chmod +x miniconda.sh
        - ./miniconda.sh -b
        - pwd
        - export PATH=/Users/travis/miniconda3/bin:$PATH
        - conda update --yes conda  # Update CONDA without command line prompt 
      env:
        - CC=clang
        - CXX=clang++


install:
  # Create a new environment
  - conda create --yes --name test python=$TRAVIS_PYTHON_VERSION
  # Activate it
  - source activate test
  # Install various dependencies
  - conda install --yes numpy=1.17 pytest pip

install:
  - conda install --yes conda-build
  # You can add any CONDA channels you may need here. CONDA supports
  # both the commands add and append. The only difference is that 
  # the add command places the channel at the front of the priority 
  # list, while append does the opposite.
  - conda config --add channels pytorch
  - conda config --add channels conda-forge
  - conda config --add channels anaconda
  - conda config --add channels uncbiag

  # Build the conda recipe for this package
  - conda build . --python=$TRAVIS_PYTHON_VERSION --output-folder bld-dir
  # Add the built package as a channel with highest priority
  - conda config --add channels "file://`pwd`/bld-dir"

  # Create and activate the test environment
  - conda create --yes --name test-environment python=$TRAVIS_PYTHON_VERSION mermaid --file dev-requirements.txt
  - source activate test-environment


# command to install dependencies
#install:
#  - python setup.py install

# command to run tests
script: ./travis_test.sh

after_success:
  # Install the command line API for CONDA uploads
  - conda install --yes anaconda-client
  - |
    ## Only upload builds from tags
    if [[ $TRAVIS_PULL_REQUEST == false && $TRAVIS_REPO_SLUG == "uncbiag/mermaid" && $TRAVIS_BRANCH == $TRAVIS_TAG  && $TRAVIS_TAG != '' ]]; then
      export ANACONDA_API_TOKEN=$CONDA_UPLOAD_TOKEN
      anaconda upload --user uncbiag bld-dir/**/mermaid-*.tar.bz2
    fi
