Skip to content

Commit daa9f2e

Browse files
committed
Add GitHub Actions workflows for PyPI publishing
- Add trusted publisher workflow for PyPI releases - Add test workflow for TestPyPI - Add publishing documentation
1 parent 1f3c97b commit daa9f2e

3 files changed

Lines changed: 145 additions & 0 deletions

File tree

.github/PUBLISHING.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Publishing Setup
2+
3+
This project uses GitHub Actions with PyPI's trusted publishers for secure, automated publishing.
4+
5+
## Setup Instructions
6+
7+
### 1. Configure PyPI Trusted Publisher
8+
9+
Go to https://pypi.org/manage/project/googleapiutils2/settings/publishing/ and add a new GitHub publisher:
10+
11+
- **Owner**: mkbabb (or your GitHub username/org)
12+
- **Repository name**: googleapiutils2
13+
- **Workflow name**: publish.yml
14+
- **Environment name**: release (recommended for security)
15+
16+
### 2. Configure TestPyPI Trusted Publisher (Optional)
17+
18+
For testing, configure the same on https://test.pypi.org/:
19+
20+
- **Owner**: mkbabb
21+
- **Repository name**: googleapiutils2
22+
- **Workflow name**: test-publish.yml
23+
- **Environment name**: (leave empty for test)
24+
25+
### 3. Create GitHub Environment (Recommended)
26+
27+
In your GitHub repository settings:
28+
29+
1. Go to Settings → Environments
30+
2. Create a new environment called "release"
31+
3. Add protection rules:
32+
- Required reviewers (optional)
33+
- Restrict deployment branches to main/master
34+
35+
## Usage
36+
37+
### Automatic Publishing
38+
39+
1. Create a new release on GitHub
40+
2. The workflow will automatically:
41+
- Build the package with UV
42+
- Publish to PyPI using trusted publishing
43+
44+
### Manual Publishing
45+
46+
Run the workflow manually from Actions tab → Publish to PyPI → Run workflow
47+
48+
### Test Publishing
49+
50+
Every push to master/main automatically publishes to TestPyPI for testing.
51+
52+
## Local Publishing (Emergency Only)
53+
54+
If GitHub Actions fails, you can publish locally:
55+
56+
```bash
57+
# Build
58+
uv build
59+
60+
# Publish with API token
61+
uv publish --token <your-token>
62+
```
63+
64+
## Benefits of Trusted Publishing
65+
66+
- No API tokens stored in GitHub secrets
67+
- Automatic OIDC authentication
68+
- More secure than password/token auth
69+
- Audit trail in both GitHub and PyPI

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
publish:
10+
name: Publish to PyPI
11+
runs-on: ubuntu-latest
12+
environment: release
13+
permissions:
14+
id-token: write # Required for trusted publishing
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v3
26+
with:
27+
enable-cache: true
28+
29+
- name: Build package
30+
run: uv build
31+
32+
- name: Publish to PyPI
33+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test-publish.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test Publish to TestPyPI
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test-publish:
12+
name: Test Publish to TestPyPI
13+
runs-on: ubuntu-latest
14+
permissions:
15+
id-token: write # Required for trusted publishing
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.12'
24+
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v3
27+
with:
28+
enable-cache: true
29+
30+
- name: Install dependencies
31+
run: uv sync
32+
33+
- name: Run tests
34+
run: uv run pytest
35+
continue-on-error: true # Don't fail if no tests
36+
37+
- name: Build package
38+
run: uv build
39+
40+
- name: Publish to TestPyPI
41+
uses: pypa/gh-action-pypi-publish@release/v1
42+
with:
43+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)