language: python
cache: pip
dist: trusty

# Use container-based infrastructure
sudo: false

# Install JDK9 for Elasticsearch 5
addons:
  apt:
    packages:
     - oracle-java9-installer
     - oracle-java9-set-default

matrix:
  include:
   - env: TOXENV=py34-dj111-postgres-noelasticsearch
     python: 3.4
   - env: TOXENV=py34-dj111-sqlite-noelasticsearch
     python: 3.4
   - env: TOXENV=py34-dj20-mysql-noelasticsearch
     python: 3.4
   - env: TOXENV=py35-dj111-postgres-noelasticsearch
     python: 3.5
   - env: TOXENV=py35-dj111-mysql-noelasticsearch
     python: 3.5
   - env: TOXENV=py35-dj111-postgres-elasticsearch2 INSTALL_ELASTICSEARCH2=yes
     python: 3.5
     sudo: true
   - env: TOXENV=py35-dj20-sqlite-noelasticsearch
     python: 3.5
   - env: TOXENV=py36-dj111-sqlite-noelasticsearch
     python: 3.6
   - env: TOXENV=py36-dj111-postgres-noelasticsearch
     python: 3.6
   - env: TOXENV=py36-dj111-mysql-noelasticsearch
     python: 3.6
   - env: TOXENV=py36-dj20-postgres-noelasticsearch
     python: 3.6
   - env: TOXENV=py36-dj111-postgres-elasticsearch2 INSTALL_ELASTICSEARCH2=yes
     python: 3.6
     sudo: true
   - env: TOXENV=py36-dj20-sqlite-elasticsearch2 INSTALL_ELASTICSEARCH2=yes
     python: 3.6
     sudo: true
   - env: TOXENV=py36-dj111-postgres-elasticsearch5 INSTALL_ELASTICSEARCH5=yes
     python: 3.6
     sudo: true
   - env: TOXENV=py36-dj20-postgres-elasticsearch5 INSTALL_ELASTICSEARCH5=yes
     python: 3.6
     sudo: true
   - env: TOXENV=py36-dj111-postgres-elasticsearch6 INSTALL_ELASTICSEARCH6=yes
     python: 3.6
     sudo: true
   - env: TOXENV=py36-dj20-postgres-elasticsearch6 INSTALL_ELASTICSEARCH6=yes
     python: 3.6
     sudo: true
  allow_failures:
    # Ignore failures on Elasticsearch tests because ES on Travis is intermittently flaky
    - env: TOXENV=py35-dj111-postgres-elasticsearch2 INSTALL_ELASTICSEARCH2=yes
    - env: TOXENV=py36-dj111-postgres-elasticsearch2 INSTALL_ELASTICSEARCH2=yes
    - env: TOXENV=py36-dj20-sqlite-elasticsearch2 INSTALL_ELASTICSEARCH2=yes
    - env: TOXENV=py36-dj111-postgres-elasticsearch5 INSTALL_ELASTICSEARCH5=yes
    - env: TOXENV=py36-dj20-postgres-elasticsearch5 INSTALL_ELASTICSEARCH5=yes
    - env: TOXENV=py36-dj111-postgres-elasticsearch6 INSTALL_ELASTICSEARCH6=yes
    - env: TOXENV=py36-dj20-postgres-elasticsearch6 INSTALL_ELASTICSEARCH6=yes

# Services
services:
  - elasticsearch

# Package installation
install:
  - pip install tox codecov
  - 'if [[ -n "$INSTALL_ELASTICSEARCH2" ]]; then ./scripts/travis/install_elasticsearch2.sh; fi'
  - 'if [[ -n "$INSTALL_ELASTICSEARCH5" ]]; then ./scripts/travis/install_elasticsearch5.sh; fi'
  - 'if [[ -n "$INSTALL_ELASTICSEARCH6" ]]; then ./scripts/travis/install_elasticsearch6.sh; fi'

# Pre-test configuration
before_script:
  - psql -c 'create database wagtaildemo;' -U postgres
  - mysql -e "SET GLOBAL wait_timeout = 36000;"
  - mysql -e "SET GLOBAL max_allowed_packet = 134209536;"

# Run the tests
script:
  tox

after_success:
  - codecov -F backend

# Who to notify about build results
notifications:
  slack:
    secure: Y/UERaVnR+RL2dOqLR0Nc60JdGkejQ1Ae5zvPRYdDiMIGSv/1KC3T5Dp8NxamqIlozbQNmRaZD+i4AdX60g1M3xlB9DMINzY584YK0X2T2S28+xIgE0MQJijbpfbk2veV8PMeA6EHNpG4zoT+4sbcSyljt9TPcYTTTiTB8rAtc0=

# bump Travis: 1
