name: Publish chkit-py to PyPI # chkit-py is versioned on its own, outside the changesets `fixed` group: bump # `version` in chkit_python/pyproject.toml, merge, then push a # `chkit-py-v` tag. The tag must match the pyproject version. # # Publishing uses PyPI trusted publishing (OIDC), so no API token is stored. # One-time setup on pypi.org: project `chkit-py` → Publishing → trusted # publisher with owner `obsessiondb`, repository `chkit`, workflow # `publish-chkit-py.yml`, environment `pypi`. TestPyPI needs the same on # test.pypi.org with environment `testpypi`. # # Run it manually (workflow_dispatch) to rehearse a release: `dry-run` builds, # checks and smoke-tests the dists without uploading; `testpypi` also uploads # them to TestPyPI. on: push: tags: - "chkit-py-v*" workflow_dispatch: inputs: target: description: "dry-run: build and check only; testpypi: also upload to TestPyPI" type: choice options: - dry-run - testpypi default: dry-run # Minimal default for every job; the publish jobs add the id-token permission # OIDC needs. permissions: contents: read jobs: build: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v7 - uses: astral-sh/setup-uv@v10.3.0 with: version: 0.13.0 - name: Verify tag matches package version if: github.event_name == 'push' working-directory: chkit_python run: | version=$(uv version --short) tag="${GITHUB_REF_NAME#chkit-py-v}" if [ "$version" != "$tag" ]; then echo "Tag $GITHUB_REF_NAME does not match pyproject version $version" >&2 exit 1 fi # The same script `bun run verify` runs as the @chkit/python build task: # sdist + wheel, `twine check --strict`, and a smoke test of the wheel. - name: Build, check and smoke-test run: bash chkit_python/scripts/build.sh - uses: actions/upload-artifact@v7 with: name: chkit-py-dist path: chkit_python/dist/ if-no-files-found: error publish: needs: build if: github.event_name == 'push' runs-on: ubuntu-24.04 environment: name: pypi url: https://pypi.org/project/chkit-py/ permissions: id-token: write steps: - uses: actions/download-artifact@v8 with: name: chkit-py-dist path: dist/ - uses: pypa/gh-action-pypi-publish@release/v1 with: packages-dir: dist/ publish-testpypi: needs: build if: github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi' runs-on: ubuntu-24.04 environment: name: testpypi url: https://test.pypi.org/project/chkit-py/ permissions: id-token: write steps: - uses: actions/download-artifact@v8 with: name: chkit-py-dist path: dist/ - uses: pypa/gh-action-pypi-publish@release/v1 with: packages-dir: dist/ repository-url: https://test.pypi.org/legacy/