name: Backend CI

on:
    push:
        paths:
            - "backend/**"
            - "scripts/**"
            - "pyproject.toml"
            - "TODO.md"
            - ".github/workflows/backend-ci.yml"
    pull_request:
        paths:
            - "backend/**"
            - "scripts/**"
            - "pyproject.toml"
            - "TODO.md"

jobs:
    lint-and-test:
        runs-on: ubuntu-latest

        steps:
            - name: Check out repository
              uses: actions/checkout@v4

            - name: Set up Python
              uses: actions/setup-python@v5
              with:
                  python-version: "3.10"

            - name: Install dependencies
              run: |
                  python -m pip install --upgrade pip
                  python -m venv .venv
                  source .venv/bin/activate
                  pip install -e .[dev]

            - name: Run formatters (check mode)
              run: |
                  source .venv/bin/activate
                  python -m black --check backend
                  python -m isort --check-only backend

            - name: Run backend tests
              run: |
                  source .venv/bin/activate
                  pytest
