name: PyPI package

on:
  push:
    paths:
      - "setup.py"
      - "pso/__init__.py"

permissions:
  contents: read
  packages: write

jobs:
  build-linux:
    runs-on: ubuntu-22.04
    strategy:
      max-parallel: 5
      matrix:
        python-version: ["3.9"]

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          pip install setuptools wheel twine
      - name: Build and publish
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
        run: |
          python setup.py bdist_wheel sdist
          twine upload dist/*.whl dist/*.tar.gz
