Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/python-sdk-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Python SDK Publish

on:
push:
branches:
- main
paths:
- "sdk-python/**"
- ".github/workflows/python-sdk-publish.yml"
workflow_dispatch:

jobs:
publish-python-sdk:
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: read
id-token: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install build dependency
run: |
python -m pip install --upgrade pip
pip install build

- name: Build package
run: make build-python-sdk

- name: Read package version
id: package
working-directory: sdk-python
run: |
version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this is using same version for all the changes on main branch right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We use the version declared in sdk-python/pyproject.toml, so if that version does not change, later runs on main will skip

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is whether we need automatic version updates or manual version control in sdk-python/pyproject.toml. I think the latter is more under control

echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Check whether version already exists on PyPI
id: pypi
env:
PACKAGE_NAME: agentcube-sdk
PACKAGE_VERSION: ${{ steps.package.outputs.version }}
run: |
status="$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/${PACKAGE_NAME}/${PACKAGE_VERSION}/json")"
if [ "$status" = "200" ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Version ${PACKAGE_VERSION} already exists on PyPI, skipping publish."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, use ‘latest’ as the release version. Since running this GitHub Action indicates that changes have been made to the python-sdk package in agentCube, it should be updated to the ‘latest’ version number even if the version remains the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Therefore, the ‘version=latest’ should be push unconditionally, followed by the ‘version=x.y.z’ where applicable; to ensure that each agentCube version has the corresponding Python SDK version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyPI package versions are immutable, so unlike container images we cannot keep updating a mutable latest tag for the same package version. Re-publishing the same version is not supported. So if we want to do that we need to do a version auto updater

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I think that for the release security, we should explicitly control the version in sdk-python/pyproject.toml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, is the best practice for PyPI to push a Python SDK version each time an agentCube release is published?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. When releasing the agentcube version, manually update the SDK version number

else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Version ${PACKAGE_VERSION} is not published yet."
fi

- name: Publish package to PyPI
if: steps.pypi.outputs.exists != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: sdk-python/dist/
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ e2e-clean:
.PHONY: build-python-sdk
build-python-sdk: ## Build Python SDK
@echo "Building Python SDK..."
cp LICENSE sdk-python/LICENSE
cd sdk-python && python3 -m build; cd ..; rm -f sdk-python/LICENSE
@echo "Build complete. Artifacts are in sdk-python/dist/"
@tmp_file="$(PROJECT_DIR)/sdk-python/LICENSE"; \
trap 'rm -f "$$tmp_file"' EXIT; \
cp LICENSE "$$tmp_file"; \
cd sdk-python && python3 -m build
@echo "Build complete. Artifacts are in sdk-python/dist/"
1 change: 1 addition & 0 deletions sdk-python/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include LICENSE
include README.md
include requirements.txt
recursive-include examples *
global-exclude __pycache__ *.py[cod]
2 changes: 1 addition & 1 deletion sdk-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "agentcube-sdk"
version = "0.1.0"
description = "Python SDK for AgentCube Code Interpreter"
readme = "README.md"
license = { text = "Apache-2.0" }
license = "Apache-2.0"
requires-python = ">=3.10"

dependencies = [
Expand Down
Loading