Skip to content
Open
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
151 changes: 151 additions & 0 deletions .github/workflows/python-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: Python SDK

on:
push:
branches: [main, dev]
paths:
- 'link/sdks/python/**'
- 'link/kalam-client/**'
- 'link/link-common/**'
- '.github/workflows/python-sdk.yml'
pull_request:
paths:
- 'link/sdks/python/**'
- 'link/kalam-client/**'
- 'link/link-common/**'
- '.github/workflows/python-sdk.yml'
workflow_dispatch:
inputs:
publish:
description: "Publish wheels to PyPI"
type: boolean
required: false
default: false

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test (${{ matrix.os }}, Python ${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.92.0"

- name: Cache Cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: link/sdks/python -> target

- name: Create venv and install maturin + pytest
working-directory: link/sdks/python
shell: bash
run: |
python -m venv .venv
if [ -f .venv/bin/activate ]; then source .venv/bin/activate; else source .venv/Scripts/activate; fi
python -m pip install --upgrade pip
pip install maturin pytest pytest-asyncio

- name: Build SDK in develop mode (inside venv)
working-directory: link/sdks/python
shell: bash
run: |
if [ -f .venv/bin/activate ]; then source .venv/bin/activate; else source .venv/Scripts/activate; fi
maturin develop --release

- name: Run unit tests (no server required)
working-directory: link/sdks/python
shell: bash
run: |
if [ -f .venv/bin/activate ]; then source .venv/bin/activate; else source .venv/Scripts/activate; fi
pytest tests/test_auth.py tests/test_exceptions.py tests/test_agent.py -v

build-wheels:
name: Build wheels (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v4

- name: Build wheels
uses: PyO3/maturin-action@v1
with:
working-directory: link/sdks/python
command: build
args: --release --strip --out dist
rust-toolchain: "1.92.0"

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: link/sdks/python/dist/*.whl

build-sdist:
name: Build source distribution
runs-on: ubuntu-latest
needs: test

steps:
- uses: actions/checkout@v4

- name: Build sdist
uses: PyO3/maturin-action@v1
with:
working-directory: link/sdks/python
command: sdist
args: --out dist

- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: sdist
path: link/sdks/python/dist/*.tar.gz

publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build-wheels, build-sdist]
if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true'
environment: pypi
permissions:
id-token: write

steps:
- name: Download all wheels
uses: actions/download-artifact@v4
with:
path: dist
pattern: wheels-*
merge-multiple: true

- name: Download sdist
uses: actions/download-artifact@v4
with:
name: sdist
path: dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
9 changes: 9 additions & 0 deletions link/sdks/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
target/
.venv/
__pycache__/
*.pyc
*.pyd
*.so
dist/
build/
*.egg-info/
Loading
Loading