Skip to content

ci: publish to PyPI from a GitHub release (trusted publishing) - #65

Merged
petercorke merged 5 commits into
mainfrom
ci/pypi-trusted-publish
Oct 13, 2026
Merged

petercorke merged 5 commits into
mainfrom
ci/pypi-trusted-publish

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Adds .github/workflows/publish.yml, which is not on main yet, so a GitHub release would not currently publish anything. It follows the release workflow of the other toolboxes (MVTB, bdsim): OIDC trusted publishing, no stored token.

What it does, on release: created or workflow_dispatch

  1. verify_version: the tag (v1.0.0) must equal [project].version in pyproject.toml, and the tagged commit must be on main. The 0.6.5 release was tagged on a commit that was never merged, so main still says 0.6.4; this refuses that.
  2. build: python -m build, then twine check.
  3. smoke_test: install the built wheel into a clean environment (dependencies from PyPI) and run an A* query.
  4. upload_pypi: pypa/gh-action-pypi-publish from the pypi environment, with id-token: write on this job only; skip_existing makes a re-run harmless.

The workflow token is contents: read everywhere else (the repository default is write).

Also

  • ci.yml: the docs job can be run by hand with workflow_dispatch, from main only, so unreviewed docs cannot be deployed to gh-pages.
  • Makefile: the manual make pypi target (build, twine upload, tag, push) is removed; a release does it.

Rehearsed here

From a clean checkout: python -m build gives the sdist and wheel, twine check passes, the wheel installs into a fresh venv (checked that it is isolated) and the smoke test prints OK 0.6.4 5.0. The version guard passes for a matching tag and refuses a mismatch. (This is not a release: main is still 0.6.4, so a tag v1.0.0 is refused until #14 is merged, which is the intent.)

Needed on PyPI before it can upload (not in this PR)

A trusted publisher for pgraph-python: owner petercorke, repository pgraph-python, workflow publish.yml, environment pypi. (The entry there now says pipit.) GitHub will create the pypi environment on the first run; add a required reviewer if you want an approval gate.

Release order

Merge this, then update and merge #14 (version 1.0.0), then create the GitHub release from main.

🤖 Generated with Claude Code

petercorke and others added 3 commits October 13, 2026 10:32
Adds .github/workflows/publish.yml: on a published GitHub Release,
build sdist+wheel from the release tag, check metadata with twine,
and publish to PyPI via pypa/gh-action-pypi-publish using OIDC trusted
publishing (permissions: id-token: write) -- no stored token/secret.
Scoped to a "pypi" GitHub Environment so PyPI's trusted-publisher
check is exact (repo + workflow + environment) and so manual-approval
gating can be added later if wanted.

Requires a one-time manual step on PyPI: add a trusted publisher on
the existing pgraph-python project (Settings -> Publishing) naming
this repo, workflow filename, and the "pypi" environment.

Also adds workflow_dispatch to ci.yml's triggers, and widens the docs
job's condition to run on manual dispatch as well as push, so the
Sphinx docs can be manually rebuilt/redeployed on demand without any
relationship to a PyPI release -- the two are on separate triggers
entirely (push+dispatch for docs, release-published only for PyPI).

Verified: pyproject.toml/publish.yml YAML parses; `python -m build`
produces a clean sdist+wheel from this checkout; `twine check` passes
on both; a genuinely isolated venv (confirmed via sys.prefix) installs
the built wheel and successfully imports and exercises real
functionality (UGraph/add_vertex/add_edge/__str__).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
make pypi (build + twine upload + tag + push) is superseded by
.github/workflows/publish.yml's trusted-publish-on-release flow.
Updated the help text accordingly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
publish.yml follows the release workflow of the other toolboxes: verify that
the tag is the version in pyproject.toml and that the tagged commit is on
main, build the sdist and wheel, twine check, install the wheel into a clean
environment and run a path query, then upload with OIDC from the pypi
environment.  skip_existing makes a re-run harmless.  The default token is
read-only.

The docs job of ci.yml can be run by hand, from main only.  The manual
twine-upload Makefile target is gone, as a release does it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

petercorke and others added 2 commits October 13, 2026 10:35
A third-party action with the right to publish should be an immutable
reference.  dependabot (github-actions, monthly) keeps it current.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (6103438) to head (a5ef6e9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #65   +/-   ##
=======================================
  Coverage   97.26%   97.26%           
=======================================
  Files           3        3           
  Lines        1570     1570           
=======================================
  Hits         1527     1527           
  Misses         43       43           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke
petercorke merged commit d41fd62 into main Oct 13, 2026
14 checks passed
@petercorke
petercorke deleted the ci/pypi-trusted-publish branch October 13, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant