Skip to content

Commit 378605e

Browse files
committed
Fix publishing to pypi
1 parent bd11a74 commit 378605e

2 files changed

Lines changed: 46 additions & 7 deletions

File tree

.github/workflows/publish_pypi.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ on:
88
jobs:
99
build-and-publish:
1010
runs-on: ubuntu-latest
11+
environment:
12+
name: pypi
13+
url: https://pypi.org/project/template-python/
14+
permissions:
15+
id-token: write
16+
contents: read
1117

1218
steps:
1319
- name: Checkout repository
@@ -21,14 +27,10 @@ jobs:
2127
- name: Install build tools
2228
run: |
2329
python -m pip install --upgrade pip
24-
pip install build twine
30+
pip install build
2531
2632
- name: Build the package
2733
run: python -m build
2834

29-
# Uncomment to publish on pypi
30-
#- name: Publish to PyPI
31-
# env:
32-
# TWINE_USERNAME: __token__ # Use API token
33-
# TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
34-
# run: twine upload dist/*
35+
- name: Publish package distributions to PyPI
36+
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,40 @@ make html
3434
cd ../
3535
open docs/_build/html/index.html
3636
```
37+
38+
# Publishing on PyPI
39+
40+
This project is configured to automatically publish to PyPI using GitHub Actions with trusted publishing (OIDC).
41+
42+
## Setup (One-time configuration)
43+
44+
### 1. Create PyPI Account and Project
45+
46+
1. Create an account on [PyPI](https://pypi.org/)
47+
2. Create a new project or claim your project name
48+
49+
### 2. Configure Trusted Publishing on PyPI
50+
51+
1. Go to your PyPI project settings
52+
2. Navigate to "Publishing" → "Add a new publisher"
53+
3. Configure the trusted publisher with these details:
54+
- **PyPI Project Name**: `template-python` (or your project name)
55+
- **Owner**: Your GitHub username/organization
56+
- **Repository name**: `template-python`
57+
- **Workflow name**: `publish_pypi.yml`
58+
- **Environment name**: `pypi`
59+
60+
### 3. Configure GitHub Environment (Optional but Recommended)
61+
62+
1. Go to your GitHub repository → Settings → Environments
63+
2. Create an environment named `pypi`
64+
3. Add protection rules:
65+
- Deployment branches: Only `main` branch
66+
67+
## Publishing Process
68+
69+
Once configured, publishing is automatic:
70+
71+
1. **Merge to main branch**: Any push to the `main` branch triggers the workflow
72+
2. **Automatic build**: The workflow builds the Python package
73+
3. **Automatic publish**: The package is automatically published to PyPI using trusted publishing

0 commit comments

Comments
 (0)