Skip to content

Publish to PyPI

Publish to PyPI #10

Workflow file for this run

name: Publish to PyPI
on:
push:
tags:
- "v*.*.*"
permissions:
contents: read
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false
jobs:
test:
name: Test
runs-on: blacksmith-4vcpu-ubuntu-2404
strategy:
matrix:
python-version: ["3.11", "3.12"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install dspy-cli with dev dependencies
run: uv sync --extra dev
- name: Lint with ruff
run: uv run ruff check .
- name: Verify tag matches pyproject version
if: matrix.python-version == '3.11'
run: |
python - << 'PY'
import os, sys
tag = os.environ["GITHUB_REF_NAME"]
if not tag.startswith("v"):
print(f"Unexpected tag format: {tag}", file=sys.stderr)
sys.exit(1)
tag_ver = tag[1:] # Strip 'v' prefix
import tomllib
with open("pyproject.toml", "rb") as f:
data = tomllib.load(f)
proj_ver = data["project"]["version"]
if proj_ver != tag_ver:
print(f"❌ Version mismatch: pyproject.toml={proj_ver} tag={tag_ver}", file=sys.stderr)
sys.exit(1)
print(f"✅ Version verified: {proj_ver}")
PY
- name: Run tests
env:
PYTEST_ADDOPTS: -v
run: uv run pytest
build:
name: Build distributions
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
run: uv python install 3.11
- name: Build sdist and wheel
run: uv build
- name: Smoke test (wheel)
run: uv run --isolated --no-project --with dist/*.whl tests/smoke_test.py
- name: Smoke test (source distribution)
run: uv run --isolated --no-project --with dist/*.tar.gz tests/smoke_test.py
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: dist-${{ github.ref_name }}
path: dist/
if-no-files-found: error
publish:
name: Publish to PyPI
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [build]
environment:
name: pypi
url: https://pypi.org/project/dspy-cli/
permissions:
id-token: write
contents: read
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: dist-${{ github.ref_name }}
path: dist
- name: Publish
run: uv publish