|
| 1 | +name: Build and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to publish' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + previous_tag: |
| 11 | + description: 'Previous release tag for changelog generation' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + default: '' |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-wheels: |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest] |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: '3.12' |
| 28 | + |
| 29 | + - name: Install build dependencies |
| 30 | + run: pip install build twine wheel |
| 31 | + shell: bash |
| 32 | + |
| 33 | + - name: Build wheel with bundled CLI |
| 34 | + run: python scripts/build_wheel.py --version "${{ inputs.version }}" --skip-sdist --clean |
| 35 | + shell: bash |
| 36 | + |
| 37 | + - uses: actions/upload-artifact@v4 |
| 38 | + with: |
| 39 | + name: wheel-${{ matrix.os }} |
| 40 | + path: dist/*.whl |
| 41 | + if-no-files-found: error |
| 42 | + |
| 43 | + publish: |
| 44 | + needs: build-wheels |
| 45 | + runs-on: ubuntu-latest |
| 46 | + environment: production |
| 47 | + permissions: |
| 48 | + contents: write |
| 49 | + env: |
| 50 | + VERSION: ${{ inputs.version }} |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + ssh-key: ${{ secrets.DEPLOY_KEY }} |
| 56 | + |
| 57 | + - uses: actions/setup-python@v5 |
| 58 | + with: |
| 59 | + python-version: '3.12' |
| 60 | + |
| 61 | + - name: Update version files |
| 62 | + run: python scripts/update_version.py "$VERSION" |
| 63 | + |
| 64 | + - uses: actions/download-artifact@v4 |
| 65 | + with: |
| 66 | + path: dist |
| 67 | + pattern: wheel-* |
| 68 | + merge-multiple: true |
| 69 | + |
| 70 | + - name: Build sdist and publish to PyPI |
| 71 | + run: | |
| 72 | + pip install build twine |
| 73 | + python -m build --sdist |
| 74 | + twine upload dist/* |
| 75 | + env: |
| 76 | + TWINE_USERNAME: __token__ |
| 77 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 78 | + |
| 79 | + - name: Configure git |
| 80 | + run: | |
| 81 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 82 | + git config user.name "github-actions[bot]" |
| 83 | +
|
| 84 | + - name: Commit version changes |
| 85 | + run: | |
| 86 | + git add pyproject.toml src/claude_agent_sdk/_version.py |
| 87 | + git commit -m "chore: release v$VERSION" |
| 88 | +
|
| 89 | + - name: Update changelog with Claude |
| 90 | + continue-on-error: true |
| 91 | + uses: anthropics/claude-code-action@v1 |
| 92 | + with: |
| 93 | + prompt: "/generate-changelog new version: ${{ env.VERSION }}, old version: ${{ inputs.previous_tag }}" |
| 94 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 95 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + claude_args: | |
| 97 | + --model claude-opus-4-6 |
| 98 | + --allowedTools 'Bash(git add:*),Bash(git commit:*),Edit' |
| 99 | +
|
| 100 | + - name: Push to main |
| 101 | + run: | |
| 102 | + git remote set-url origin git@github.com:anthropics/claude-agent-sdk-python.git |
| 103 | + git push origin main |
| 104 | +
|
| 105 | + - name: Create tag and GitHub Release |
| 106 | + env: |
| 107 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 108 | + run: | |
| 109 | + git tag -a "v$VERSION" -m "Release v$VERSION" |
| 110 | + git push origin "v$VERSION" |
| 111 | +
|
| 112 | + awk -v ver="$VERSION" '/^## / { if (found) exit; if ($2 == ver) found=1; next } found { print }' CHANGELOG.md > release_notes.md |
| 113 | + echo -e "\n---\n\n**PyPI:** https://pypi.org/project/claude-agent-sdk/$VERSION/\n\n\`\`\`bash\npip install claude-agent-sdk==$VERSION\n\`\`\`" >> release_notes.md |
| 114 | +
|
| 115 | + gh release create "v$VERSION" --title "v$VERSION" --notes-file release_notes.md |
0 commit comments