Skip to content

Publish releases to PyPI from annotated tags through trusted publishing - #1588

Open
dimitri-yatsenko wants to merge 7 commits into
masterfrom
docs/remove-changelog-archive
Open

dimitri-yatsenko wants to merge 7 commits into
masterfrom
docs/remove-changelog-archive

Conversation

@dimitri-yatsenko

@dimitri-yatsenko dimitri-yatsenko commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Summary

A release becomes an annotated tag vX.Y.Z on master whose message is the release notes. Pushing the tag runs .github/workflows/cd.yml, which checks the tag, runs lint and tests, and publishes the package built at the tag to PyPI through trusted publishing, after a maintainer approves the pypi deployment. It then creates the GitHub release from the tag's message. No PyPI token is stored in the repository. The old changelog archive is removed: the tags hold the notes of every past release that had notes, so git show vX.Y.Z prints them.

Changes

  • .github/workflows/cd.yml (replaces post_draft_release_published.yaml):
    • Pull requests and pushes to master build the sdist and wheel once with hynek/build-and-inspect-python-package, which also runs twine check and checks the wheel's contents.
    • On a pushed tag, check runs .github/scripts/check_release_tag.sh <tag> master. A tag must be vX.Y.Z, annotated, on master, and still on the commit the run builds. A tag whose message has a Retroactive: line records a past release and is never published.
    • lint.yaml and test.yaml run as the release gate through workflow_call.
    • The publish job runs in the pypi environment. It is the only job with id-token: write. It checks that the built files carry the tag's version, attests their build provenance, and publishes with pypa/gh-action-pypi-publish.
    • The release job creates the GitHub release "DataJoint Library X.Y.Z" from the tag's message with gh release create --verify-tag, attaching the wheel and sdist. It updates the release instead if one already exists, so a re-run is safe. It also refuses to run if the tag has moved. The release is marked Latest only when its tag is the highest version, so a patch on an older line never displaces a newer release, and a signed tag's signature is left out of the notes.
    • A manual run on a tag ref builds without publishing: only a pushed tag releases.
    • A Slack notification uses the existing SLACK_WEBHOOK_URL secret, and its failure does not fail the run.
    • Top-level permissions: contents: read. Every action is pinned by full SHA. There are no TWINE_* secrets and no TestPyPI path. Tag runs are never cancelled, and the concurrency group has a fixed name.
  • .github/scripts/check_release_tag.sh (new): fails on a tag that is not vX.Y.Z, on a lightweight tag, on a tag not on master, and on a tag that no longer points at GITHUB_SHA. A tag whose message has a Retroactive: line passes with publish=false.
  • Removes draft_release.yaml, .github/release_drafter.yaml and CHANGELOG-archive.md.
  • RELEASE_MEMO.md and CONTRIBUTING.md describe the new release steps. The memo's branch table lists master, next and maint/2.3, and states that every release tag goes on master.

How to release

  1. Write the notes in a file outside the clone, for example ~/release-notes/vX.Y.Z.md. The first line says what the release is about; then the changes, grouped by area, each naming its pull request.
  2. Tag the release commit on master and push the tag:
    git fetch origin
    git tag -a vX.Y.Z <commit on origin/master> --cleanup=verbatim -F ~/release-notes/vX.Y.Z.md
    git tag -n99 vX.Y.Z
    git push origin vX.Y.Z
  3. Once lint and tests pass, approve the pypi deployment on the CD run's page. The workflow publishes to PyPI and creates the GitHub release.

Do not create the tag from the Releases page: it makes a lightweight tag, which the workflow refuses. A release made from the web page is tracked in #1680.

Before the first release

  • pypi environment and the release-tags ruleset are in place: a required reviewer, deployments limited to v*.*.* tags, and only admins can create, update or delete v* tags.
  • To do before tagging: add the PyPI trusted publisher for the datajoint project: owner datajoint, repository datajoint-python, workflow cd.yml, environment pypi. Without it, publishing fails after the deployment is approved.
  • After the first release through this workflow, remove datajoint-python from the access list of the organization secrets TWINE_USERNAME and TWINE_PASSWORD, or delete them if no other repository uses them.

