---
name: "Publish release"

#on:
#  push:
#    branches:
#      - stable
#    tags:
#      - 'v*'

jobs:
  publish-release:
    name: "Create Release"
    runs-on: ubuntu-latest
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v2

      - name: "Set up Python"
        uses: actions/setup-python@v2
        with:
          python-version: "3.8"
      - name: "Install dependencies"
        run: |
          set -xe
          python -VV
          python -m site
          python -m pip install --upgrade pip setuptools wheel
      - name: "Build package"
        run: |
          python setup.py sdist --formats=gztar,zip bdist_wheel
      - name: "Create Release"
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          draft: false
          prerelease: false
      - name: "Publish package to PyPI"
        uses: pypa/gh-action-pypi-publish@v1.3.1
        with:
          skip_existing: true
          user: __token__
          password: ${{ secrets.PYPI_TOKEN }}
      - name: "Upload Release Asset"
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./dist/yacfg-${GITHUB_REF##*/}.zip
          asset_name: yacfg-${GITHUB_REF##*/}.zip
          asset_content_type: application/zip
