updated README.md #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Python SDK Legacy Name | |
| on: | |
| workflow_dispatch: | |
| release: | |
| types: | |
| - published | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| defaults: | |
| run: | |
| working-directory: bindings/python_legacy | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Check if version is already on PyPI | |
| id: pypi_check | |
| run: | | |
| python - <<'PY' | |
| import json | |
| import os | |
| import tomllib | |
| import urllib.error | |
| import urllib.request | |
| with open("pyproject.toml", "rb") as f: | |
| project = tomllib.load(f)["project"] | |
| name = project["name"] | |
| version = project["version"] | |
| url = f"https://pypi.org/pypi/{name}/json" | |
| publish_needed = True | |
| try: | |
| with urllib.request.urlopen(url, timeout=15) as resp: | |
| payload = json.load(resp) | |
| releases = payload.get("releases", {}) | |
| publish_needed = version not in releases | |
| except urllib.error.HTTPError as e: | |
| if e.code != 404: | |
| raise | |
| with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out: | |
| out.write(f"publish_needed={'true' if publish_needed else 'false'}\n") | |
| PY | |
| - name: Build package | |
| if: steps.pypi_check.outputs.publish_needed == 'true' | |
| run: | | |
| python -m pip install --upgrade pip build twine | |
| python -m build | |
| - name: Publish to PyPI | |
| if: steps.pypi_check.outputs.publish_needed == 'true' | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| if [ -z "${TWINE_PASSWORD}" ]; then | |
| echo "PYPI_API_TOKEN secret is missing" | |
| exit 1 | |
| fi | |
| twine upload dist/* | |
| - name: Skip publish (already exists) | |
| if: steps.pypi_check.outputs.publish_needed != 'true' | |
| run: echo "Version already exists on PyPI; skipping publish." |