Automating Python Releases: GitHub Actions, Poetry, and Trusted Publishers
Overview of Automated Publishing
Publishing a
Prerequisites and Tools
To follow this workflow, you need a basic understanding of

Key Libraries & Tools
- Poetry: A comprehensive tool forPythonpackaging and dependency management.
- PyPI: The official third-party software repository forPython.
- GitHub Actions: A CI/CD platform that allows you to automate your build, test, and deployment pipeline.
- Trusted Publishers: A PyPIsecurity feature that uses short-livedOIDCtokens instead of permanent API keys.
Configuring Trusted Publishers
Security is paramount when connecting release.yml). This prevents long-lived credentials from being stolen or leaked.
Building the Workflow
The heart of the automation is the .github/workflows/release.yml file. This workflow should trigger only when a specific tag pattern is pushed. Using regular expressions ensures that only valid version tags following
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
The workflow is divided into logical jobs: fetching details, checking if the version already exists on
jobs:
setup-and-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Poetry
run: pipx install poetry
- name: Build
run: poetry build
We utilize poetry build to generate the source distribution and the wheel file. These artifacts are then passed to the pypa/gh-action-pypi-publish action for the final upload.
Syntax Notes and Best Practices
Pay close attention to GitHub Output. When passing data between jobs, you cannot use standard environment variables because each job runs on a fresh virtual machine. Instead, use echo "key=value" >> $GITHUB_OUTPUT to persist data like version numbers for subsequent jobs. Additionally, always follow
Tips & Gotchas
1.0.0 and realize there is a bug, you cannot simply delete and re-upload 1.0.0. You must bump the version to 1.0.1. Implementing a check job in your workflow that queries the

Fancy watching it?
Watch the full video and context