When merging, use a merge commit, or replace the squash message with this PR's summary: earlier commit messages in this branch describe a TestPyPI path and a release.yaml that no longer exist.

@dimitri-yatsenko dimitri-yatsenko added the documentation Issues related to documentation label Oct 15, 2026
Release history now lives entirely in git tags and GitHub Releases.
Every version the archive covered (0.3.2 through 0.14.3) has a tag
and a release carrying its notes.
A release is now an annotated tag vX.Y.Z on master whose message is the release notes. Pushing the tag runs the new Release workflow: it checks the tag, runs the lint and test workflows as the gate, builds the package at the tag, publishes it to PyPI, creates the GitHub release with the tag's message as its notes and the wheel and sdist attached, and posts to Slack.

The check (`.github/scripts/check_release_tag.sh`) fetches the tag object itself, since checkout can store an annotated tag as a lightweight ref. It fails on a lightweight tag, naming the `git tag -a` command, and on a tag whose commit is not on master. It stops without publishing on a tag whose message has a `Retroactive:` line, which marks a past release re-tagged with its notes. Running the workflow by hand from a tag publishes it to TestPyPI, or, with testpypi unchecked, repeats a failed release.

This replaces release-drafter: the Manual Draft Release workflow, its configuration, and the workflow that published a release once its draft was published, including the archived upload-release-asset action. The lint and test workflows gain a workflow_call trigger so the release can run them. RELEASE_MEMO.md describes how a release is cut, and CONTRIBUTING.md points to it. Pull request titles still state the user-visible change, since the notes are written from them; labels no longer drive the notes.
@dimitri-yatsenko
dimitri-yatsenko force-pushed the docs/remove-changelog-archive branch from 86e3038 to 4d2b8fe Compare October 20, 2026 22:41
@dimitri-yatsenko dimitri-yatsenko added enhancement Indicates new improvements and removed documentation Issues related to documentation labels Oct 20, 2026
@dimitri-yatsenko dimitri-yatsenko changed the title docs: remove CHANGELOG-archive.md; history lives in tags and releases ci: release from annotated tags; remove CHANGELOG-archive.md Oct 20, 2026
@dimitri-yatsenko
dimitri-yatsenko marked this pull request as draft October 21, 2026 16:46

@MilagrosMarin MilagrosMarin 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.

Thanks @dimitri-yatsenko, this is a clean design: tags as the single record, a gate that refuses lightweight tags, and the retroactive history preserved. I checked that the past tags (e.g. v2.0.0, v0.14.3, v0.11.2) are already annotated on the remote, and CI is green.

Releasing from the GitHub UI
The web UI can't create an annotated tag. "Draft a new release → Create new tag on publish" makes a lightweight tag, so a release done the usual UI way would:

  1. create the GitHub release and the tag,
  2. fail check_release_tag.sh (lightweight), so nothing reaches PyPI,
  3. need the CLI to fix, and then gh release create fails because the release already exists.

