name: Publish to PyPI

on:
  push:
    tags: ["v*"]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  # v4.2.2

      - name: Install uv
        uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b  # v7.3.0

      - name: Set up Python
        run: uv python install 3.12

      - name: Install dependencies
        run: uv venv && uv pip install ".[dev,browser]"

      - name: Lint
        run: uv run ruff check wafer/ tests/

      - name: Test
        run: uv run pytest tests/ -x -q

  publish:
    needs: test
    runs-on: ubuntu-latest
    permissions:
      id-token: write  # trusted publishing (no API token needed)
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  # v4.2.2
        with:
          fetch-depth: 0
          fetch-tags: true

      - name: Install uv
        uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b  # v7.3.0

      - name: Set up Python
        run: uv python install 3.12

      - name: Build
        run: uv build

      - name: Publish
        uses: pypa/gh-action-pypi-publish@v1.13.0
