# This workflow will upload a Python Package using Twine when a release is created

name: Upload Python Package

on:
  push:
    # Sequence of patterns matched against refs/tags
    tags:
      - '*' # Push events to matching *, i.e. 1.0, 20.15.10

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Get the version
      id: get_version
      run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine
    - name: Build and publish
      env:
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
      run: |
        sed -i.bak 's/^version =.*/version = "${{ steps.get_version.outputs.VERSION }}"/' setup.py
        python setup.py sdist bdist_wheel
        twine upload dist/*

    - 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: ${{ github.ref }}
        body: |
          Release created, package download: https://pypi.org/project/certbot-dns-infomaniak/${{ steps.get_version.outputs.VERSION }}/
        draft: false
        prerelease: false
