# cspell:ignore noreply prereleased sdist
name: CD

on:
  release:
    types:
      - prereleased
      - released

jobs:
  push:
    name: Push to stable branch
    if: startsWith(github.ref, 'refs/tags')
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@master
      - name: Push to stable branch
        run: |
          git config --global user.name "GitHub Action"
          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git push origin HEAD:refs/heads/stable -f

  pypi:
    name: Publish to PyPI
    if: startsWith(github.ref, 'refs/tags')
    needs: push
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: "3.8"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install scikit-build setuptools twine wheel
      - name: Build and publish
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
        run: |
          python setup.py sdist
          twine upload dist/*
