language: python
env:
  global:
  - STREAMLINK_DIST_DIR=${TRAVIS_BUILD_DIR}/dist
  - STREAMLINK_INSTALLER_DIST_DIR=${STREAMLINK_DIST_DIR}/nsis
  - SDIST_KEY_FILE="${TRAVIS_BUILD_DIR}/signing.key"

git:
  depth: 300

matrix:
  include:
  - python: '2.7'
  - python: '3.4'
  - python: '3.5'
    env: BUILD_DOCS=yes BUILD_INSTALLER=yes BUILD_SDIST=yes DEPLOY_PYPI=yes
  - python: '3.6'
  - python: '3.7'
    dist: xenial
    sudo: true
  - python: '3.8-dev'
    dist: xenial
    sudo: true
  allow_failures:
  - python: '3.8-dev'

before_install:
  - pip install --disable-pip-version-check --upgrade pip setuptools
  - pip install -r dev-requirements.txt
  - pip install pycountry
  - if [[ $BUILD_DOCS == 'yes' ]]; then
      pip install -r docs-requirements.txt;
      pip install doctr;
    fi

install:
  - pip install -e .

script:
  - pytest --cov
  - if [[ $BUILD_DOCS == 'yes' ]]; then make --directory=docs html; fi
  - if [[ $BUILD_INSTALLER == 'yes' ]]; then ./script/makeinstaller.sh; fi

after_success:
  - set -e
  # latest version - push docs for master
  - if [[ $BUILD_DOCS == 'yes' && $TRAVIS_REPO_SLUG == 'streamlink/streamlink' ]]; then doctr deploy latest; fi
  # stable version - push docs for tags
  - if [[ $BUILD_DOCS == 'yes' && $TRAVIS_REPO_SLUG == 'streamlink/streamlink' && -n "$TRAVIS_TAG" ]]; then doctr deploy .; fi
  - codecov

addons:
  apt:
    packages:
    - nsis
    - imagemagick
    - inkscape

before_deploy:
  - ./script/bintrayconfig.sh

deploy:
  - provider: releases
    api_key: "${RELEASES_API_KEY}"
    file: "${STREAMLINK_INSTALLER_DIST_DIR}/streamlink-${TRAVIS_TAG}.exe"
    file_glob: true
    skip_cleanup: true
    on:
      tags: true
      condition: $BUILD_INSTALLER = yes
      repo: streamlink/streamlink
  - provider: script
    script: python script/github_releases.py
    skip_cleanup: true
    on:
      tags: true
      condition: $BUILD_INSTALLER == yes
      repo: streamlink/streamlink
  - provider: bintray
    file: build/bintray-nightly.json
    user: "${BINTRAY_USER}"
    key: "${BINTRAY_KEY}"
    skip_cleanup: true
    on:
      branch: master
      condition: $BUILD_INSTALLER == yes && $TRAVIS_EVENT_TYPE == cron
      repo: streamlink/streamlink
  - provider: script
    script: ./script/sdistsign.sh
    skip_cleanup: true
    on:
      tags: true
      condition: $BUILD_SDIST == yes
      repo: streamlink/streamlink
  - provider: releases
    api_key: "${RELEASES_API_KEY}"
    file: "${STREAMLINK_DIST_DIR}/streamlink-${TRAVIS_TAG}*"
    file_glob: true
    skip_cleanup: true
    on:
      tags: true
      condition: $BUILD_SDIST = yes
      repo: streamlink/streamlink

after_deploy:
  - if [[ "$BUILD_INSTALLER" == 'yes' && "$TRAVIS_EVENT_TYPE" == 'cron' ]]; then ./script/bintrayupdate.sh; fi

doctr:
  build-tags: True
  deploy-repo: streamlink/streamlink.github.io
  key-path: doctr_deploy_key.enc
  require-master: True
