name: Publish to PyPI

on:
  release:
    types: [published]

permissions:
  contents: read

jobs:
  quality-gate:
    runs-on: blacksmith-4vcpu-ubuntu-2404
    strategy:
      matrix:
        python-version: ["3.11", "3.12"]
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: pip install -e ".[dev]"
      - name: Lint
        run: |
          ruff check src/ tests/
          ruff format --check src/ tests/
      - name: Type check
        run: mypy src/aipea/
      - name: Test
        run: pytest tests/ -v --cov=src/aipea --cov-report=term-missing --cov-fail-under=75

  publish:
    needs: quality-gate
    runs-on: blacksmith-4vcpu-ubuntu-2404
    environment: release
    permissions:
      id-token: write
      contents: read
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: "3.12"
      - name: Install build tools
        run: pip install hatch
      - name: Build package
        run: hatch build
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1
