Skip to content

Commit be41b13

Browse files
authored
feat: add secure PyPI publishing workflow (#17)
Adds a GitHub Actions workflow to securely publish the Python package to PyPI using Trusted Publishing (OIDC). This workflow is triggered on new GitHub releases and handles building and publishing the package without the need for long-lived API tokens.
1 parent 539360a commit be41b13

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# .github/workflows/publish.yml
2+
name: Publish Python Package to PyPI
3+
4+
on:
5+
# Trigger the workflow only when a new release is published
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
pypi-publish:
11+
name: Upload release to PyPI
12+
runs-on: ubuntu-latest
13+
14+
# Define the environment for trusted publishing
15+
# This name 'pypi' MUST match what you configure on PyPI
16+
environment: pypi
17+
18+
# Grant OIDC token permission for the job
19+
permissions:
20+
id-token: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.x"
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install build
35+
36+
- name: Build package
37+
run: python -m build
38+
39+
- name: Publish package to PyPI
40+
uses: pypa/gh-action-pypi-publish@release/v1
41+
# No 'user' or 'password' fields are needed here.
42+
# The action automatically uses the OIDC token from the
43+
# 'id-token: write' permission.

0 commit comments

Comments
 (0)