on:
  workflow_dispatch:
  push:
    tags:
      - "*.*.*"

name: release

permissions:
  contents: read

jobs:
  build:
    name: Build distributions for PyPI
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Set up Python
        uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0

      - name: Install build dependencies
        run: python -m pip install build

      - name: Build distributions
        run: python -m build

      - name: Upload distributions
        uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
        with:
          name: certifi-dists
          path: dist/

  pypi:
    name: Publish to PyPI
    runs-on: ubuntu-latest
    environment: release

    needs:
      - build

    permissions:
      # Used to authenticate to PyPI via OIDC.
      id-token: write

    steps:
      - name: fetch dists
        uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
        with:
          name: certifi-dists
          path: dist/

      - name: publish
        if: github.event_name == 'push'
        uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
        with:
          attestations: true
