name: Publish

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

permissions:
  contents: read

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    environment:
      name: pypi
      url: https://pypi.org/project/getmail6
    permissions:
      id-token: write
    steps:
      - name: Install links
        run: sudo apt-get install -y links

      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Python 3.13
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"

      - name: Make sure tag matches version
        run: "[[ $(git describe --tags --exact-match) = v$(python -c 'import getmailcore ; print(getmailcore.__version__)') ]]"

      - name: Build project
        run: make dist

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