language: python
sudo: false
python:
  - '2.7'
  - '3.4'
  - '3.5'
  - '3.6'

cache:
  directories:
  - $HOME/.cache/pip
  - .tox
before_cache:
  - rm -f $HOME/.cache/pip/log/debug.log
  - rm -fr .tox/log/ .tox/*/log/ .tox/*/tmp/ .tox/dist .tox/*/lib/*/site-packages/drf_yasg*

jobs:
  include:
    - # workaround for python 3.7 on travis https://github.com/travis-ci/travis-ci/issues/9815#issuecomment-401756442
      stage: test
      python: '3.7'
      dist: xenial
      sudo: required
    -
      python: '3.6'
      env: TOXENV=djmaster
    - # readthedocs uses python 3.5 for building
      python: '3.5'
      env: TOXENV=docs
    -
      python: '2.7'
      env: TOXENV=lint

    - stage: publish
      python: '3.6'
      script: skip
      env: PYPI_DEPLOY=true
      deploy: &pypi
        provider: pypi
        user: cvijdea
        password:
          secure: 54DvknusZ7uHlo9IJxgbNDVKYrwaScyuOZyAGZPb/PTUj8WroQZtp1bFOrAtzfcM4ctIIoLWVzmSwrxypmU4hNif2ZvJ8Vo2PnVh9G6wQ2fD2FN+kFBYczBNrzW5xhjJ53OiTYy/zzHgzxC/sp+hB4sibWl0v69PGU5v6oyBltOWZLXYpqMA6fINt62XDVwuNHVKAo1T/yoeJMQKeCKYAx8QOtve9/qcl5Td/OOM6z42hX5+q3N7RgkCFLl0KopwaPwBaL1Z3Bn+aUhiIUdrRrdigY329QtNXoa/VRBNvUSAwbvecShmgl3c9HigL2ZWmtmHaXda6YCdqmbVfSHSEDsn4AwhZ3A9WblbRtuBwP79YKiE+4BLmgLlGGA4IrAKr3woe+078q/bGqBzmeDd+jt72hhibzD5B96zo4tSNksSxSJGwMYH988fBN/ppynrzRvO0sR/THwpb0r42era8tRd3ZVBefloVas/nQZZs4+zMYoO0fbaLDXdkfaxsF5/X6WkwTYjbI3tdapUT6lYXwi1eKUM1ZGsfKpuq0lFa3qxevYBKveWStQwGyJz1KhVUHbo3OrA3U6q9yoqpzhcZBhzGAPSgumi+EkBUj69cymlYkmqXVBn4VnWsdeFefNYE6Kvh/HJEDPDaWSNgfVLN9xWVqJqM7QiWA351W9dRZA=
        on:
          tags: true
        distributions: "sdist bdist_wheel"

  allow_failures:
    - env: TOXENV=lint
    - env: TOXENV=djmaster

  fast_finish: true

install:
 - pip install -r requirements/ci.txt

before_script:
 - coverage erase

script:
 - tox

after_success:
  - |
    if [[ -z "$TOXENV" && -z "$PYPI_DEPLOY" ]]; then
      chmod +x coverage.sh
      ./coverage.sh
    fi

branches:
  only:
    - master
    - /^release\/.*$/
    - /^v?\d+\.\d+(\.\d+)?(-?\S+)?$/

stages:
  - test
  - name: publish
    if: tag IS present


notifications:
  email:
    on_success: always
    on_failure: always