Could we support a UI path? One option:

  • Maintainer writes the notes in a draft release (Save draft, which doesn't create the tag).
  • A workflow_dispatch "Tag release" workflow (input: version) reads the draft body and creates the annotated tag via the API.
  • Since a tag pushed with GITHUB_TOKEN won't trigger release.yaml, either call it directly (workflow_call) or use an App token.
  • release.yaml publishes the existing draft (gh release edit --draft=false + upload assets) instead of gh release create.

If that's out of scope, a line in RELEASE_MEMO.md saying "don't create the tag from the Releases page; it makes a lightweight tag" would prevent a confusing first failure.

Minor

  • Re-runs: if a step after gh release create fails (e.g. Slack), re-running fails at create. Skipping when the release exists would keep re-runs idempotent.
  • Since pushing v* now publishes to PyPI, a tag ruleset restricting who can create v* tags may be worth adding if one isn't in place.
  • RELEASE_MEMO.md says never delete a pushed tag, while the lightweight-tag error says to delete and force-push. Worth noting that a tag rejected by the check is the exception.

Let me know what you think!

@MilagrosMarin

Copy link
Copy Markdown
Contributor

One more small thing on the release flow: step 3 leaves a notes.md behind on the releaser's machine, and nothing stops it from being committed by accident. Two light options:

  • Tag without a file: git tag -a vX.Y.Z --cleanup=verbatim -e (opens the editor; -F - reads stdin).
  • Add notes.md to .gitignore.

The draft-release workflow suggested above would remove the local file entirely, since the notes would live in the draft.

@dimitri-yatsenko dimitri-yatsenko modified the milestones: v2.3.6, v2.3.7 Nov 6, 2026
Write the release notes to git tag on standard input (-F -) so no notes
file is left in the working tree. Note that tags created from the
Releases page are lightweight and refused, and that a tag refused before
publishing is the one tag that may be replaced. The release step updates
an existing GitHub release instead of failing on re-run.
@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Fixed in 00bff96: step 3 now passes the notes to git tag -a vX.Y.Z --cleanup=verbatim -F - from a quoted heredoc, so no notes.md is left in the working tree. I went with stdin rather than -e, since with --cleanup=verbatim the editor's own # instructions would stay in the tag message; the memo says so. The lightweight-tag error in check_release_tag.sh shows the same stdin form.

@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Thanks @MilagrosMarin. Fixed in 00bff96:

  • Releasing from the GitHub UI: RELEASE_MEMO.md now says to create the tag with git, not from the Releases page, since "Create new tag on publish" makes a lightweight tag that the workflow refuses.
  • Re-runs: the release step updates an existing GitHub release (gh release edit --draft=false plus gh release upload --clobber) instead of failing at gh release create. This also covers your step 3: after the lightweight tag is replaced and the workflow re-run, it updates the release that the UI created.
  • Deleting tags: the memo now limits "never move or delete" to tags the workflow has published, and names a tag it refused before publishing anything (such as a lightweight one) as the exception, which matches the error message.

@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

@MilagrosMarin the browser release path you proposed is now #1680, as a follow-up so this PR stays focused on tag-based releases. The tag ruleset is a repository setting and will be handled separately.

Rename the release workflow to cd.yml and publish with
pypa/gh-action-pypi-publish from the pypi environment, so no PyPI token
is stored in the repository. Pull requests and pushes to master build
the sdist and wheel once; a release tag also checks the tag, runs lint
and tests, and creates the GitHub release from the tag's message.

The tag check now also fails if the tag no longer points at the commit
the run builds. Remove the TestPyPI path and the TWINE secrets, pin every
action by SHA, and document writing the notes outside the clone and
approving the pypi deployment.
@dimitri-yatsenko dimitri-yatsenko changed the title ci: release from annotated tags; remove CHANGELOG-archive.md Publish releases to PyPI from annotated tags through trusted publishing Nov 21, 2026
@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

@MilagrosMarin, an update on your two points. The release workflow is now cd.yml. It publishes to PyPI through trusted publishing after a maintainer approves the pypi deployment, so the release process is described again in RELEASE_MEMO.md.

  • Releasing from the GitHub web page: this is tracked as a follow-up in Release from the GitHub UI: write the notes in a draft release, and let a workflow make the annotated tag #1680, so this PR stays focused on releasing from tags. Until then, RELEASE_MEMO.md says to create the tag with git, not from the Releases page, because "Create new tag on publish" makes a lightweight tag, which the workflow refuses. The release job still updates a GitHub release that already exists, so a release first created on the web page is handled once its tag is replaced with an annotated one.
  • The notes.md left behind: the notes are now written to a file outside the clone, so nothing is left in the working tree. RELEASE_MEMO.md now says: write the notes in a file outside the clone, such as ~/release-notes/vX.Y.Z.md, then run git tag -a vX.Y.Z <commit on origin/master> --cleanup=verbatim -F ~/release-notes/vX.Y.Z.md and push the tag. The error that check_release_tag.sh prints for a lightweight tag gives the same form.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Indicates new improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants