---
name: "Version build"

on:
  push:
    tags:
      - "v*.*.*"

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      # Currently, only for one arch, because I've got no idea about cross-platform and python
      matrix:
        include:
          - os: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - uses: actions/setup-python@v4
        with:
          python-version: 3.9

      - name: Setup poetry
        uses: abatilo/actions-poetry@v2
        with:
          poetry-version: 1.3.2

      - name: Build
        run: poetry build

      - name: Get archive name
        run: echo "ARCHIVE_NAME=$(find $GITHUB_WORKSPACE/dist -maxdepth 1 -mindepth 1 -name '*tar.gz' -execdir basename '{}' ';')" >> $GITHUB_ENV

      - name: Archive build artifacts
        uses: actions/upload-artifact@v3
        with:
          name: ${{ env.ARCHIVE_NAME }}
          path: ${{  github.workspace  }}/dist/${{ env.ARCHIVE_NAME }}

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Download artifact
        uses: actions/download-artifact@v3
        with:
          path: ${{  github.workspace  }}/release/
      - name: check
        run: ls -R 

      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          files: ${{  github.workspace  }}/release/*/*