Skip to content

Publish to PyPI

Publish to PyPI #18

Workflow file for this run

name: Publish to PyPI
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g., v0.8.0 or 0.8.0)'
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: Normalize version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
TAG="${{ github.event.release.tag_name }}"
else
TAG="${{ inputs.version }}"
fi
# Ensure tag has v prefix
TAG_VERSION="${TAG#v}"
TAG_VERSION="v${TAG_VERSION}"
# Bare version for pyproject.toml comparison
BARE_VERSION="${TAG_VERSION#v}"
echo "tag=${TAG_VERSION}" >> "$GITHUB_OUTPUT"
echo "bare=${BARE_VERSION}" >> "$GITHUB_OUTPUT"
echo "Publishing version: ${TAG_VERSION} (${BARE_VERSION})"
- uses: actions/checkout@v4
with:
ref: ${{ steps.version.outputs.tag }}
- uses: astral-sh/setup-uv@v4
- name: Verify version matches pyproject.toml
run: |
TOML_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
if [ "$TOML_VERSION" != "${{ steps.version.outputs.bare }}" ]; then
echo "Error: Tag version (${{ steps.version.outputs.bare }}) doesn't match pyproject.toml ($TOML_VERSION)"
exit 1
fi
working-directory: python
- name: Build
run: uv build
working-directory: python
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python/dist/