Overview
Create a separate GitHub Actions workflow for publishing to TestPyPI to enable safe testing of the release process before publishing to production PyPI.
Why TestPyPI?
Benefits:
- ✅ Test the entire release process without touching production
- ✅ Verify PyPI Trusted Publishing configuration works
- ✅ Catch packaging/metadata issues early
- ✅ Safe experimentation with workflow changes
- ✅ Standard best practice for Python projects
Implementation Checklist
1. TestPyPI Account Setup
2. Configure Trusted Publishing on TestPyPI
3. Create GitHub Environment
4. Create Workflow File
# GitHub Actions CI/CD - TestPyPI Publish Workflow
# Publishes package to TestPyPI for testing
name: Publish to TestPyPI
on:
push:
tags:
- 'v*-test*' # Trigger on test tags (e.g., v2.2.0-test, v2.2.0-test1)
workflow_dispatch: # Allow manual trigger
jobs:
build-and-publish-test:
name: Build and Publish to TestPyPI
runs-on: ubuntu-latest
environment: testpypi # Use GitHub environment for Trusted Publishing
permissions:
id-token: write # Required for Trusted Publishing
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build distribution packages
run: |
python -m build
- name: Check distribution packages
run: |
twine check dist/*
ls -la dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
verbose: true
print-hash: true
5. Test the Workflow
6. Documentation
Usage Examples
Testing a release:
# 1. Create test release branch
git checkout -b release-2.2-test main
# 2. Update version to test version
# pyproject.toml: version = "2.2.0-test1"
# devflow/__init__.py: __version__ = "2.2.0-test1"
# 3. Tag and push
git add pyproject.toml devflow/__init__.py
git commit -m "chore: bump version to 2.2.0-test1 for TestPyPI"
git tag -a v2.2.0-test1 -m "Test release 2.2.0"
git push origin v2.2.0-test1
# 4. Verify TestPyPI publication
# Check: https://test.pypi.org/project/devaiflow/
# 5. Test installation
pip install --index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
devaiflow==2.2.0-test1
# 6. If successful, proceed with production release using v2.2.0 tag
Manual workflow trigger:
Tag Naming Convention
- TestPyPI:
v2.2.0-test, v2.2.0-test1, v2.2.0-test2
- Production PyPI:
v2.2.0, v2.2.1, v2.3.0
The -test suffix ensures the workflow only triggers for test releases.
Expected Outcomes
After completing this issue:
- ✅ Safe testing environment for release process
- ✅ Ability to verify Trusted Publishing works
- ✅ Catch issues before production release
- ✅ Confidence in release automation
- ✅ Best practice Python packaging workflow
References
Acceptance Criteria
Overview
Create a separate GitHub Actions workflow for publishing to TestPyPI to enable safe testing of the release process before publishing to production PyPI.
Why TestPyPI?
Benefits:
Implementation Checklist
1. TestPyPI Account Setup
2. Configure Trusted Publishing on TestPyPI
devaiflowitdovedevaiflowpublish-test.ymltestpypi3. Create GitHub Environment
testpypirelease-*branches4. Create Workflow File
.github/workflows/publish-test.ymlwith the following content:5. Test the Workflow
Create test release branch:
Update version to test version in
pyproject.toml:Update version in
devflow/__init__.py:Commit changes:
git add pyproject.toml devflow/__init__.py git commit -m "chore: bump version to 2.2.0-test1 for TestPyPI"Create and push test tag:
git tag -a v2.2.0-test1 -m "Test release for TestPyPI" git push origin v2.2.0-test1Monitor GitHub Actions: https://github.com/itdove/devaiflow/actions
Verify publication on TestPyPI: https://test.pypi.org/project/devaiflow/
Test installation from TestPyPI:
6. Documentation
v*-test*for TestPyPI,v*for productionUsage Examples
Testing a release:
Manual workflow trigger:
Tag Naming Convention
v2.2.0-test,v2.2.0-test1,v2.2.0-test2v2.2.0,v2.2.1,v2.3.0The
-testsuffix ensures the workflow only triggers for test releases.Expected Outcomes
After completing this issue:
References
Acceptance Criteria
testpypicreated