# <https://travis-ci.org/jakubroztocil/httpie>
sudo: false
language: python
os:
  - linux
env:
  global:
    - NEWEST_PYTHON=3.7
python:
  - 3.6
  # - 3.7  # is done in the matrix below as described in travis-ci/travis-ci#9069
  # pypy3 currently fails because of a Flask issue
  # - pypy3

cache: pip
matrix:
  include:

    # Manually defined macOS build
    # <https://docs.travis-ci.com/user/multi-os/#Python-example-(unsupported-languages)>
    - os: osx
      language: generic
      env:
        # Latest Python 3.x from Homebrew
        - TOXENV=py37  # <= needs to be kept up-to-date to reflect latest minor version
        - BREW_PYTHON_PACKAGE=python@3


    # Travis Python 3.7 must run sudo on
    - os: linux
      python: 3.7
      env: TOXENV=py37
      sudo: true    # Required for Python 3.7
      dist: xenial  # Required for Python 3.7


    # Add a codestyle-only build
    - os: linux
      python: 3.6
      env: CODESTYLE_ONLY=true


install:
    - |
      if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
          if [[ -n "$BREW_PYTHON_PACKAGE" ]]; then
              export HOMEBREW_NO_INSTALL_CLEANUP=1
              brew update
              if ! brew list --versions "$BREW_PYTHON_PACKAGE" >/dev/null; then
                  brew install "$BREW_PYTHON_PACKAGE"
              elif ! brew outdated "$BREW_PYTHON_PACKAGE"; then
                  brew upgrade "$BREW_PYTHON_PACKAGE"
              fi
          fi
          pip3 install tox
      fi
script:
    - |
      if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
          if [[ $CODESTYLE_ONLY ]]; then
              make pycodestyle
          else
              make test
          fi
      else
          PATH="/usr/local/bin:$PATH" tox -e "$TOXENV"
      fi
after_success:
    - |
      if [[ $TRAVIS_PYTHON_VERSION == $NEWEST_PYTHON && $TRAVIS_OS_NAME == 'linux' ]]; then
          make coveralls
      fi
notifications:
  webhooks:
    # options: [always|never|change] default: always
    on_success: always
    on_failure: always
    on_start: always
    urls:
      # https://gitter.im/jkbrzt/httpie
      - https://webhooks.gitter.im/e/c42fcd359a110d02830b
