name: Test against different Python version

on:
  push:
    branches: master
  pull_request:
jobs:

  python_tests:
    runs-on: ubuntu-latest

    strategy:
      # Do not fail if one the tests did not pass
      fail-fast: false

      matrix:
        # Python version(s) to use when running the tests
        python:
          - 3.6
          - 3.8
          - 3.9-dev

        # Docker images of MySQL-compliant databases to run the tests suite on
        database: "mysql:8.0.20"

    services:
        mysql:
            image: ${{ matrix.database }}
            env:
                MYSQL_ALLOW_EMPTY_PASSWORD: yes
                MYSQL_DATABASE: index_digest
            ports:
                - "3306:3306"
            options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python }}

    # https://github.com/actions/cache/blob/main/examples.md#using-pip-to-get-cache-location
    - name: Get pip cache dir
      id: pip-cache
      run: |
        echo "::set-output name=dir::$(pip cache dir)"

    - name: pip cache
      uses: actions/cache@v2
      with:
        path: ${{ steps.pip-cache.outputs.dir }}
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/setup.py') }}
        restore-keys: |
          ${{ runner.os }}-pip-

    - name: Install dependencies
      run: make install

    - name: Linter
      run: make lint

    - name: Set up the database
      run: |
        docker ps
        mysql --protocol=tcp -u root -v < setup.sql
        # import the test schema files
        "./sql/populate.sh"
        mysql --protocol=tcp -uindex_digest -pqwerty index_digest -v -e '\s; SHOW TABLES; SHOW DATABASES;'

    - name: Tests
      run: make test

Test against different Python version (a separate workflow)
Test against different Python version (a separate workflow)
