name: Build & Publish

on:
  pull_request:
    paths:
      - ".github/workflows/build-and-publish.yml"
      - "setup.*"

  workflow_dispatch:
    inputs:
      branch:
        description: "The branch, tag or SHA to release from"
        required: true
        default: "main"

jobs:
  os-built-distributions:
    name: Build on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.branch }}
          submodules: true
      - name: Install Python
        uses: actions/setup-python@v2
      - name: Install build dependencies
        run: python -m pip install --upgrade cibuildwheel
      - name: Build wheels
        run: python -m cibuildwheel
        env:
          CIBW_SKIP: "cp27-* cp35-* pp27-*" # skip 2.7 and 3.5 wheels
          CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
      - uses: actions/upload-artifact@v2
        with:
          name: python-package-distributions
          path: ./wheelhouse/*.whl

  source-distribution:
    name: Build source distribution
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.branch }}
          submodules: true
      - name: Install Python
        uses: actions/setup-python@v2
      - name: Build source distribution
        run: python setup.py sdist
      - name: Store the source distribution
        uses: actions/upload-artifact@v2
        with:
          name: python-package-distributions
          path: dist
          retention-days: 4

  publish:
    needs:
      - os-built-distributions
      - source-distribution
    runs-on: ubuntu-latest
    steps:
      - name: Download all the dists
        uses: actions/download-artifact@v2
        with:
          name: python-package-distributions
          path: dist/
      - name: What will we publish?
        run: ls -l dist
      - name: Publish
        if: github.event.inputs.branch != ''
        uses: pypa/gh-action-pypi-publish@master
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}
          skip_existing: true

Add GitHub workflow to handle new releases
Add GitHub workflow to handle new releases

Wheels will be created for GNU/Linux, macOS and Windows:
- PyPy 3.7
- CPython 3.6 - 3.9

- Fixes #19.
- Fixes #50.
- Fixes #51.
- Fixes #56.
- Fixes #57.
- Fixes #61.
- Fixes #62.
