diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 8a68d2a..31471d6 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,28 +1,88 @@ -name: Publish Python 🐍 distributions 📦 to PyPI +name: Publish Python distributions to PyPI + on: - release: - types: - - published + pull_request: + paths: + - '.github/workflows/publish-to-pypi.yml' + - 'MANIFEST.in' + - 'README.md' + - 'polypheny/**' + - 'pyproject.toml' + - 'setup.py' + workflow_dispatch: + inputs: + release_tag: + description: Version to build without publishing (e.g. v2.0.0) + default: v0.0.0 + type: string + release: + types: [published] + +permissions: + contents: read + jobs: - publish: - name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - id-token: write - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.8 - uses: actions/setup-python@v5 - with: - python-version: 3.8 - - name: Set Version - id: version - run: echo "${GITHUB_REF#refs/tags/}" > polypheny-connector-version.txt - - name: Create MANIFEST.in - run: echo "include polypheny-connector-version.txt" > MANIFEST.in - - name: Build package - run: python setup.py sdist - - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + build: + name: Build and verify Python distributions + runs-on: ubuntu-latest + timeout-minutes: 10 + env: + RELEASE_TAG: ${{ github.event.release.tag_name || inputs.release_tag || 'v0.0.0' }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Set package version + run: | + if [[ ! "$RELEASE_TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then + echo 'Expected a vMAJOR.MINOR.PATCH version, for example v2.0.0.' >&2 + exit 1 + fi + printf '%s\n' "$RELEASE_TAG" > polypheny-connector-version.txt + + - name: Build source distribution and wheel + run: | + python -m pip install 'build==1.6.1' 'twine==7.0.0' + python -m build + + - name: Check metadata and test installed wheel + run: | + python -m twine check --strict dist/* + python -m venv "$RUNNER_TEMP/polypheny-release" + smoke_python="$RUNNER_TEMP/polypheny-release/bin/python" + "$smoke_python" -m pip install dist/*.whl + "$smoke_python" -m pip check + "$smoke_python" -I - <<'PY' + import os + from importlib.metadata import version + + import polypheny + + assert version("polypheny") == os.environ["RELEASE_TAG"][1:] + assert callable(polypheny.connect) + PY + + - uses: actions/upload-artifact@v4 + with: + name: python-distributions + path: dist/ + if-no-files-found: error + + publish: + name: Publish verified distributions to PyPI + if: github.event_name == 'release' && !github.event.release.prerelease + needs: build + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: python-distributions + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e571f17 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include polypheny-connector-version.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..26e6bb0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=68"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index aca754a..0e7008e 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ def readme(): 'release': ('setup.py', version), }, }, - python_requires=">=3.8", + python_requires=">=3.9", install_requires=[ "polypheny-prism-api==2.2", ],