name: Core Tests.

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: 'recursive'

      - name: Set up Python 3.10
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install dependencies
        run: |
          clang_format_version=$(python - <<'PY'
          from pathlib import Path

          for raw_line in Path("config.yaml").read_text().splitlines():
              line = raw_line.strip()
              if line.startswith("CLANG_FORMAT_VERSION:"):
                  print(line.split(":", 1)[1].strip().strip("\"'"))
                  break
          else:
              raise SystemExit("CLANG_FORMAT_VERSION is not set in config.yaml")
          PY
          )
          pip install black[jupyter]==22.3.0 "clang-format==${clang_format_version}" pytest pytest-check
          pip install torch==2.8.0 --index-url https://download.pytorch.org/whl/cpu
          # tests/test_dataset_endonerf.py and tests/test_dynamic_surgical_trainer.py
          # import PIL + tqdm; install the [examples] extra so the test
          # collection doesn't ImportError on a fresh build. The tests also
          # have `pytest.importorskip` guards as a belt-and-braces.
          BUILD_NO_CUDA=1 pip install .[examples]
      - name: Code Formatting Check
        run: lint/format-code.sh --check --full
      - name: Run Tests.
        run: pytest tests/
