name: CI

on:
  push:
    branches: [main]
  pull_request:
  release:
    types: [published]

jobs:
  test:
    name: Run tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13"]
    env:
      UV_PYTHON: ${{ matrix.python-version }}
    steps:
      - uses: actions/checkout@v4
      - name: Install uv
        uses: astral-sh/setup-uv@v6
      - name: Install the project
        run: uv sync --locked --all-extras --dev
      - name: Run tests
        run: uv run pytest

  publish-pypi:
    name: Publish to PyPI
    if: github.event_name == 'release' && github.event.action == 'published'
    runs-on: ubuntu-latest
    environment:
      name: pypi
      url: https://pypi.org/p/dynapydantic
    permissions:
      id-token: write
    steps:
      - uses: actions/checkout@v4
      - name: Install uv
        uses: astral-sh/setup-uv@v6
      - name: Install the project
        run: uv sync --locked --all-extras --dev
      - name: Run tests
        run: uv run pytest tests
      - name: Build package
        run: uv build
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
