name: Publish Package to PyPi

on:
  release:
    types: [released, prereleased]

jobs:
  deploy:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install build
    - name: Build
      run: |
        python -m build
    - name: Publish to PyPI Staging
      if: "github.event.release.prerelease"
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        user: '__token__'
        password: ${{ secrets.TEST_PYPI_TOKEN }}
        repository_url: https://test.pypi.org/legacy/
    - name: Publish to PyPI
      if: "!github.event.release.prerelease"
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        user: '__token__'
        password: ${{ secrets.PYPI_TOKEN }}
