Skip to content

Commit 8206eca

Browse files
authored
Add GitHub Actions workflow for PyPi publishing
This workflow allows manual triggering to publish a package to PyPi from a specified branch or tag.
1 parent 40499bf commit 8206eca

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

.github/workflows/pypi-publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish package to PyPi
2+
3+
on:
4+
# CHANGED: This allows you to manually run the workflow from the
5+
# GitHub Actions tab (click 'Run workflow').
6+
workflow_dispatch:
7+
inputs:
8+
branch:
9+
description: 'Branch or tag to build from (e.g., main or v1.0.0)'
10+
required: true
11+
default: 'main'
12+
13+
jobs:
14+
push:
15+
runs-on: ubuntu-latest
16+
17+
# 1. SECURITY: Add permissions for OIDC token generation
18+
permissions:
19+
id-token: write # Grants permission to exchange a token with PyPI
20+
contents: read # Allows checkout of the repository
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v5
25+
with:
26+
# Use the branch/tag provided in the manual input
27+
ref: ${{ github.event.inputs.branch }}
28+
29+
- name: Setup Python
30+
uses: actions/setup-python@v5
31+
with:
32+
# Use a stable, specific version
33+
python-version: 3.11
34+
35+
- name: Build package
36+
# Install the 'build' tool and then run it to create the sdist and wheel.
37+
run: |
38+
python -m pip install --upgrade pip
39+
python -m pip install build
40+
python -m build
41+
42+
# 2. SECURITY: Publish to PyPi (using Trusted Publisher)
43+
- name: Publish to PyPi (using Trusted Publisher)
44+
uses: pypa/gh-action-pypi-publish@release/v1
45+
# No manual secrets are needed!

0 commit comments

Comments
 (0)