name: Build and Publish Package

on:
  push:
    tags: ["v*"]

jobs:
  build-n-publish:
    name: Build and publish package to PyPI and TestPyPI
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - run: |
        git fetch --prune --unshallow --tags
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install pep517
      run: >-
        python -m
        pip install
        pep517
        --user
    - name: Build a binary wheel and a source tarball
      run: >-
        python -m
        pep517.build
        --source
        --binary
        --out-dir dist/
        .
    - name: Publish distribution 📦 to Test PyPI
      uses: pypa/gh-action-pypi-publish@master
      with:
        user: __token__
        password: ${{ secrets.TEST_PYPI_TOKEN }}
        repository_url: https://test.pypi.org/legacy/
    - name: Publish distribution 📦 to PyPI
      uses: pypa/gh-action-pypi-publish@master
      with:
        user: __token__
        password: ${{ secrets.PYPI_TOKEN }}
