Skip to content

Commit 46b07f7

Browse files
Merge pull request #247 from acsoto/issue-246-python-sdk-publish
Add Python SDK publish workflow
2 parents 22ed588 + 6a2be5b commit 46b07f7

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Python SDK Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "sdk-python/**"
9+
- ".github/workflows/python-sdk-publish.yml"
10+
workflow_dispatch:
11+
12+
jobs:
13+
publish-python-sdk:
14+
runs-on: ubuntu-latest
15+
environment: pypi
16+
permissions:
17+
contents: read
18+
id-token: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.12"
28+
29+
- name: Install build dependency
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install build
33+
34+
- name: Build package
35+
run: make build-python-sdk
36+
37+
- name: Read package version
38+
id: package
39+
working-directory: sdk-python
40+
run: |
41+
version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
42+
echo "version=$version" >> "$GITHUB_OUTPUT"
43+
44+
- name: Check whether version already exists on PyPI
45+
id: pypi
46+
env:
47+
PACKAGE_NAME: agentcube-sdk
48+
PACKAGE_VERSION: ${{ steps.package.outputs.version }}
49+
run: |
50+
status="$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/${PACKAGE_NAME}/${PACKAGE_VERSION}/json")"
51+
if [ "$status" = "200" ]; then
52+
echo "exists=true" >> "$GITHUB_OUTPUT"
53+
echo "Version ${PACKAGE_VERSION} already exists on PyPI, skipping publish."
54+
else
55+
echo "exists=false" >> "$GITHUB_OUTPUT"
56+
echo "Version ${PACKAGE_VERSION} is not published yet."
57+
fi
58+
59+
- name: Publish package to PyPI
60+
if: steps.pypi.outputs.exists != 'true'
61+
uses: pypa/gh-action-pypi-publish@release/v1
62+
with:
63+
packages-dir: sdk-python/dist/

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ e2e-clean:
319319
.PHONY: build-python-sdk
320320
build-python-sdk: ## Build Python SDK
321321
@echo "Building Python SDK..."
322-
cp LICENSE sdk-python/LICENSE
323-
cd sdk-python && python3 -m build; cd ..; rm -f sdk-python/LICENSE
324-
@echo "Build complete. Artifacts are in sdk-python/dist/"
322+
@tmp_file="$(PROJECT_DIR)/sdk-python/LICENSE"; \
323+
trap 'rm -f "$$tmp_file"' EXIT; \
324+
cp LICENSE "$$tmp_file"; \
325+
cd sdk-python && python3 -m build
326+
@echo "Build complete. Artifacts are in sdk-python/dist/"

sdk-python/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ include LICENSE
22
include README.md
33
include requirements.txt
44
recursive-include examples *
5+
global-exclude __pycache__ *.py[cod]

sdk-python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "agentcube-sdk"
77
version = "0.1.0"
88
description = "Python SDK for AgentCube Code Interpreter"
99
readme = "README.md"
10-
license = { text = "Apache-2.0" }
10+
license = "Apache-2.0"
1111
requires-python = ">=3.10"
1212

1313
dependencies = [

0 commit comments

Comments
 (0)