Skip to content

Derive version from git tag and publish to PyPI via OIDC - #257

Merged
zanjonke merged 1 commit into
mainfrom
feat/release
Jul 24, 2026
Merged

Derive version from git tag and publish to PyPI via OIDC#257
zanjonke merged 1 commit into
mainfrom
feat/release

Conversation

@zanjonke

@zanjonke zanjonke commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the failing PyPI publish workflow and makes releases fully tag-driven.

Previously the workflow tried to sed a version = line into pyproject.toml that didn't exist (the version was dynamic), then git commited with nothing staged — which failed the job. This replaces that with a clean, conventional setup.

Changes

  • pyproject.toml — build with hatch-vcs; the version is sourced from the git tag ([tool.hatch.version] source = "vcs"). Removed the _version.py path source.
  • _version.py — deleted. No longer stored in the repo; the version comes from the git tag at build time.
  • system_config.pyclient_version now resolves from installed package metadata (importlib.metadata), falling back to the highest git tag for uninstalled source checkouts.
  • .github/workflows/publish-to-pypi.yml
    • release-triggered only (removed the manual workflow_dispatch/version-input path),
    • least-privilege permissions (top-level {}, opt-in per job),
    • publishes via PyPI Trusted Publishing (OIDC) using pypa/gh-action-pypi-publish instead of a long-lived PYPI_API_TOKEN.

The PyPI Trusted Publisher (owner Codeplain-ai, repo codeplain, workflow publish-to-pypi.yml, environment pypi) is already registered.

Release procedure after this merges

Publish a GitHub Release with tag vX.Y.Z (higher than what's on PyPI) → the workflow builds with that version and publishes to PyPI. No secrets, no manual version bumps.

Verification

  • uv build on a clean tag checkout produces the exact tag version (verified end-to-end).
  • Clean pip install of the built wheel → codeplain --version reports the correct version (via package metadata).
  • black, isort, flake8, mypy, and the test suite all pass.

Testing recommendation

Cut a pre-release vX.Y.Zrc1 first (marked pre-release) to exercise the full OIDC pipeline without affecting normal pip install users.

@zanjonke
zanjonke requested a review from pedjaradenkovic July 21, 2026 13:03
@zanjonke zanjonke self-assigned this Jul 21, 2026
@zanjonke zanjonke added the enhancement New feature or request label Jul 21, 2026
Replace the broken sed/commit-back release flow with tag-driven
versioning:

- pyproject.toml: build with hatch-vcs, version sourced from the git
  tag (source = "vcs"); drop the _version.py path source.
- Remove _version.py; system_config resolves the version from package
  metadata, falling back to the highest git tag for source checkouts.
- publish-to-pypi.yml: release-triggered only, least-privilege
  permissions, and publish via PyPI Trusted Publishing (OIDC) using
  pypa/gh-action-pypi-publish instead of a long-lived API token.

@pedjaradenkovic pedjaradenkovic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go!

@zanjonke
zanjonke merged commit 9c2c659 into main Jul 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants