name: CI

on:
  push:
    branches: [ main ]
  pull_request:

jobs:
  build-test:
    name: Build and test (abi3)
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Build wheel with maturin (abi3-py311)
        uses: messense/maturin-action@v1
        with:
          command: build
          args: --release --out dist
      - name: Test wheel on CPython 3.11–3.14
        shell: bash
        run: |
          set -eux
          # Create a venv and run tests; abi3 wheel should work on >=3.11
          python -m venv .venv
          source .venv/bin/activate || source .venv/Scripts/activate
          pip -q install -U pip pytest
          pip -q install dist/*.whl
          pytest -q
          deactivate

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: "3.11" }
      - run: pip install ruff black
      - run: ruff check .
      - run: black --check .

  publish:
    if: startsWith(github.ref, 'refs/tags/v')
    needs: [build-test]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: messense/maturin-action@v1
        with:
          command: publish
          args: --skip-existing
          pypi-token: ${{ secrets.PYPI_API_TOKEN }}
