-
Notifications
You must be signed in to change notification settings - Fork 0
272 lines (221 loc) · 8.29 KB
/
sdk-python.yml
File metadata and controls
272 lines (221 loc) · 8.29 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: SDK Python
on:
push:
branches: [main]
paths:
- "sdks/python/**"
- ".github/workflows/sdk-python.yml"
pull_request:
branches: [main]
paths:
- "sdks/python/**"
- ".github/workflows/sdk-python.yml"
workflow_dispatch:
permissions:
contents: read
id-token: write
# Cancel in-progress runs on same branch/PR
concurrency:
group: sdk-py-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
defaults:
run:
working-directory: sdks/python
jobs:
# =============================================================================
# Lint & Type Check
# =============================================================================
lint:
name: Lint & Type Check
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
run: |
uv venv
uv pip install -e ".[dev]"
- name: Run ruff linter
run: uv run ruff check src tests
- name: Run ruff formatter check
run: uv run ruff format --check src tests
- name: Run mypy type check
run: uv run mypy --strict src
# =============================================================================
# Unit Tests
# =============================================================================
test-unit:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
run: |
uv venv
uv pip install -e ".[dev]"
- name: Run unit tests
run: uv run pytest tests/unit -v --tb=short
# =============================================================================
# Integration Tests
# =============================================================================
test-integration:
name: Integration Tests
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
run: |
uv venv
uv pip install -e ".[dev]"
- name: Run integration tests
run: uv run pytest tests/integration -v --tb=short
# =============================================================================
# Coverage
# =============================================================================
coverage:
name: Coverage Report
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install dependencies
run: |
uv venv
uv pip install -e ".[dev]"
- name: Run tests with coverage
run: uv run pytest --cov=src --cov-report=term-missing --cov-report=xml --cov-fail-under=90
- name: Upload coverage to job summary
run: |
echo "## 📊 Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
uv run coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
# =============================================================================
# Build & Verify
# =============================================================================
build:
name: Build & Verify
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install build tools
run: uv pip install --system build twine
- name: Build package
run: python -m build
- name: Verify package with twine
run: twine check dist/*
- name: Test install from wheel
run: |
uv venv test-install
uv pip install --python test-install dist/*.whl
test-install/bin/python -c "from logwell import Logwell; print('Import OK')"
- name: Upload build artifacts
uses: actions/upload-artifact@v6
with:
name: sdk-python-dist
path: sdks/python/dist/
retention-days: 7
# =============================================================================
# Publish to PyPI (only on main, only if version changed)
# =============================================================================
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [lint, test-unit, test-integration, coverage, build]
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
environment:
name: pypi
url: https://pypi.org/project/logwell/
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install build tools
run: uv pip install --system build
- name: Build package
run: python -m build
- name: Check if version exists on PyPI
id: version-check
run: |
PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])")
LOCAL_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "local_version=$LOCAL_VERSION" >> $GITHUB_OUTPUT
# Check if this version already exists on PyPI
if pip index versions "$PACKAGE_NAME" 2>/dev/null | grep -q "$LOCAL_VERSION"; then
echo "Version $LOCAL_VERSION already exists on PyPI"
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Version $LOCAL_VERSION is new, will publish"
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Publish to PyPI (Trusted Publisher)
if: steps.version-check.outputs.should_publish == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: sdks/python/dist/
- name: Add publish info to job summary
if: steps.version-check.outputs.should_publish == 'true'
run: |
echo "## 📦 SDK Published to PyPI" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Package:** \`${{ steps.version-check.outputs.package_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`${{ steps.version-check.outputs.local_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "pip install ${{ steps.version-check.outputs.package_name }}==${{ steps.version-check.outputs.local_version }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Skip publish info
if: steps.version-check.outputs.should_publish == 'false'
run: |
echo "## ℹ️ SDK Publish Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Version \`${{ steps.version-check.outputs.local_version }}\` already exists on PyPI." >> $GITHUB_STEP_SUMMARY
echo "Bump the version in \`sdks/python/pyproject.toml\` to trigger a new publish." >> $GITHUB_STEP_SUMMARY