Skip to content

Release to PyPI

Release to PyPI #2

Workflow file for this run

name: Release to PyPI
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Version to release (leave empty to use pyproject.toml version)"
required: false
type: string
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --all-extras
- name: Run tests
run: uv run pytest --tb=short --ignore=tests/integration
build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.13
- name: Update version from release tag
if: github.event_name == 'release'
run: |
VERSION="${GITHUB_REF#refs/tags/v}"
sed -i "s|^version = .*|version = \"$VERSION\"|" pyproject.toml
echo "Building version: $VERSION"
- name: Update version from input
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
run: |
VERSION="${{ github.event.inputs.version }}"
sed -i "s|^version = .*|version = \"$VERSION\"|" pyproject.toml
echo "Building version: $VERSION"
- name: Build package
run: uv build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish-testpypi:
needs: build
runs-on: ubuntu-latest
environment: testpypi
permissions:
id-token: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
publish-pypi:
needs: publish-testpypi
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1