name: CI

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.10.13

    - name: Install Poetry
      run: |
        pip install poetry coverage
        poetry config virtualenvs.create false

    - name: Run unittest tests
      run: coverage run -m unittest discover -s tests

    - name: Upload Coverage to Codecov
      uses: codecov/codecov-action@v2
      with:
        token: ${{ secrets.CODECOV_TOKEN }}

    - name: Build with Poetry
      run: |
        poetry build

    - name: Publish
      run: |
        pip install twine
        twine upload dist/*
      env:
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
