mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-07-07 14:45:00 +00:00

- Update publish.yml to create PR after publishing - Add create-release-tag.yml to tag releases when PR merges - Eliminates manual version syncing between repo and PyPI
153 lines
No EOL
4.5 KiB
YAML
153 lines
No EOL
4.5 KiB
YAML
name: Publish to PyPI
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'Version to publish (e.g., 0.1.0)'
|
|
required: true
|
|
type: string
|
|
test_pypi:
|
|
description: 'Publish to Test PyPI first'
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
|
|
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: Update version
|
|
run: |
|
|
# Update version in pyproject.toml
|
|
sed -i 's/version = ".*"/version = "${{ github.event.inputs.version }}"/' pyproject.toml
|
|
sed -i 's/__version__ = ".*"/__version__ = "${{ github.event.inputs.version }}"/' src/claude_code_sdk/__init__.py
|
|
|
|
- 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 Test PyPI
|
|
if: ${{ github.event.inputs.test_pypi == 'true' }}
|
|
env:
|
|
TWINE_USERNAME: __token__
|
|
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
|
run: |
|
|
twine upload --repository testpypi dist/*
|
|
echo "Package published to Test PyPI"
|
|
echo "Install with: pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ claude-code-sdk==${{ github.event.inputs.version }}"
|
|
|
|
- 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-code-sdk==${{ github.event.inputs.version }}"
|
|
|
|
- name: Create version update PR
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
# Create a new branch for the version update
|
|
BRANCH_NAME="release/v${{ github.event.inputs.version }}"
|
|
git checkout -b "$BRANCH_NAME"
|
|
|
|
# Configure git
|
|
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
|
git config --local user.name "github-actions[bot]"
|
|
|
|
# Commit the version changes
|
|
git add pyproject.toml src/claude_code_sdk/__init__.py
|
|
git commit -m "chore: bump version to ${{ github.event.inputs.version }}"
|
|
|
|
# Push the branch
|
|
git push origin "$BRANCH_NAME"
|
|
|
|
# Create PR using GitHub CLI (gh)
|
|
gh pr create \
|
|
--title "chore: bump version to ${{ github.event.inputs.version }}" \
|
|
--body "This PR updates the version to ${{ github.event.inputs.version }} after publishing to PyPI.
|
|
|
|
## Changes
|
|
- Updated version in \`pyproject.toml\`
|
|
- Updated version in \`src/claude_code_sdk/__init__.py\`
|
|
|
|
## Release Information
|
|
- Published to PyPI: https://pypi.org/project/claude-code-sdk/${{ github.event.inputs.version }}/
|
|
- Install with: \`pip install claude-code-sdk==${{ github.event.inputs.version }}\`
|
|
|
|
## Next Steps
|
|
After merging this PR, a release tag will be created automatically." \
|
|
--base main \
|
|
--head "$BRANCH_NAME" |