name: Run Tests
on: push
jobs:
  python:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
    env:
      PYTHON_VERSION: ${{matrix.python-version}}
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{matrix.python-version}}
        uses: actions/setup-python@v5
        with:
          python-version: ${{matrix.python-version}}
          allow-prereleases: true
      - if: matrix.python-version == '3.13'  # For lxml...
        run: |
          sudo apt-get update
          sudo apt-get install --yes libxml2 libxslt-dev
      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install --yes ghostscript imagemagick
          sudo sed -i 's#<policy domain="coder" rights="none" pattern="PDF" />#<policy domain="coder" rights="read|write" pattern="PDF" />#' /etc/ImageMagick-6/policy.xml
          python -m pip install --upgrade pip
          python -m pip install .[test]

      - name: run
        run: make test-ref

      - name: Test with tox
        run: tox
        env:
          TOXENV: py${{matrix.python-version}}

      - name: Generate coverage report
        run: coverage xml

      - name: Upload test coverage
        uses: coverallsapp/github-action@v2
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
        with:
          github-token: ${{ github.token }}
          file: "coverage.xml"
          format: "cobertura"
