name: publish to TestPyPI

on: push

jobs:
  build-n-publish:
    name: Build and publish Python 🐍 distributions 📦 TestPyPI
    runs-on: ubuntu-20.04
    
    steps:
    - uses: actions/checkout@master
    - name: Set up Python 3.8
      uses: actions/setup-python@v1
      with:
        python-version: 3.8
    - name: Install libvips
      run: sudo apt-get install -y libvips
    - name: Install pypa/build
      run: >-
        python -m
        pip install -r requirements.txt
        --user
    - name: Initialize submodule
      run: >-
        git submodule init
    - name: Update submodule
      run: >-
        git submodule update --remote --recursive
    - name: Build a binary wheel
      run: >-
        python
        setup.py
        bdist_wheel
    - name: Publish distribution 📦 to Test PyPI
      if: startsWith(github.ref, 'refs/tags')
      uses: pypa/gh-action-pypi-publish@master
      with:
        password: ${{ secrets.TEST_PYPI_API_TOKEN }}
        repository_url: https://test.pypi.org/legacy/
