Skip to content

0.1.0

0.1.0 #1

Workflow file for this run

name: Publish Python Package
# 1. Trigger the workflow when a new GitHub Release is published
on:
release:
types: [published]
jobs:
build_sdist_and_wheel:
name: Build distribution 📦
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
# Install the 'build' tool, which creates the distribution files
- name: Install build dependencies
run: python -m pip install build
# Create source and wheel distribution archives in the 'dist/' directory
- name: Build distributions
run: python -m build
# Store the built artifacts for the next jobs to download
- name: Upload distribution artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
# --- PyPI Release Job (Secure, using OIDC) ---
pypi_publish:
name: Publish to PyPI
needs: [build_sdist_and_wheel] # Ensure the build job succeeds first
runs-on: ubuntu-latest
# 2. Use the environment name you configured in PyPI (Optional, but recommended)
environment: pypi
# 3. CRITICAL: This is the mandatory permission for Trusted Publishers (OIDC)
permissions:
id-token: write
contents: read # Required to read the repository contents
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
# 4. The PyPA action handles the OIDC token exchange and Twine upload securely
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# --- TestPyPI Release Job (Optional, for pre-release testing) ---
testpypi_publish:
name: Publish to TestPyPI
needs: [build_sdist_and_wheel]
runs-on: ubuntu-latest
# Use the environment name you configured in TestPyPI
environment: testpypi
permissions:
id-token: write
contents: read
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
# The 'repository-url' is what makes this target TestPyPI
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/