diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 00000000..d3b389ea --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,50 @@ +on: + release: + types: [published] + +jobs: + pypi-publish: + name: Upload release to PyPI + runs-on: ubuntu-latest + environment: + name: release + url: https://pypi.org/project/pyvsnr + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install build and twine + run: | + python -m pip install --upgrade pip + pip install build twine + + - name: Build package + run: | + python -m build + + - name: Check package with Twine + run: | + twine check dist/* + + - name: Determine PyPI repository + run: | + if [[ ${{ github.event.release.prerelease }} == 'true' ]]; then + echo "REPOSITORY_URL=https://test.pypi.org/legacy/" >> $GITHUB_ENV + echo "PYPI_API_TOKEN=${{ secrets.TEST_PYPI_API_TOKEN }}" >> $GITHUB_ENV + else + echo "REPOSITORY_URL=https://upload.pypi.org/legacy/" >> $GITHUB_ENV + echo "PYPI_API_TOKEN=${{ secrets.PYPI_API_TOKEN }}" >> $GITHUB_ENV + fi + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@v1.9.0 + with: + repository-url: ${{ env.REPOSITORY_URL }} + user: __token__ + password: ${{ env.PYPI_API_TOKEN }}