name: Upload Python Package to PyPI when a Release is published

on:
  release:
    types: [published]

permissions:
  contents: write
  pull-requests: write

jobs:
  build-and-publish:
    name: Build and release to PyPI
    runs-on: ubuntu-latest
    environment:
      name: pypi
      url: https://pypi.org/p/actron-neo-api
    permissions:
      id-token: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.x"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools setuptools-scm wheel
      - name: Build package
        run: |
          python setup.py sdist bdist_wheel
      - name: Publish package distributions to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
