name: tests

on: [push, pull_request]

jobs:
  test:
    name: Run tests
    runs-on: ubuntu-20.04

    strategy:
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]

    steps:
      - uses: actions/checkout@v2

      - name: Use Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install system dependencies
        run: sudo apt-get update && sudo apt-get install --no-install-recommends dvisvgm dvipng imagemagick inkscape pdf2svg poppler-utils texlive-binaries texlive-latex-base texlive-latex-extra texlive-extra-utils texlive-xetex

      - name: Install python dependencies
        run: |
          pip install mypy
          pip install -r requirements.txt
          pip install -r requirements_tests.txt
          pip install .

      - name: Run tests
        run: pytest -v --cov=plasTeX

      - name: Run mypy
        run: mypy --install-types --non-interactive plasTeX unittests

      - name: Upload Coveralls
        run: coveralls --service=github
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          COVERALLS_FLAG_NAME: ${{ matrix.python-version }}
          COVERALLS_PARALLEL: true

  finish:
    name: Finish Coveralls
    needs: test
    runs-on: ubuntu-latest
    container: python:3-slim

    steps:
      - name: Finish Coveralls
        run: |
          pip3 install coveralls
          coveralls --finish
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
