Files
2025-09-28 14:52:53 -07:00

169 lines
4.7 KiB
YAML

name: Publish to PyPI
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 0.1.0)'
required: true
type: string
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run tests
run: |
python -m pytest tests/ -v
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run ruff
run: |
ruff check src/ tests/
ruff format --check src/ tests/
- name: Run mypy
run: |
mypy src/
publish:
needs: [test, lint]
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set version
id: version
run: |
VERSION="${{ github.event.inputs.version }}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Update version
run: |
python scripts/update_version.py "${{ env.VERSION }}"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: python -m build
- name: Check package
run: twine check dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
echo "Package published to PyPI"
echo "Install with: pip install claude-agent-sdk==${{ env.VERSION }}"
- name: Create version update PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create a new branch for the version update
BRANCH_NAME="release/v${{ env.VERSION }}"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
# Create branch via API
BASE_SHA=$(git rev-parse HEAD)
gh api \
--method POST \
/repos/$GITHUB_REPOSITORY/git/refs \
-f ref="refs/heads/$BRANCH_NAME" \
-f sha="$BASE_SHA"
# Get current SHA values of files
echo "Getting SHA for pyproject.toml"
PYPROJECT_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/pyproject.toml --jq '.sha')
echo "Getting SHA for _version.py"
VERSION_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/src/claude_agent_sdk/_version.py --jq '.sha')
# Commit pyproject.toml via GitHub API (this creates signed commits)
message="chore: bump version to ${{ env.VERSION }}"
base64 -i pyproject.toml > pyproject.toml.b64
gh api \
--method PUT \
/repos/$GITHUB_REPOSITORY/contents/pyproject.toml \
-f message="$message" \
-F content=@pyproject.toml.b64 \
-f sha="$PYPROJECT_SHA" \
-f branch="$BRANCH_NAME"
# Commit _version.py via GitHub API
base64 -i src/claude_agent_sdk/_version.py > version.py.b64
gh api \
--method PUT \
/repos/$GITHUB_REPOSITORY/contents/src/claude_agent_sdk/_version.py \
-f message="$message" \
-F content=@version.py.b64 \
-f sha="$VERSION_SHA" \
-f branch="$BRANCH_NAME"
# Create PR using GitHub CLI
PR_BODY="This PR updates the version to ${{ env.VERSION }} after publishing to PyPI.
## Changes
- Updated version in \`pyproject.toml\`
- Updated version in \`src/claude_agent_sdk/_version.py\`
## Release Information
- Published to PyPI: https://pypi.org/project/claude-agent-sdk/${{ env.VERSION }}/
- Install with: \`pip install claude-agent-sdk==${{ env.VERSION }}\`
🤖 Generated by GitHub Actions"
PR_URL=$(gh pr create \
--title "chore: bump version to ${{ env.VERSION }}" \
--body "$PR_BODY" \
--base main \
--head "$BRANCH_NAME")
echo "PR created: $PR_URL"