name: CI

on:
  pull_request:
  push:
    branches: [main]

concurrency:
  group: ci-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  prek:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v6
      - uses: astral-sh/setup-uv@v8.0.0
        with:
          python-version: "3.12"
          enable-cache: true
      - run: uv sync --all-packages
      - uses: j178/prek-action@v2

  test:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v6
      - uses: astral-sh/setup-uv@v8.0.0
        with:
          python-version: "3.12"
          enable-cache: true
      - run: uv sync --all-packages
      - name: Test
        run: uv run pytest packages/ -v
        env:
          CI: "true"

  version:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - uses: astral-sh/setup-uv@v8.0.0
        with:
          python-version: "3.12"
          enable-cache: true
      - run: uv sync --all-packages
      - name: Check version bump
        run: uv run python scripts/versioning.py check-version
