name: Packages CI

on:
  pull_request:
    paths:
      - "packages/codeflash-core/**"
      - "packages/codeflash-python/**"
      - "pyproject.toml"
      - "uv.lock"
  push:
    branches: [main]
    paths:
      - "packages/codeflash-core/**"
      - "packages/codeflash-python/**"
      - "pyproject.toml"
      - "uv.lock"

jobs:
  check:
    runs-on: ubuntu-latest
    concurrency:
      group: packages-ci-${{ github.head_ref || github.run_id }}
      cancel-in-progress: true
    permissions:
      contents: read

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0  # needed for version check against origin/main

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

      - name: Install uv
        uses: astral-sh/setup-uv@v6

      - name: Install dependencies
        run: uv sync --all-packages

      - name: Ruff check
        run: uv run ruff check packages/

      - name: Ruff format
        run: uv run ruff format --check packages/

      - name: Interrogate
        run: uv run interrogate packages/codeflash-core/src/ packages/codeflash-python/src/

      - name: Mypy
        run: uv run mypy packages/codeflash-core/src/ packages/codeflash-python/src/

      - name: Pytest
        run: uv run pytest packages/ -v
        env:
          CI: "true"

      - name: Check version bump
        if: github.event_name == 'pull_request'
        run: uv run python scripts/versioning.py check-version
