1+ # .github/workflows/publish-to-pypi.yml
2+
3+ name : Publish Python Package to PyPI
4+
5+ # Run this workflow only when a new release is published on GitHub
6+ on :
7+ release :
8+ types : [ published ] # Triggers when you click "Publish release"
9+
10+ permissions :
11+ contents : read # Needed to check out the repository
12+
13+ jobs :
14+ deploy :
15+ name : Build and publish to PyPI
16+ runs-on : ubuntu-latest # Use the latest Ubuntu runner
17+
18+ steps :
19+ - name : Checkout repository
20+ uses : actions/checkout@v4 # Checks out your code
21+
22+ - name : Set up Python
23+ uses : actions/setup-python@v4
24+ with :
25+ python-version : ' 3.10' # Choose a Python version
26+
27+ - name : Install dependencies
28+ run : |
29+ python -m pip install --upgrade pip
30+ pip install build twine # Install build tools
31+
32+ - name : Build package
33+ run : python -m build # Build the sdist and wheel
34+
35+ - name : Publish package to PyPI
36+ # Use the trusted publisher mechanism if configured on PyPI,
37+ # otherwise fallback to using the API token.
38+ # For simplicity here, we are using the API token method.
39+ # See: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
40+ uses : pypa/gh-action-pypi-publish@release/v1
41+ with :
42+ user : __token__
43+ password : ${{ secrets.PYPI_API_TOKEN }} # Use the secret you created!
44+ # repository-url: https://test.pypi.org/legacy/ # Uncomment for testing on TestPyPI
45+ # skip-existing: true # Optional: prevents errors if version already exists
0 commit comments