name: Build

on:
  push:
    branches-ignore:
      - master
  pull_request:
    branches:
      - "**"

jobs:
  build:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mariadb:10.3
        ports:
          - 3306
        env:
          MYSQL_ROOT_PASSWORD: testing
          MYSQL_DATABASE: karp
          MYSQL_PASSWORD: testing
          MYSQL_USER: karp
        options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10

    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.6, 3.7, 3.8]
        es-version: ["6.8.6"]
    steps:
      - uses: actions/checkout@v1
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          make install-dev
      - name: Download elasticsearch
        run: |
          wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${{ matrix.es-version }}.tar.gz
          tar -xzf elasticsearch-${{ matrix.es-version }}.tar.gz
      - name: Create .env file
        run: |
          echo "ELASTICSEARCH_ENABLED=True" >> .env
          echo "ES_HOME=`realpath elasticsearch-${{ matrix.es-version }}`" >> .env
          cat .env
      - name: Lint with flake8 for syntax errors
        run: make lint-syntax-errors
      - name: Lint with pylint
        run: make lint-no-fail
      # - name: Typecheck with pytype
      #   if: matrix.python-version != '3.8'
      #   run: make type-check
      - name: Test with pytest
        run: |
          echo "KARP5_DBPASS=${KARP5_DBPASS}"
          make test-w-coverage
          docker logs "${{ job.services.mysql.id }}"
        env:
          KARP5_DBPASS: karp:testing@127.0.0.1:${{ job.services.mysql.ports['3306'] }}
      # - name: Coveralls
      #   uses: coverallsapp/github-action@master
      #   with:
      #     github-token: ${{ secrets.github_token }}
