Skip to content

Build and Publish Python 🐍📦 #4

Build and Publish Python 🐍📦

Build and Publish Python 🐍📦 #4

# GitHub Actions workflow to build and publish to PyPI
name: Build and Publish Python 🐍📦
on:
release:
types:
- published
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
- name: Publish to TestPyPI (optional)
if: github.ref_type == 'branch' && github.ref_name == 'main'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
twine upload --repository testpypi dist/*