name: Publish Python Release to PyPI

on:
  push:
    tags:
      - "v*"

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python
      uses: actions/setup-python@v3
      with:
        python-version: "3.10"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine
        make install-dev
    - name: Build and publish
      env:
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*
    - name: Update API docs
      run: make docs
    - name: Update CHANGELOG
      id: changelog
      uses: requarks/changelog-action@v1
      with:
        token: ${{ github.token }}
        tag: ${{ github.ref_name }}
    - name: Commit API docs, CHANGELOG.md
      uses: stefanzweifel/git-auto-commit-action@v4
      with:
        branch: main
        commit_message: 'docs: update API docs, CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
        file_pattern: 'docs CHANGELOG.md'
