name: Build Test Publish to Test-PyPI


# run when pushing tags or manually run
on:
  push:
    tags:
    - 'tv*'
  workflow_dispatch:



jobs:

  build-and-publish:
    name: Build and publish to Test-PyPI
    runs-on: ubuntu-latest

    steps:
    - name: Checkout main
      uses: actions/checkout@main
    
    - name: Setup Python
      uses: actions/setup-python@v4
      with:
        python-version: "3.7"
    
    - name: Build package
      run: |
        python -m pip install --upgrade pip
        pip install --upgrade setuptools build wheel twine pytest
        python -m build
        
    - name: Install package
      run: |
        python3 -m build --wheel
        pip install dist/*.whl
    
    - name: Test using pytest
      run: |
        pytest tests/    
    
    - name: Publish Test-PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        password: ${{ secrets.TEST_PYPI_API_TOKEN }}
        repository_url: https://test.pypi.org/legacy/

