Release Python SDK #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .github/workflows/main.yml (Python) | |
| name: Release Python SDK | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - '.changelog/v*.md' | |
| workflow_dispatch: | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write # Required for PyPI trusted publishing | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 | |
| with: | |
| python-version: '3.11' | |
| - name: Extract Version | |
| id: version | |
| run: | | |
| VERSION=$(grep -oP "version\s*=\s*['\"]?\K[^'\"]+" pyproject.toml 2>/dev/null) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build Package | |
| run: python -m build | |
| - name: Create Tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.tag }}" | |
| git push origin ${{ steps.version.outputs.tag }} | |
| - name: Read Changelog | |
| id: changelog | |
| run: | | |
| CHANGELOG_FILE=".changelog/${{ steps.version.outputs.tag }}.md" | |
| if [ -f "$CHANGELOG_FILE" ]; then | |
| delimiter="$(openssl rand -hex 8)" | |
| echo "content<<$delimiter" >> $GITHUB_OUTPUT | |
| cat "$CHANGELOG_FILE" >> $GITHUB_OUTPUT | |
| echo "" >> $GITHUB_OUTPUT | |
| echo "$delimiter" >> $GITHUB_OUTPUT | |
| else | |
| echo "content=Release ${{ steps.version.outputs.tag }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create Release | |
| uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 | |
| with: | |
| tag_name: ${{ steps.version.outputs.tag }} | |
| name: Release ${{ steps.version.outputs.tag }} | |
| body: ${{ steps.changelog.outputs.content }} | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |