name: Release

on:
  release:
    types:
      - published

permissions: {}

jobs:
  build:
    runs-on: ubuntu-latest
    name: Build package
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4.1.7

      - name: Set up Python 3.x
        uses: actions/setup-python@v5
        with:
          python-version: 3.x

      - name: Install poetry
        run:  make install-poetry

      - name: Set version number
        run: |
          poetry version "${{ github.event.release.tag_name }}"

      - name: Build
        run: poetry build --no-interaction

      - name: Upload dists
        uses: actions/upload-artifact@v4.3.3
        with:
          name: "dist"
          path: "dist/"
          if-no-files-found: error
          retention-days: 5

  publish:
    name: Publish release to PyPI
    runs-on: ubuntu-latest
    needs: "build"
    environment:
      name: release
      url: https://pypi.org/project/awesomeversion
    permissions:
      id-token: write
    steps:
    - name: Download dists
      uses: actions/download-artifact@v4.1.7
      with:
        name: "dist"
        path: "dist/"

    - name: Publish dists to PyPI
      uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0 # v1.9.0