Skip to content

Commit cce8e5f

Browse files
committed
Add GitHub Actions workflows for PyPI publishing
1 parent f58cc3b commit cce8e5f

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

.github/workflows/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# GitHub Actions Workflows for PyPI Publishing
2+
3+
This directory contains GitHub Actions workflows for automatically publishing the diffrays package to PyPI.
4+
5+
## Workflows
6+
7+
### 1. `publish.yml` - Production PyPI Publishing
8+
- **Triggers**:
9+
- When a GitHub release is published
10+
- Manual trigger via GitHub Actions UI
11+
- **Purpose**: Publishes the package to the official PyPI repository
12+
- **Required Secret**: `PYPI_API_TOKEN`
13+
14+
### 2. `testpypi.yml` - TestPyPI Publishing
15+
- **Triggers**:
16+
- Push to `main` or `develop` branches
17+
- Manual trigger via GitHub Actions UI
18+
- **Purpose**: Publishes the package to TestPyPI for testing
19+
- **Required Secret**: `TEST_PYPI_API_TOKEN`
20+
21+
## Setup Instructions
22+
23+
### For Production PyPI Publishing:
24+
25+
1. **Create PyPI API Token**:
26+
- Go to [PyPI](https://pypi.org) and log in
27+
- Navigate to Account Settings → API tokens
28+
- Create a new API token (scope: "Entire account" or project-specific)
29+
- Copy the token (starts with `pypi-`)
30+
31+
2. **Add GitHub Secret**:
32+
- Go to your GitHub repository
33+
- Settings → Secrets and variables → Actions
34+
- Click "New repository secret"
35+
- Name: `PYPI_API_TOKEN`
36+
- Value: Your PyPI API token
37+
38+
3. **Publishing Process**:
39+
- Update version in `pyproject.toml`
40+
- Commit and push changes
41+
- Create a GitHub release with the same version number
42+
- The workflow will automatically publish to PyPI
43+
44+
### For TestPyPI Publishing:
45+
46+
1. **Create TestPyPI Account**:
47+
- Go to [test.pypi.org](https://test.pypi.org)
48+
- Create an account (can be same as PyPI account)
49+
50+
2. **Create TestPyPI API Token**:
51+
- Log in to TestPyPI
52+
- Go to Account Settings → API tokens
53+
- Create a new API token
54+
- Copy the token
55+
56+
3. **Add GitHub Secret**:
57+
- Add `TEST_PYPI_API_TOKEN` secret in GitHub repository settings
58+
- Value: Your TestPyPI API token
59+
60+
## Usage
61+
62+
### Manual Publishing
63+
Both workflows support manual triggering:
64+
1. Go to GitHub repository → Actions tab
65+
2. Select the desired workflow
66+
3. Click "Run workflow"
67+
68+
### Version Management
69+
- Update the version in `pyproject.toml` before creating a release
70+
- The version in the release tag should match the version in `pyproject.toml`
71+
- Example: If `pyproject.toml` has `version = "1.6"`, create a release with tag `v1.6`
72+
73+
## Security Notes
74+
- Never commit API tokens to the repository
75+
- Use repository secrets for storing sensitive information
76+
- API tokens provide better security than username/password authentication

.github/workflows/publish.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch: # Allows manual triggering
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.8'
19+
20+
- name: Install build dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install build twine
24+
25+
- name: Build package
26+
run: python -m build
27+
28+
- name: Check package
29+
run: twine check dist/*
30+
31+
- name: Publish to PyPI
32+
env:
33+
TWINE_USERNAME: __token__
34+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
35+
run: twine upload dist/*

.github/workflows/testpypi.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Publish to TestPyPI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.8'
19+
20+
- name: Install build dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install build twine
24+
25+
- name: Build package
26+
run: python -m build
27+
28+
- name: Check package
29+
run: twine check dist/*
30+
31+
- name: Publish to TestPyPI
32+
env:
33+
TWINE_USERNAME: __token__
34+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
35+
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
36+
run: twine upload dist/*

0 commit comments

Comments
 (0)