name: Build
on:
  push:
    branches-ignore:
      - data
      - gh-pages
    tags:
      - '**'
  pull_request:
    branches-ignore:
      - data
      - gh-pages

jobs:

  # Build job. Builds source distribution (sdist) and binary wheels distribution (bdist_wheel)
  build:
    name: Build ${{ matrix.dist }} [${{ matrix.python-version }} | ${{ matrix.os }} ${{ matrix.architecture }}]
    strategy:
      fail-fast: false
      matrix:
        # os: [ubuntu-latest, macos-latest, windows-latest] # Build wheels on different systems
        # python-version: [3.6, 3.7]
        # architecture: [x64]
        # dist: [bdist_wheel]
        include:
          - os: ubuntu-latest # Modify one element to build source distribution
            python-version: 3.7
            architecture: x64
            dist: sdist bdist_wheel
    runs-on: ${{ matrix.os }}
    env:
      PYTHONUNBUFFERED: 1

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
        architecture: ${{ matrix.architecture }}

    - name: Build
      run: |
        python -m pip install --upgrade pip
        python -m pip install --upgrade setuptools wheel
        python setup.py ${{ matrix.dist }}

    - name: Upload artifacts
      uses: actions/upload-artifact@v2
      with:
        name: dist
        path: dist

  # Deploy job. Uploads distribution to PyPI (only on tags)
  deploy:
    name: Publish to PyPI
    runs-on: ubuntu-latest
    needs: build
    if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
    env:
      PYTHONUNBUFFERED: 1

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Download artifacts
      uses: actions/download-artifact@v2
      with:
        name: dist
        path: dist

    - name: Publish to PyPI
      uses: pypa/gh-action-pypi-publish@v1.2.2
      with:
        user: __token__
        password: ${{ secrets.PYPI_TOKEN }}
        packages_dir: dist/
