name: Publish to PyPI

on:
  release:
    types: [published]

permissions:
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest

    environment: release
    permissions:
      id-token: write

    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
          cache: "pip"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install hatch

      - name: Lint/Format
        run: hatch fmt

      - name: Mypy
        run: hatch run types:check

      - name: Build package
        run: hatch build

      - name: Test package
        run: hatch test --cover

      - name: Publish package distributions to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
