name: Build and Publish

on:
  push:
    tags:
    - v*

jobs:
  build:
    name: Build wheels
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

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

    - name: Build
      run: python -m hatch build

    - uses: actions/upload-artifact@v3
      with:
        name: artifacts
        path: dist/*
        if-no-files-found: error

  publish:
    name: Publish release
    needs:
    - build

    runs-on: ubuntu-latest

    steps:
    - uses: actions/download-artifact@v3
      with:
        name: artifacts
        path: dist

    - name: Push build artifacts to PyPI
      uses: pypa/gh-action-pypi-publish@v1.6.4
      with:
        skip_existing: true
        user: __token__
        password: ${{ secrets.PYPI_API_TOKEN }}

    - name: Publish Github Release
      uses: softprops/action-gh-release@v1
      with:
        files: dist/*
