Skip to content

Commit 69ec88d

Browse files
committed
Improve version update workflow
1 parent c4384ea commit 69ec88d

2 files changed

Lines changed: 80 additions & 35 deletions

File tree

.github/workflows/publish.yml

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
name: Publish to PyPI
22

33
on:
4+
push:
5+
branches: [dickson/version-bump] # TESTING ONLY - REMOVE BEFORE MERGE
46
workflow_dispatch:
57
inputs:
68
version:
79
description: 'Version to publish (e.g., 0.1.0)'
810
required: true
911
type: string
10-
test_pypi:
11-
description: 'Publish to Test PyPI first'
12-
required: false
13-
type: boolean
14-
default: true
15-
12+
default: '0.0.15' # TESTING ONLY - REMOVE BEFORE MERGE
1613
jobs:
1714
test:
1815
runs-on: ubuntu-latest
@@ -79,11 +76,16 @@ jobs:
7976
with:
8077
python-version: '3.12'
8178

79+
- name: Set version
80+
id: version
81+
run: |
82+
VERSION="${{ github.event.inputs.version || '0.0.15' }}" # TESTING ONLY - defaults to 0.0.15
83+
echo "VERSION=$VERSION" >> $GITHUB_ENV
84+
echo "version=$VERSION" >> $GITHUB_OUTPUT
85+
8286
- name: Update version
8387
run: |
84-
# Update version in pyproject.toml
85-
sed -i 's/version = ".*"/version = "${{ github.event.inputs.version }}"/' pyproject.toml
86-
sed -i 's/__version__ = ".*"/__version__ = "${{ github.event.inputs.version }}"/' src/claude_code_sdk/__init__.py
88+
python scripts/update_version.py "${{ env.VERSION }}"
8789
8890
- name: Install build dependencies
8991
run: |
@@ -96,31 +98,21 @@ jobs:
9698
- name: Check package
9799
run: twine check dist/*
98100

99-
- name: Publish to Test PyPI
100-
if: ${{ github.event.inputs.test_pypi == 'true' }}
101-
env:
102-
TWINE_USERNAME: __token__
103-
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
104-
run: |
105-
twine upload --repository testpypi dist/*
106-
echo "Package published to Test PyPI"
107-
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 }}"
108-
109101
- name: Publish to PyPI
110102
env:
111103
TWINE_USERNAME: __token__
112104
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
113105
run: |
114106
twine upload dist/*
115107
echo "Package published to PyPI"
116-
echo "Install with: pip install claude-code-sdk==${{ github.event.inputs.version }}"
108+
echo "Install with: pip install claude-code-sdk==${{ env.VERSION }}"
117109
118110
- name: Create version update PR
119111
env:
120112
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121113
run: |
122114
# Create a new branch for the version update
123-
BRANCH_NAME="release/v${{ github.event.inputs.version }}"
115+
BRANCH_NAME="release/v${{ env.VERSION }}"
124116
git checkout -b "$BRANCH_NAME"
125117
126118
# Configure git
@@ -129,25 +121,29 @@ jobs:
129121
130122
# Commit the version changes
131123
git add pyproject.toml src/claude_code_sdk/__init__.py
132-
git commit -m "chore: bump version to ${{ github.event.inputs.version }}"
124+
git commit -m "chore: bump version to ${{ env.VERSION }}
125+
126+
This PR updates the version to ${{ env.VERSION }} after publishing to PyPI.
127+
128+
## Changes
129+
- Updated version in \`pyproject.toml\`
130+
- Updated version in \`src/claude_code_sdk/__init__.py\`
131+
132+
## Release Information
133+
- Published to PyPI: https://pypi.org/project/claude-code-sdk/${{ env.VERSION }}/
134+
- Install with: \`pip install claude-code-sdk==${{ env.VERSION }}\`
135+
136+
## Next Steps
137+
After merging this PR, a release tag will be created automatically.
138+
139+
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
133140
134141
# Push the branch
135142
git push origin "$BRANCH_NAME"
136143
137144
# Create PR using GitHub CLI (gh)
138145
gh pr create \
139-
--title "chore: bump version to ${{ github.event.inputs.version }}" \
140-
--body "This PR updates the version to ${{ github.event.inputs.version }} after publishing to PyPI.
141-
142-
## Changes
143-
- Updated version in \`pyproject.toml\`
144-
- Updated version in \`src/claude_code_sdk/__init__.py\`
145-
146-
## Release Information
147-
- Published to PyPI: https://pypi.org/project/claude-code-sdk/${{ github.event.inputs.version }}/
148-
- Install with: \`pip install claude-code-sdk==${{ github.event.inputs.version }}\`
149-
150-
## Next Steps
151-
After merging this PR, a release tag will be created automatically." \
146+
--title "chore: bump version to ${{ env.VERSION }}" \
147+
--body "Automated PR to update version after PyPI release." \
152148
--base main \
153149
--head "$BRANCH_NAME"

scripts/update_version.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""Update version in pyproject.toml and __init__.py files."""
3+
4+
import sys
5+
import re
6+
from pathlib import Path
7+
8+
9+
def update_version(new_version: str) -> None:
10+
"""Update version in project files."""
11+
# Update pyproject.toml
12+
pyproject_path = Path("pyproject.toml")
13+
content = pyproject_path.read_text()
14+
15+
# Only update the version field in [project] section
16+
content = re.sub(
17+
r'^version = "[^"]*"',
18+
f'version = "{new_version}"',
19+
content,
20+
count=1,
21+
flags=re.MULTILINE
22+
)
23+
24+
pyproject_path.write_text(content)
25+
print(f"Updated pyproject.toml to version {new_version}")
26+
27+
# Update __init__.py
28+
init_path = Path("src/claude_code_sdk/__init__.py")
29+
content = init_path.read_text()
30+
31+
# Only update __version__ assignment
32+
content = re.sub(
33+
r'^__version__ = "[^"]*"',
34+
f'__version__ = "{new_version}"',
35+
content,
36+
count=1,
37+
flags=re.MULTILINE
38+
)
39+
40+
init_path.write_text(content)
41+
print(f"Updated __init__.py to version {new_version}")
42+
43+
44+
if __name__ == "__main__":
45+
if len(sys.argv) != 2:
46+
print("Usage: python scripts/update_version.py <version>")
47+
sys.exit(1)
48+
49+
update_version(sys.argv[1])

0 commit comments

Comments
 (0)