cache: pip
dist: xenial
os: linux

services:
  - mysql
  - postgresql

language: python
python: '3.8'


jobs:
  allow_failures:
    - env: TOXENV=mypy
  include:
    # lint stage
    - stage: lint
      name: "Check MANIFEST.in"
      env: TOXENV=manifest
    - name: "Check code quality with Flake8"
      env: TOXENV=flake8
    - name: "Check package metadata with Pyroma"
      env: TOXENV=pyroma
    - name: "Check static typing with MyPy"
      env: TOXENV=mypy

    # docs stage
    - stage: docs
      name: "Check RST conformity with doc8"
      env: TOXENV=doc8
    - name: "Check README.rst"
      env: TOXENV=readme
    - name: "Check documentation build with Sphinx"
      env: TOXENV=docs

    # test stage
    - stage: test
      name: "Tests with MySQL"
      env: TOXENV=py DB=mysql PYBEL_TEST_CONNECTOR=mysqlclient PYBEL_TEST_CONNECTION=mysql+mysqldb://travis@localhost/test?charset=utf8
    - name: "Tests with PostgreSQL"
      env: TOXENV=py DB=postgresql PYBEL_TEST_CONNECTOR=psycopg2-binary PYBEL_TEST_CONNECTION=postgresql+psycopg2://travis@localhost/tests
    - name: "Tests with SQLite"
      env: TOXENV=py DB=sqlite
    - name: "Tests with legacy Python (3.5)"
      python: 3.5
      env: TOXENV=py DB=sqlite

install:
  - sh -c 'if [ "$TOXENV" = "py" ]; then pip install tox codecov; else pip install tox; fi'

before_script:
  - sh -c "if [ '$DB' = 'postgresql' ]; then psql -c 'DROP DATABASE IF EXISTS tests;' -U postgres; fi"
  - sh -c "if [ '$DB' = 'postgresql' ]; then psql -c 'DROP DATABASE IF EXISTS tests_tmp;' -U postgres; fi"
  - sh -c "if [ '$DB' = 'postgresql' ]; then psql -c 'CREATE DATABASE tests;' -U postgres; fi"
  - sh -c "if [ '$DB' = 'postgresql' ]; then psql -c 'CREATE DATABASE tests_tmp;' -U postgres; fi"
  - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'DROP DATABASE IF EXISTS test;'; fi"
  - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE test CHARACTER SET utf8 COLLATE utf8_general_ci;'; fi"
  - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e \"GRANT ALL PRIVILEGES ON test.* to 'travis'@'%' WITH GRANT OPTION;\"; fi"

script:
  - tox

after_success:
  - sh -c 'if [ "$TOXENV" = "py" ]; then tox -e coverage-report; codecov; fi'

notifications:
  slack: pybel:n2KbWKBum3musnBg3L76gGwq
