name: Test

on:
  workflow_dispatch:
  workflow_call:

permissions:
  contents: read

jobs:
  tests:
    name: Python tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'
          cache: pip
      - name: Install dependencies
        run: |
          pip install pip-tools
          pip-sync requirements.txt requirements-dev.txt
      - name: Setup pre-commit cache
        uses: actions/cache@v4
        with:
          path: ~/.cache/pre-commit
          key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
      - name: Check pre-commit
        run: pre-commit run --show-diff-on-failure --color=always --all-files
      - name: Test
        run: pytest --cov=. --cov-branch --cov-report term-missing:skip-covered
        working-directory: ./src/
