Repository navigation
Publish the package to PyPI on every release - #43
Conversation
A pushed tag never reached PyPI unless someone uploaded it by hand. A new pypi.yml runs on a vX.Y.Z tag: it checks the tag against pyproject.toml, builds the sdist and wheel with SOURCE_DATE_EPOCH at the commit time, runs twine check --strict, and publishes by Trusted Publishing. A dry run from a branch builds and checks only. Signed-off-by: Rich DiMartino <richdimartino@gmail.com> Co-Authored-By: Poe (Claude Opus) <richdimartino+poe@gmail.com>
Prudence (cabal PR 525): with SOURCE_DATE_EPOCH, two builds give the same wheel but different sdists, since sdist members keep file mtimes. The comment said a re-run builds the same files; it now says the wheel, and that skip-existing keeps a re-run passing either way. Signed-off-by: Rich DiMartino <richdimartino@gmail.com> Co-Authored-By: Poe (Claude Opus) <richdimartino+poe@gmail.com>
The one job that held id-token: write also ran uv build and uvx twine (unpinned packages from PyPI), so either could mint the tenish-stack upload token. This ports techne's reviewed pypi.yml (merged there as b8821f0): a build job (contents: read, no persisted credentials) checks the tag against pyproject.toml and that it is on main, builds, runs twine and uploads dist/ as an artifact; a pypi job (tag only, environment pypi, permissions exactly id-token: write) only downloads and publishes. tests/test_ci_workflow.py gains techne's three pypi.yml tests; dropping the job tag guard, widening pypi's permissions, a run step in pypi, or disabling the on-main check each fail one. The header names the trusted publisher's fields (a pending publisher until the first upload). Signed-off-by: Rich DiMartino <richdimartino@gmail.com> Co-Authored-By: Poe (Claude Opus) <richdimartino+poe@gmail.com>
An extra uses: step in the job holding the OIDC token passed the test (Temperance's finding on the same test in daedalus). The test now compares the job's actions in order. Signed-off-by: Rich DiMartino <richdimartino@gmail.com> Co-Authored-By: Poe (Claude Opus) <richdimartino+poe@gmail.com>
prudence-tenishai
left a comment
There was a problem hiding this comment.
Summary
This adds a tag-triggered .github/workflows/pypi.yml that publishes tenish-stack by Trusted Publishing. It also adds readme to pyproject.toml, a CHANGELOG entry and three tests. The split is done properly. build has only contents: read, so uv build and uvx twine never run where an OIDC token can be minted. pypi has exactly {id-token: write}, needs: [build], the job-level guard if: github.ref_type == 'tag' and environment: pypi. Its only steps are download-artifact and the publish action, and the publish step has skip-existing: true and a second tag guard of its own. The checkout sets persist-credentials: false. The build step checks that the exact files tenish_stack-$VERSION-py3-none-any.whl and tenish_stack-$VERSION.tar.gz exist and that nothing else is in dist, and $VERSION has already been checked against the tag. So the uploaded file names are tied to the tag without a separate check in the publish job. The pypi job does not wait on tests, which is a deliberate choice and the header says so: the on-main check (merge-base --is-ancestor HEAD origin/main, with fetch-depth: 0 so origin/main is present) only accepts commits that reached main through the ruleset's required ci check. I also checked the workflow_dispatch path. A dispatch from a branch only builds and checks. A dispatch with --ref vX.Y.Z does publish, because the guard tests ref_type rather than event_name. That run goes through the same version, on-main and environment checks as a tag push, and skip-existing makes it equivalent to a re-run. The header only promises "a dry run from a branch", so I don't count it as a defect. The tests are good. test_pypi_publishes_only_a_tag_by_trusted_publishing compares dicts exactly where that matters, and the two bash-extraction tests run the real step bodies rather than copies of them.
Issues
Nit
tests/test_ci_workflow.py:83: two of the header's guarantees are not pinned. I ran the whole file against each mutant: settingpersist-credentials: truepasses 11/11, and so does deletingskip-existing: true. Both are correct in the workflow today. Two more asserts would make them as hard to delete as the other guarantees.tests/test_ci_workflow.py:37:test_every_action_is_pinned_to_a_commit_shareads onlyci.yml, so nothing tests the pins oncheckout,setup-uv,upload-artifactanddownload-artifactinpypi.yml; only the publish action's pin is asserted. All five pins are correct today (see Verdict). Looping the pin test over both workflow files would keep them that way..github/workflows/pypi.yml:18: one header line runs long ("No PyPI token is stored here. skip-existing lets…"). It looks like a reflow left over from an edit.
Suggestions
None.
Verdict
Verdict: LGTM, verification: executed: these ran on mash1 at 6f52cfc. tests/test_ci_workflow.py passed 11/11, and ruff check stack tests and mypy stack tests (CI's lint and type checks) were clean. I ran the real "Build the sdist and wheel" step body with VERSION=0.1.0: uv build produced exactly the expected wheel and sdist, twine check --strict passed both, and the step exited 0. I applied nine mutants to pypi.yml and ran the whole test file against each. Seven were caught (1 failed each): a run: step moved into pypi, contents: read added to pypi, the job-level tag guard dropped, the environment dropped, the tag-equals-declared check disabled, the on-main check disabled, and id-token added to build. Two passed, as listed under Nit 1. I resolved all five action pins through the GitHub API: checkout v7.0.1, setup-uv v10.3.3, upload-artifact v7.0.2 and download-artifact v8.0.2 are lightweight tags that point straight at the pinned commits. gh-action-pypi-publish v1.14.3 is an annotated tag that dereferences to 7245906… and is the latest release. I could not run the pypi job itself: it needs a pushed tag and the pending publisher on pypi.org. The OIDC exchange and the upload are therefore unexercised until the first release, and the evidence for the permissions and guards is the YAML and the mutants above. Temperance's pre-pass (same sha) had no WRONG or RISKY items and agrees with this.
This repo has no release workflow, so a tagged version reached PyPI only when someone uploaded it by hand. This adds
.github/workflows/pypi.yml, triggered by a pushedvX.Y.Ztag.What it does
pyproject.tomldeclares.uv build, withSOURCE_DATE_EPOCHat the commit time, and requires exactly the two files named for that version. It runstwine check --strictand writes the sha256 of both to the run summary.pypa/gh-action-pypi-publishv1.14.3 (pinned by commit) using Trusted Publishing, in thepypienvironment, withskip-existing. The job has onlycontents: readandid-token: write, and no PyPI token is stored in the repo.workflow_dispatch), it builds and checks only.pyproject.tomlgetsreadme = "README.md". Without it,twine check --strictfails and the PyPI page is blank.Testing
workflow_dispatchworks only once the file is on the default branch. After merge,gh workflow run pypi.yml --ref mainis a dry run.Known gaps
workflow_calltrigger, and techne's test workflow cancels runs that share its concurrency group, so that's left out.Needed before the first tag after this merges
A PyPI owner of
tenish-stackadds a trusted publisher on pypi.org: ownertenishai, repositorystack, workflowpypi.yml, environmentpypi. Until then, the publish step fails with an OIDC error.Part of the suite-wide change started in tenishai/daedalus PR 309 (issue tenishai/daedalus#308): every public repo publishes to PyPI on every tag.
Update: build and publish are separate jobs
The first version ran
uv buildanduvx twine(unpinned packages from PyPI) in the job holdingid-token: write, where any of them could mint the upload token. Our reviewer flagged that shape on tenishai/liminal#273 and tenishai/techne#1430. This now ports techne's reviewedpypi.yml(tenishai/techne#1430): abuildjob (contents: read) checks the tag againstpyproject.tomland that it points at a commit on main, builds, runs twine and uploadsdist/; apypijob (tag only, environmentpypi, permissions exactlyid-token: write) only downloads and publishes. The workflow header names the trusted publisher's fields (a pending publisher until tenish-stack's first upload).A test now pins the trigger and the split, and fails when the publishing job gains a permission beside
id-token, gains arun:step, or the build side loses its check. Still publishes only from avX.Y.Ztag; a merge to main publishes nothing.