name: Package Release
on:
  push:
    tags: "*"
  release:
    types: [released]
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 100
          persist-credentials: false
      - name: Fetch git tags
        run: git fetch origin 'refs/tags/*:refs/tags/*'
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.9"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools setuptools_scm wheel twine
      - name: Build and Install Wheel
        run: |
          python setup.py bdist_wheel
          pip install dist/scooby*.whl
      - name: Test Report Generation with No Dependencies
        run: python -c "import scooby;scooby.Report();"
      - name: Build and Publish to PyPI
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
        run: |
          python setup.py sdist
          twine upload --skip-existing dist/scooby*
