PyPI Publishing Guide¶
This guide explains how to publish the gi package to PyPI using GitHub Actions.
Overview¶
The gi package is automatically published to PyPI when: 1. A new GitHub release is created 2. The workflow is manually triggered
Setup Instructions¶
1. Create PyPI Account¶
- Go to PyPI and create an account
- Verify your email address
2. Configure Trusted Publishing (Recommended)¶
Trusted publishing is more secure than API tokens and is the recommended approach.
Step 1: Create PyPI Project¶
- Go to PyPI and create a new project named
python-gitignore - Note: The project name must match the name in
pyproject.toml
Step 2: Configure Trusted Publishing¶
- In your PyPI project settings, go to "Publishing" → "Trusted publishers"
- Click "Add a new pending publisher"
- Configure the publisher:
- PyPI project name:
python-gitignore - Owner:
sempervent(your GitHub username/organization) - Repository name:
gi - Workflow filename:
publish.yml - Environment name:
pypi - Environment URL: Leave empty
- Click "Add pending publisher"
- The publisher will be pending until the first successful run
3. Alternative: API Token Method¶
If you prefer to use API tokens instead of trusted publishing:
Step 1: Create API Token¶
- Go to PyPI Account Settings
- Go to "API tokens" section
- Click "Add API token"
- Choose "Entire account (all projects)" or "Specific project"
- Copy the token (it starts with
pypi-)
Step 2: Add Secret to GitHub¶
- Go to your GitHub repository
- Go to Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
PYPI_API_TOKEN - Value: Your PyPI API token
Step 3: Update Workflow¶
If using API tokens, uncomment the environment variables in the workflow:
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
# ... rest of the command
Publishing Process¶
Automatic Publishing (Recommended)¶
-
Create a GitHub Release:
-
The workflow will:
- Build the package using
python -m build - Upload to PyPI using
twine - Verify the publication
Manual Publishing¶
- Go to your GitHub repository
- Go to Actions → "Publish to PyPI"
- Click "Run workflow"
- Enter the version number
- Click "Run workflow"
Verification¶
After publishing, you can verify the package is available:
- Check PyPI: https://pypi.org/project/python-gitignore/
- Install the package:
pip install python-gitignore - Test the CLI:
gi --help
Troubleshooting¶
Common Issues¶
- "Package already exists"
- Make sure the version number in
pyproject.tomlis unique -
Check if the version was already published
-
"Authentication failed"
- Verify the PyPI API token is correct
-
Check that the token has the right permissions
-
"Trusted publishing failed"
- Ensure the workflow file name matches exactly
- Check that the environment name is
pypi - Verify the repository name and owner are correct
Debug Steps¶
- Check workflow logs in GitHub Actions
- Verify package metadata in
pyproject.toml - Test locally:
Security Best Practices¶
- Use trusted publishing instead of API tokens when possible
- Never commit API tokens to the repository
- Use environment-specific secrets for different PyPI accounts
- Regularly rotate API tokens if using token-based authentication
Package Information¶
- Package name:
python-gitignore - PyPI URL: https://pypi.org/project/python-gitignore/
- Installation:
pip install python-gitignore - CLI command:
gi
Release Checklist¶
Before publishing a new version:
- Update version in
pyproject.toml - Update version in
gi/__init__.py - Run tests:
python -m pytest - Run linting:
uv run ruff check - Test build locally:
python -m build - Create GitHub release with proper tag
- Verify publication on PyPI
- Test installation:
pip install python-gitignore