diff --git a/.github/workflows/create-release-tag.yml b/.github/workflows/create-release-tag.yml new file mode 100644 index 0000000..4f3a2d3 --- /dev/null +++ b/.github/workflows/create-release-tag.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ff9da9a..1822a89 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -65,9 +65,14 @@ jobs: 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 @@ -108,4 +113,41 @@ jobs: run: | twine upload dist/* echo "Package published to PyPI" - echo "Install with: pip install claude-code-sdk==${{ github.event.inputs.version }}" \ No newline at end of file + 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" \ No newline at end of file