name: Release

on:
  push:
    tags:
      - '**'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Get tag
      id: tag
      run: |
        echo ::set-output name=tag::${GITHUB_REF#refs/tags/}

    - name: Set up Python 3.7
      uses: actions/setup-python@v4
      with:
        python-version: 3.7

    - name: Install dependencies
      run: python -m pip install --upgrade pip poetry

    - name: Build project
      run: poetry build

    - name: Publish release to PyPI
      env:
        POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
      run: |
        poetry publish

    - name: Create Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
      with:
        tag_name: ${{ steps.tag.outputs.tag }}
        release_name: ${{ steps.tag.outputs.tag }}
        draft: false
        prerelease: false
