Repository navigation
178 lines (154 loc) · 4.76 KB
/
Copy pathpython-sdk.yml
File metadata and controls
178 lines (154 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Python SDK
on:
push:
branches: [main]
paths:
- 'link/sdks/python/**'
- 'link/sdks/rust/**'
- 'link/link-common/**'
- '.github/workflows/python-sdk.yml'
workflow_dispatch:
inputs:
publish:
description: "Publish wheels to PyPI"
type: boolean
required: false
default: false
workflow_call:
inputs:
publish:
description: "Publish wheels to PyPI"
type: boolean
required: false
default: false
env:
CARGO_TERM_COLOR: always
CARGO_ENCODED_RUSTFLAGS: ""
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
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.99.1"
- 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.99.1"
- 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: ${{ inputs.publish }}
environment:
name: pypi
permissions:
id-token: write
contents: 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
- name: Checkout
if: github.ref == 'refs/heads/main'
uses: actions/checkout@v4
with:
ref: main
- name: Record published Python SDK versions
if: github.ref == 'refs/heads/main'
shell: bash
run: |
set -euo pipefail
python3 scripts/versions.py mark-published --group python --write
if git diff --quiet -- versions.json; then
echo "published versions already recorded"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add versions.json
git commit -m "chore: record published Python SDK versions"
git push origin HEAD:main