name: Release

on:
  push:
    tags:
      - release/*

jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: ["3.8", "3.9", "3.10", "3.11",]
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v2

      - name: Dump env
        shell: bash
        env:
          GITHUB_DUMP: ${{ toJson(github) }}
        run: |
          echo "github env:"
          echo "$GITHUB_DUMP"

      - name: Set up Python interpreter [${{ matrix.python-version }}]
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install dependencies
        shell: bash
        run: |
            python -m pip install --upgrade pip
            pip install setuptools build wheel twine
            pip install -r tests/requirements.txt

      - name: Build wheel and sdist packages
        env:
          PYTHONPATH: .
          GITHUB_DUMP: ${{ toJson(github) }}
        run: |
          python -m build

      - name: Publish packages to pypi (release)
        shell: bash
        env:
          TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
          TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
        run: |
          twine upload --skip-existing --non-interactive --repository pypi dist/*
  
