-
Notifications
You must be signed in to change notification settings - Fork 246
489 lines (446 loc) · 16.9 KB
/
release.yml
File metadata and controls
489 lines (446 loc) · 16.9 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
name: Release Python SDK
on:
workflow_dispatch:
inputs:
version:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
- prepatch
- preminor
- premajor
prerelease_type:
description: 'Pre-release type (used when version is prepatch/preminor/premajor)'
type: choice
default: ""
options:
- ""
- alpha
- beta
- rc
prerelease_increment:
description: "Pre-release number (e.g., 1 for alpha1). Leave empty to auto-increment or start at 1."
type: string
default: ""
confirm_major:
description: "Type RELEASE MAJOR to confirm a major or premajor release"
required: false
default: ""
permissions:
contents: write
id-token: write # Required for PyPI Trusted Publishing via OIDC
concurrency:
group: python-sdk-release
cancel-in-progress: false
jobs:
release-python-sdk:
runs-on: ubuntu-latest
environment: protected branches
steps:
- name: Verify branch
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "❌ Error: Releases can only be triggered from main branch"
echo "Current ref: ${{ github.ref }}"
exit 1
fi
- name: Confirm major release
if: ${{ inputs.version == 'major' || inputs.version == 'premajor' }}
run: |
if [ "${{ inputs.confirm_major }}" != "RELEASE MAJOR" ]; then
echo "❌ For major/premajor releases, set confirm_major to RELEASE MAJOR"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: "1.8.4"
virtualenvs-create: true
virtualenvs-in-project: true
- name: Configure Git
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
run: |
git config user.name "langfuse-bot"
git config user.email "[email protected]"
echo "$GH_ACCESS_TOKEN" | gh auth login --with-token
gh auth setup-git
- name: Get current version
id: current-version
run: |
current_version=$(poetry version -s)
echo "version=$current_version" >> $GITHUB_OUTPUT
echo "Current version: $current_version"
- name: Calculate new version
id: new-version
run: |
current_version="${{ steps.current-version.outputs.version }}"
version_type="${{ inputs.version }}"
prerelease_type="${{ inputs.prerelease_type }}"
prerelease_increment="${{ inputs.prerelease_increment }}"
# Extract base version (strip any pre-release suffix like a1, b2, rc1)
base_version=$(echo "$current_version" | sed -E 's/(a|b|rc)[0-9]+$//')
# Parse version components
IFS='.' read -r major minor patch <<< "$base_version"
if echo "$current_version" | grep -qE '(a|b|rc)[0-9]+$'; then
current_is_prerelease="true"
else
current_is_prerelease="false"
fi
if [ "$version_type" = "premajor" ] || [ "$version_type" = "preminor" ] || [ "$version_type" = "prepatch" ]; then
if [ -z "$prerelease_type" ]; then
echo "❌ Error: prerelease_type must be specified when version is a prerelease variant"
exit 1
fi
# Determine the prerelease base version target
case "$version_type" in
premajor)
if [ "$current_is_prerelease" = "true" ] && [ "$minor" -eq 0 ] && [ "$patch" -eq 0 ]; then
target_major=$major
else
target_major=$((major + 1))
fi
target_minor=0
target_patch=0
;;
preminor)
target_major=$major
if [ "$current_is_prerelease" = "true" ] && [ "$patch" -eq 0 ] && [ "$minor" -gt 0 ]; then
target_minor=$minor
else
target_minor=$((minor + 1))
fi
target_patch=0
;;
prepatch)
target_major=$major
target_minor=$minor
if [ "$current_is_prerelease" = "true" ] && [ "$patch" -gt 0 ]; then
target_patch=$patch
else
target_patch=$((patch + 1))
fi
;;
esac
target_base_version="${target_major}.${target_minor}.${target_patch}"
# Map prerelease type to Python suffix
case "$prerelease_type" in
alpha) suffix="a" ;;
beta) suffix="b" ;;
rc) suffix="rc" ;;
esac
# Determine prerelease number
if [ -n "$prerelease_increment" ]; then
pre_num="$prerelease_increment"
else
# Check if current version is same type of prerelease, if so increment
escaped_target_base_version=$(echo "$target_base_version" | sed 's/\./\\./g')
if echo "$current_version" | grep -qE "^${escaped_target_base_version}${suffix}[0-9]+$"; then
current_pre_num=$(echo "$current_version" | sed -E "s/^${escaped_target_base_version}${suffix}([0-9]+)$/\1/")
pre_num=$((current_pre_num + 1))
else
pre_num=1
fi
fi
new_version="${target_base_version}${suffix}${pre_num}"
is_prerelease="true"
else
# Standard version bump
case "$version_type" in
patch)
patch=$((patch + 1))
;;
minor)
minor=$((minor + 1))
patch=0
;;
major)
major=$((major + 1))
minor=0
patch=0
;;
esac
new_version="${major}.${minor}.${patch}"
is_prerelease="false"
fi
echo "version=$new_version" >> $GITHUB_OUTPUT
echo "is_prerelease=$is_prerelease" >> $GITHUB_OUTPUT
echo "New version: $new_version (prerelease: $is_prerelease)"
- name: Check if tag already exists
run: |
if git rev-parse "v${{ steps.new-version.outputs.version }}" >/dev/null 2>&1; then
echo "❌ Error: Tag v${{ steps.new-version.outputs.version }} already exists"
exit 1
fi
echo "✅ Tag v${{ steps.new-version.outputs.version }} does not exist"
- name: Update version in pyproject.toml
run: |
poetry version ${{ steps.new-version.outputs.version }}
- name: Update version in langfuse/version.py
run: |
new_version="${{ steps.new-version.outputs.version }}"
sed -i "s/__version__ = \".*\"/__version__ = \"$new_version\"/" langfuse/version.py
echo "Updated langfuse/version.py:"
cat langfuse/version.py
- name: Verify version consistency
run: |
pyproject_version=$(poetry version -s)
file_version=$(grep -oP '__version__ = "\K[^"]+' langfuse/version.py)
echo "pyproject.toml version: $pyproject_version"
echo "langfuse/version.py version: $file_version"
if [ "$pyproject_version" != "$file_version" ]; then
echo "❌ Error: Version mismatch between pyproject.toml and langfuse/version.py"
exit 1
fi
if [ "$pyproject_version" != "${{ steps.new-version.outputs.version }}" ]; then
echo "❌ Error: Version in files doesn't match expected version"
exit 1
fi
echo "✅ Versions are consistent: $pyproject_version"
- name: Build package
run: poetry build
- name: Verify build artifacts
run: |
echo "Verifying build artifacts..."
if [ ! -d "dist" ]; then
echo "❌ Error: dist directory not found"
exit 1
fi
wheel_count=$(ls dist/*.whl 2>/dev/null | wc -l)
sdist_count=$(ls dist/*.tar.gz 2>/dev/null | wc -l)
if [ "$wheel_count" -eq 0 ]; then
echo "❌ Error: No wheel file found in dist/"
exit 1
fi
if [ "$sdist_count" -eq 0 ]; then
echo "❌ Error: No source distribution found in dist/"
exit 1
fi
echo "✅ Build artifacts:"
ls -lh dist/
# Verify the version in the built artifacts matches
expected_version="${{ steps.new-version.outputs.version }}"
wheel_file=$(ls dist/*.whl | head -1)
if ! echo "$wheel_file" | grep -q "$expected_version"; then
echo "❌ Error: Wheel filename doesn't contain expected version $expected_version"
echo "Wheel file: $wheel_file"
exit 1
fi
echo "✅ Artifact version verified"
- name: Commit version changes
run: |
git add pyproject.toml langfuse/version.py
git commit -m "chore: release v${{ steps.new-version.outputs.version }}"
- name: Create and push tag
id: push-tag
run: |
git tag "v${{ steps.new-version.outputs.version }}"
git push origin main
git push origin "v${{ steps.new-version.outputs.version }}"
- name: Publish to PyPI
id: publish-pypi
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
- name: Create GitHub Release
id: create-release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.new-version.outputs.version }}
name: v${{ steps.new-version.outputs.version }}
generate_release_notes: true
prerelease: ${{ steps.new-version.outputs.is_prerelease == 'true' }}
files: |
dist/*.whl
dist/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Notify Slack on success
if: success()
uses: slackapi/[email protected]
with:
payload: |
{
"text": "✅ Langfuse Python SDK v${{ steps.new-version.outputs.version }} published to PyPI",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "✅ Langfuse Python SDK Released",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Version:*\n`v${{ steps.new-version.outputs.version }}`"
},
{
"type": "mrkdwn",
"text": "*Type:*\n`${{ inputs.version }}${{ inputs.prerelease_type && format(' ({0})', inputs.prerelease_type) || '' }}`"
},
{
"type": "mrkdwn",
"text": "*Released by:*\n${{ github.actor }}"
},
{
"type": "mrkdwn",
"text": "*Package:*\n`langfuse`"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "📋 View Release Notes",
"emoji": true
},
"url": "${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ steps.new-version.outputs.version }}",
"style": "primary"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "📦 View on PyPI",
"emoji": true
},
"url": "https://pypi.org/project/langfuse/${{ steps.new-version.outputs.version }}/"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "🔧 View Workflow",
"emoji": true
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "🔒 Published with Trusted Publishing (OIDC) • 🤖 Automated release"
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_RELEASES }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- name: Notify Slack on failure
if: failure()
uses: slackapi/[email protected]
with:
payload: |
{
"text": "❌ Langfuse Python SDK release workflow failed",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "❌ Langfuse Python SDK Release Failed",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "⚠️ The release workflow encountered an error and did not complete successfully."
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Requested Version:*\n`${{ inputs.version }}`"
},
{
"type": "mrkdwn",
"text": "*Pre-release Type:*\n${{ inputs.prerelease_type || 'N/A' }}"
},
{
"type": "mrkdwn",
"text": "*Triggered by:*\n${{ github.actor }}"
},
{
"type": "mrkdwn",
"text": "*Current Version:*\n`${{ steps.current-version.outputs.version }}`"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*🔍 Troubleshooting:*\n• Check workflow logs for error details\n• Verify PyPI Trusted Publishing is configured correctly\n• Ensure the version doesn't already exist on PyPI\n• Check if the git tag already exists\n• If partially published, check PyPI and GitHub releases"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "🔧 View Workflow Logs",
"emoji": true
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"style": "danger"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "📖 PyPI Trusted Publishing Docs",
"emoji": true
},
"url": "https://docs.pypi.org/trusted-publishers/"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "🚨 Action required • Check workflow logs for details"
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_ENGINEERING }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK