Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 31 additions & 35 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
name: Publish to PyPI

on:
push:
branches: [dickson/version-bump] # TESTING ONLY - REMOVE BEFORE MERGE
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

default: '0.0.0.dev20250121' # TESTING ONLY - REMOVE BEFORE MERGE
jobs:
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -79,11 +76,16 @@ jobs:
with:
python-version: '3.12'

- name: Set version
id: version
run: |
VERSION="${{ github.event.inputs.version || '0.0.0.dev20250121' }}" # TESTING ONLY - defaults to test version
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT

- 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
python scripts/update_version.py "${{ env.VERSION }}"

- name: Install build dependencies
run: |
Expand All @@ -96,31 +98,21 @@ jobs:
- 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 }}"
echo "Install with: pip install claude-code-sdk==${{ env.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 }}"
BRANCH_NAME="release/v${{ env.VERSION }}"
git checkout -b "$BRANCH_NAME"

# Configure git
Expand All @@ -129,25 +121,29 @@ jobs:

# 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 }}"
git commit -m "chore: bump version to ${{ env.VERSION }}

This PR updates the version to ${{ env.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/${{ env.VERSION }}/
- Install with: \`pip install claude-code-sdk==${{ env.VERSION }}\`

## Next Steps
After merging this PR, a release tag will be created automatically.

Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"

# 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." \
--title "chore: bump version to ${{ env.VERSION }}" \
--body "Automated PR to update version after PyPI release." \
--base main \
--head "$BRANCH_NAME"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "claude-code-sdk"
version = "0.0.14"
version = "0.0.0.dev20250121"
description = "Python SDK for Claude Code"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
49 changes: 49 additions & 0 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
"""Update version in pyproject.toml and __init__.py files."""

import sys
import re
from pathlib import Path


def update_version(new_version: str) -> None:
"""Update version in project files."""
# Update pyproject.toml
pyproject_path = Path("pyproject.toml")
content = pyproject_path.read_text()

# Only update the version field in [project] section
content = re.sub(
r'^version = "[^"]*"',
f'version = "{new_version}"',
content,
count=1,
flags=re.MULTILINE
)

pyproject_path.write_text(content)
print(f"Updated pyproject.toml to version {new_version}")

# Update __init__.py
init_path = Path("src/claude_code_sdk/__init__.py")
content = init_path.read_text()

# Only update __version__ assignment
content = re.sub(
r'^__version__ = "[^"]*"',
f'__version__ = "{new_version}"',
content,
count=1,
flags=re.MULTILINE
)

init_path.write_text(content)
print(f"Updated __init__.py to version {new_version}")


if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python scripts/update_version.py <version>")
sys.exit(1)

update_version(sys.argv[1])
2 changes: 1 addition & 1 deletion src/claude_code_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
UserMessage,
)

__version__ = "0.0.14"
__version__ = "0.0.0.dev20250121"

__all__ = [
# Main exports
Expand Down