PyPI Publishing Setup Guide¶
This guide provides step-by-step instructions for setting up automated PyPI publishing using GitHub Actions with Trusted Publishing.
Overview¶
The publishing workflow (.github/workflows/publish.yml) automatically publishes to PyPI when a GitHub release is created. It uses PyPI's Trusted Publishing feature, which eliminates the need for API tokens.
Prerequisites¶
- Repository owner/admin access on GitHub
- PyPI account with project ownership rights
- Package name available on PyPI (or already registered to you)
Setup Instructions¶
Step 1: Configure PyPI Trusted Publishing¶
-
Log in to PyPI
-
Go to https://pypi.org/
-
Sign in with your account
-
Navigate to Publishing Settings
The project must exist on PyPI before you can add a publisher. Use twine to upload a local build (dist/*) to testpypi, examine the create test project, make changes as need, bump version and repeat until satisfied.
When you are satisfied with the test project, you can publish it to PyPI.
Now you can add a publisher to the existing project. I know, the directions say the project doesn't have to exist, but it does. You cannot add a publisher to a non-existent project no matter how many times you push the Add button (it just doesn't work).
Once the project exists, you can add a publisher to it.
- Go to your account settings: https://pypi.org/manage/account/publishing/
-
Or: Click your username → "Your projects" → Project Name → "Publishing"
-
Add a New Pending Publisher
Click "Add a new pending publisher" and fill in:
- PyPI Project Name:
appimage-updater - Owner:
royw(your GitHub username) - Repository name:
appimage-updater - Workflow name:
publish.yml - Environment name:
pypi
Click "Add" to save.
-
Important Notes
-
This creates a "pending" publisher that will be activated on first successful publish
- After the first publish, the pending publisher becomes a permanent trusted publisher
- You can add this before or after creating the first release
Step 2: Configure GitHub Environment¶
-
Navigate to Repository Settings
-
Go to your repository: https://github.com/royw/appimage-updater
- Click "Settings" tab
-
Click "Environments" in the left sidebar
-
Create PyPI Environment
-
Click "New environment"
- Name:
pypi -
Click "Configure environment"
-
Configure Environment Protection Rules (Recommended)
Add protection rules to prevent accidental publishes:
- Required reviewers: Add yourself or trusted maintainers
- This requires manual approval before publishing
- Wait timer: Optional delay before deployment (e.g., 5 minutes)
- Deployment branches: Select "Selected branches"
- Add rule:
main(only allow publishes from main branch)
- Add rule:
Click "Save protection rules"
-
Environment Secrets (Not needed for Trusted Publishing)
-
With Trusted Publishing, you don't need to add any secrets
- GitHub automatically provides authentication to PyPI
Step 3: Verify Workflow Configuration¶
The workflow file .github/workflows/publish.yml should contain:
environment:
name: pypi
url: https://pypi.org/p/appimage-updater
permissions:
id-token: write # Required for trusted publishing
This is already configured correctly in the repository.
Step 4: Remove Old Publishing Job from CI¶
The publish-to-pypi job should be removed from .github/workflows/ci.yml since we now have a dedicated publishing workflow.
Publishing Process¶
Creating a Release¶
- Ensure Version is Updated
- Commit and Push Changes
- Create Git Tag
-
Create GitHub Release
- Choose tag:
v0.6.0 - Release title:
v0.6.0 - Description: Copy relevant section from CHANGELOG.md
- Check "Set as the latest release"
-
Click "Publish release"
-
Monitor Publishing
-
Go to Actions tab: https://github.com/royw/appimage-updater/actions
- Watch the "Publish to PyPI" workflow
- If environment protection is enabled, approve the deployment
- Verify successful publish to PyPI
Manual Publishing (Testing)¶
For testing the workflow without creating a release:
-
Navigate to Actions
-
Click "Publish to PyPI" workflow
-
Run Workflow
-
Click "Run workflow" button
- Select branch:
main -
Click "Run workflow"
-
Note: Manual runs will still publish to PyPI, so use with caution!
Troubleshooting¶
Common Issues¶
1. "Trusted publishing exchange failure"¶
Cause: PyPI trusted publisher not configured correctly
Solution:
- Verify all fields in PyPI publishing settings match exactly:
- Owner:
royw - Repository:
appimage-updater - Workflow:
publish.yml - Environment:
pypi - Check that the workflow is running from the correct repository
2. "Environment protection rules failed"¶
Cause: Deployment waiting for approval or branch restrictions
Solution:
- Check the Actions tab for pending approvals
- Verify the workflow is running from an allowed branch
- Review environment protection rules in Settings → Environments
3. "Package name already exists"¶
Cause: First-time publish with existing package name
Solution:
- If you own the package: Add trusted publisher to existing project
- If you don't own it: Choose a different package name
4. "Permission denied: id-token"¶
Cause: Missing or incorrect permissions in workflow
Solution:
- Verify
permissions: id-token: writeis in the workflow - Check that the workflow has not been modified incorrectly
Viewing Logs¶
-
GitHub Actions Logs
-
Go to Actions tab
- Click on the workflow run
-
Click on job name to see detailed logs
-
PyPI Activity
- Check "Release history" for published versions
Security Best Practices¶
-
Use Environment Protection
-
Always require manual approval for production publishes
-
Restrict to main branch only
-
Review Before Publishing
-
Check CHANGELOG.md is updated
- Verify version number is correct
- Run tests locally:
uv run pytest -
Build and inspect package:
uv build && ls -lh dist/ -
Monitor Published Packages
-
Review PyPI project page after each publish
- Verify package metadata is correct
-
Test installation:
pip install appimage-updater==0.6.0 -
Trusted Publishing Benefits
-
No API tokens to manage or leak
- Automatic credential rotation
- Audit trail through GitHub Actions
- Reduced attack surface
Additional Resources¶
- PyPI Trusted Publishing Guide
- GitHub Actions Documentation
- PyPI Publishing Action
- Python Packaging Guide
Quick Reference¶
PyPI URLs¶
- Project page: https://pypi.org/project/appimage-updater/
- Publishing settings: https://pypi.org/manage/account/publishing/
GitHub URLs¶
- Repository: https://github.com/royw/appimage-updater
- Actions: https://github.com/royw/appimage-updater/actions
- Environments: https://github.com/royw/appimage-updater/settings/environments
- Releases: https://github.com/royw/appimage-updater/releases