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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Set up Python
        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
        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@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
        with:
          name: certifi-dists
          path: dist/

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