Publishing
Publishing Releases¶
This is how to publish a Python package to PyPI from GitHub Actions, when using the python-template template.
Thanks to
the dynamic versioning plugin,
the release.yml
workflow (semantic-release), and the publish.yml
workflow, tagged GitHub Releases publish the matching version to PyPI.
You can release in either way:
- Automatic (recommended): push Conventional Commits to
main/master.release.ymlruns semantic-release, which creates a GitHub Release and avX.Y.Ztag when commits warrant a bump. It then dispatchespublish.ymlon that tag. - Manual: create a tagged release yourself in the GitHub UI or with
gh(below). Thatrelease: publishedevent startspublish.yml.
Why the automatic path dispatches instead of waiting for the release event:
GitHub does not start a new workflow from an event created with the default
GITHUB_TOKEN. semantic-release uses that token, so the release it creates
never triggers publish.yml on its own. workflow_dispatch is one of the two
exceptions, which is why release.yml calls gh workflow run. Leave that job
on GITHUB_TOKEN. A PAT or a GitHub App token would also fire the release
event, and publish.yml would run twice.
publish.yml can also be started with Run workflow. Start it from the release
tag (the workflow input defaults to PyPI; choose TestPyPI for a dry upload).
A dispatch from a branch has no vX.Y.Z tag, so uv-dynamic-versioning produces
a local version that PyPI rejects.
First-Time Setup¶
This part is a little confusing the first time. Here is the simplest way to do it. For the purposes of this example replace OWNER and PROJECT with the right values.
Note: These steps assume you already have a GitHub repo with your code pushed. If you're setting up manually, create an empty GitHub repo (no README, no .gitignore, no license — the template already provides these) and push your code to it. See the python-template README for Copier usage and repo layout.
-
Get a PyPI account at pypi.org and sign in.
-
Pick a name for the project that isn’t already taken.
-
Go to
https://pypi.org/project/PROJECTto see if another project with that name already exists. -
If needed, update your
pyproject.tomlwith the correct name. -
Add the API tokens as repository Actions secrets (Settings → Secrets and variables → Actions):
-
PYPI_API_TOKEN, from pypi.org/manage/account/token/. TEST_PYPI_API_TOKEN, from test.pypi.org/manage/account/token/.
publish.yml reads those names. A run that targets TestPyPI uploads to
https://test.pypi.org/legacy/ and does not touch production PyPI.
The job also selects a GitHub Environment named pypi or testpypi.
Create one (Settings → Environments) only when you want required
reviewers to hold a publish. The secret names stay on the repository.
- Create a first release so versioning starts on
0.x(optional but recommended):
semantic-release’s first release is 1.0.0 if no tags exist. To stay on 0.x, create
an initial tag once after setup:
Later bumps follow Conventional Commits automatically.
-
Confirm it publishes to PyPI
-
Watch
release.ymland thepublish.ymlrun it starts (or the run started by a manual release) in the GitHub Actions tab. -
If it succeeds, you should see it appear at
https://pypi.org/project/PROJECT.
What the publish job checks¶
publish.yml tests the tree, builds with uv build --no-sources (so the wheel
does not depend on a local path), imports the package from that wheel, then
uploads with uv publish --token, using PYPI_API_TOKEN or
TEST_PYPI_API_TOKEN.
Publishing Subsequent Releases¶
Follow this checklist for each new release.
Pre-Release Checklist¶
- Verify all changes are committed and pushed:
- Run linting and tests locally:
- Confirm CI is passing:
Or check the Actions tab on GitHub.
- Determine the new version number (manual releases only):
Use semantic versioning / Conventional Commits:
- fix: → patch (e.g.
v0.5.8→v0.5.9) - feat: → minor (e.g.
v0.5.9→v0.6.0) - BREAKING CHANGE /
!→ major (e.g.v0.6.0→v1.0.0)
Create the Release¶
-
Automatic: merge Conventional Commits to
mainand letrelease.ymlcreate the GitHub Release and dispatchpublish.yml. If the release exists but the upload failed, re-runpublish.ymlfrom the tag. Re-runningrelease.ymldoes not publish again: semantic-release finds nothing new to release and skips the dispatch. -
Manual — create the release with
gh:
NEW_TAG="vX.Y.Z" # Replace with actual version
LAST_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName')
gh release create "${NEW_TAG}" \
--title "${NEW_TAG}" \
--notes "$(cat <<'EOF'
## What's Changed
[Summarize changes here--see format guide below]
### Full Changelog
https://github.com/OWNER/PROJECT/compare/${LAST_TAG}...${NEW_TAG}
EOF
)"
Alternatively, use --generate-notes for GitHub’s auto-generated notes, or
--notes-file FILENAME to read from a file.
- Verify the release published successfully:
# Check the release workflow:
gh run list --workflow=publish.yml --limit 1
# Verify on PyPI (may take a minute):
# https://pypi.org/project/PROJECT
Release Notes Format¶
Use this structure for release notes (manual releases):
## What's Changed
### Bug Fixes
**Short title of fix**
Description of what was fixed and why it matters.
### New Features
**Short title of feature**
Description of the new capability.
### Breaking Changes
**Short title of breaking change**
Description of what changed and how to migrate.
### Full Changelog
https://github.com/OWNER/PROJECT/compare/vPREVIOUS...vNEW
Guidelines:
-
Use
## What's Changedas the top-level heading. -
Group changes under
### Bug Fixes,### New Features,### Breaking Changes, etc. as appropriate. -
Use
**bold**for short titles of individual changes. -
Include technical details only when helpful for users.
-
Always include the Full Changelog compare link at the end.
-
For small releases, a simple bullet list is acceptable instead of full sections.
This file was built with python-template.