From 69ec88d6a01ded86dae94ddc2fb607271c34d1ba Mon Sep 17 00:00:00 2001 From: Dickson Tsai Date: Mon, 21 Jul 2025 09:30:02 -0700 Subject: [PATCH 1/5] Improve version update workflow --- .github/workflows/publish.yml | 66 ++++++++++++++++------------------- scripts/update_version.py | 49 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 35 deletions(-) create mode 100755 scripts/update_version.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1822a896..997202ba 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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.15' # TESTING ONLY - REMOVE BEFORE MERGE jobs: test: runs-on: ubuntu-latest @@ -79,11 +76,16 @@ jobs: with: python-version: '3.12' + - name: Set version + id: version + run: | + VERSION="${{ github.event.inputs.version || '0.0.15' }}" # TESTING ONLY - defaults to 0.0.15 + 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: | @@ -96,16 +98,6 @@ 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__ @@ -113,14 +105,14 @@ jobs: 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 @@ -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] " # 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" \ No newline at end of file diff --git a/scripts/update_version.py b/scripts/update_version.py new file mode 100755 index 00000000..9d92a817 --- /dev/null +++ b/scripts/update_version.py @@ -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 ") + sys.exit(1) + + update_version(sys.argv[1]) \ No newline at end of file From 4eb3a1f955d0b65b8ae40ca3e8b2ba138de75e96 Mon Sep 17 00:00:00 2001 From: Dickson Tsai Date: Mon, 21 Jul 2025 09:32:22 -0700 Subject: [PATCH 2/5] Update test version --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 997202ba..1ea8ed28 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,7 @@ on: description: 'Version to publish (e.g., 0.1.0)' required: true type: string - default: '0.0.15' # TESTING ONLY - REMOVE BEFORE MERGE + default: '0.0.0.dev20250121' # TESTING ONLY - REMOVE BEFORE MERGE jobs: test: runs-on: ubuntu-latest @@ -79,7 +79,7 @@ jobs: - name: Set version id: version run: | - VERSION="${{ github.event.inputs.version || '0.0.15' }}" # TESTING ONLY - defaults to 0.0.15 + 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 From 5c120a30ff0d4f564084493144134e73a8f79cec Mon Sep 17 00:00:00 2001 From: Dickson Tsai Date: Mon, 21 Jul 2025 09:39:49 -0700 Subject: [PATCH 3/5] Try again --- .github/workflows/publish.yml | 67 +++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1ea8ed28..bf5b9c4f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,7 @@ on: description: 'Version to publish (e.g., 0.1.0)' required: true type: string - default: '0.0.0.dev20250121' # TESTING ONLY - REMOVE BEFORE MERGE + default: '0.0.0.dev20250721' # TESTING ONLY - REMOVE BEFORE MERGE jobs: test: runs-on: ubuntu-latest @@ -79,7 +79,7 @@ jobs: - name: Set version id: version run: | - VERSION="${{ github.event.inputs.version || '0.0.0.dev20250121' }}" # TESTING ONLY - defaults to test version + VERSION="${{ github.event.inputs.version || '0.0.0.dev20250721' }}" # TESTING ONLY - defaults to test version echo "VERSION=$VERSION" >> $GITHUB_ENV echo "version=$VERSION" >> $GITHUB_OUTPUT @@ -109,21 +109,49 @@ jobs: - name: Create version update PR env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Create a new branch for the version update BRANCH_NAME="release/v${{ env.VERSION }}" - git checkout -b "$BRANCH_NAME" + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV - # Configure git - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" + # 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" - # Commit the version changes - git add pyproject.toml src/claude_code_sdk/__init__.py - git commit -m "chore: bump version to ${{ env.VERSION }} + # 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 __init__.py" + INIT_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/__init__.py --jq '.sha') - This PR updates the version to ${{ env.VERSION }} after publishing to PyPI. + # 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 __init__.py via GitHub API + base64 -i src/claude_code_sdk/__init__.py > init.py.b64 + gh api \ + --method PUT \ + /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/__init__.py \ + -f message="$message" \ + -F content=@init.py.b64 \ + -f sha="$INIT_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\` @@ -133,17 +161,12 @@ jobs: - 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] " + 🤖 Generated by GitHub Actions" - # Push the branch - git push origin "$BRANCH_NAME" - - # Create PR using GitHub CLI (gh) - gh pr create \ + PR_URL=$(gh pr create \ --title "chore: bump version to ${{ env.VERSION }}" \ - --body "Automated PR to update version after PyPI release." \ + --body "$PR_BODY" \ --base main \ - --head "$BRANCH_NAME" \ No newline at end of file + --head "$BRANCH_NAME") + + echo "PR created: $PR_URL" \ No newline at end of file From 8f3dd3f6c02467b23d8ee24fd4cd8f8b63a40832 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 16:40:39 +0000 Subject: [PATCH 4/5] chore: bump version to 0.0.0.dev20250721 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index cb270fb3..d53fbc27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "claude-code-sdk" -version = "0.0.14" +version = "0.0.0.dev20250721" description = "Python SDK for Claude Code" readme = "README.md" requires-python = ">=3.10" From 1b135a890d46603711a7adcd6af72a05fac84f20 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 16:40:40 +0000 Subject: [PATCH 5/5] chore: bump version to 0.0.0.dev20250721 --- src/claude_code_sdk/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/claude_code_sdk/__init__.py b/src/claude_code_sdk/__init__.py index 1439937a..c9c7028a 100644 --- a/src/claude_code_sdk/__init__.py +++ b/src/claude_code_sdk/__init__.py @@ -24,7 +24,7 @@ UserMessage, ) -__version__ = "0.0.14" +__version__ = "0.0.0.dev20250721" __all__ = [ # Main exports