Merge pull request #46 from anthropics/automated-version-update-workflow
Some checks failed
Lint / lint (push) Has been cancelled
Test / test (3.10) (push) Has been cancelled
Test / test (3.11) (push) Has been cancelled
Test / test (3.12) (push) Has been cancelled
Test / test (3.13) (push) Has been cancelled

feat: automate version updates after PyPI release
This commit is contained in:
Lina Tawfik 2025-06-27 18:15:59 -07:00 committed by GitHub
commit b3c20bd7e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 102 additions and 1 deletions

View file

@ -0,0 +1,59 @@
name: Create Release Tag
on:
pull_request:
types: [closed]
branches: [main]
jobs:
create-tag:
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from branch name
id: extract_version
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
VERSION="${BRANCH_NAME#release/v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create and push tag
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Create annotated tag
git tag -a "v${{ steps.extract_version.outputs.version }}" \
-m "Release v${{ steps.extract_version.outputs.version }}"
# Push tag
git push origin "v${{ steps.extract_version.outputs.version }}"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.extract_version.outputs.version }}
release_name: Release v${{ steps.extract_version.outputs.version }}
body: |
## Release v${{ steps.extract_version.outputs.version }}
Published to PyPI: https://pypi.org/project/claude-code-sdk/${{ steps.extract_version.outputs.version }}/
### Installation
```bash
pip install claude-code-sdk==${{ steps.extract_version.outputs.version }}
```
### What's Changed
See the [full changelog](https://github.com/${{ github.repository }}/compare/v${{ steps.extract_version.outputs.version }}...v${{ steps.extract_version.outputs.version }})
draft: false
prerelease: false

View file

@ -65,9 +65,14 @@ jobs:
publish: publish:
needs: [test, lint] needs: [test, lint]
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
@ -108,4 +113,41 @@ jobs:
run: | run: |
twine upload dist/* twine upload dist/*
echo "Package published to PyPI" 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==${{ 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"