This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Repository navigation
199 lines (164 loc) · 5.37 KB
/
Copy pathrelease-sdk-python.yml
File metadata and controls
199 lines (164 loc) · 5.37 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
name: Release Python SDK
on:
push:
tags:
- 'sdk-python-v*'
permissions:
contents: write
pull-requests: write
id-token: write # Required for trusted publishing
jobs:
verify-tag:
name: Verify Tag on Main Branch
runs-on: ubuntu-latest
outputs:
version: ${{ steps.parse.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Parse tag
id: parse
run: |
VERSION="${GITHUB_REF#refs/tags/sdk-python-v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "🔢 Version: $VERSION"
- name: Verify tag is on main branch
uses: ./.github/actions/verify-tag
- name: Verify version matches pyproject.toml
run: |
VERSION="${{ steps.parse.outputs.version }}"
PACKAGE_VERSION=$(grep -E '^version = ' sdk/python/pyproject.toml | awk -F'"' '{print $2}')
if [ "$PACKAGE_VERSION" != "$VERSION" ]; then
echo "❌ Tag version ($VERSION) does not match pyproject.toml version ($PACKAGE_VERSION)"
exit 1
fi
echo "✅ Version matches pyproject.toml"
validate-and-test:
name: Validate and Test
needs: verify-tag
runs-on: ubuntu-latest
defaults:
run:
working-directory: sdk/python
outputs:
current_version: ${{ steps.get_version.outputs.current_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version format
run: |
if ! [[ "${{ needs.verify-tag.outputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
echo "❌ Invalid version format. Please use semantic versioning (e.g., 1.0.0 or 1.0.0-beta1)"
exit 1
fi
- name: Get current version
id: get_version
run: |
current_version=$(grep -E '^version = ' pyproject.toml | awk -F'"' '{print $2}')
echo "current_version=$current_version" >> $GITHUB_OUTPUT
echo "Current version: $current_version"
echo "New version: ${{ needs.verify-tag.outputs.version }}"
- name: Check version is newer
run: |
current="${{ steps.get_version.outputs.current_version }}"
new="${{ needs.verify-tag.outputs.version }}"
# Simple version comparison (works for most cases)
if [ "$(printf '%s\n' "$new" "$current" | sort -V | head -n1)" = "$new" ] && [ "$new" != "$current" ]; then
echo "❌ New version ($new) must be higher than current version ($current)"
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tests
run: tox -e py311
- name: Run linting
run: tox -e lint,type
build:
name: Build Distribution
needs: [verify-tag, validate-and-test]
runs-on: ubuntu-latest
defaults:
run:
working-directory: sdk/python
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build distribution packages
run: python -m build
- name: Check distribution packages
run: twine check dist/*
- name: Upload distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: sdk/python/dist/
publish-pypi:
name: Publish to PyPI
needs: [verify-tag, build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/ftl-sdk
permissions:
id-token: write
steps:
- name: Download distribution packages
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
create-release:
name: Create GitHub Release
needs: [verify-tag, publish-pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: "Python SDK v${{ needs.verify-tag.outputs.version }}"
draft: false
prerelease: false
generate_release_notes: true
body: |
## Python SDK v${{ needs.verify-tag.outputs.version }}
### Installation
```bash
pip install ftl-sdk==${{ needs.verify-tag.outputs.version }}
```
### Links
- [PyPI Package](https://pypi.org/project/ftl-sdk/${{ needs.verify-tag.outputs.version }}/)
- [Documentation](https://github.com/fastertools/ftl/tree/main/sdk/python)
- name: Verify PyPI installation
run: |
echo "Waiting for PyPI to update..."
sleep 60
# Try to install from PyPI
pip install ftl-sdk==${{ needs.verify-tag.outputs.version }}
echo "✅ Package is available on PyPI!"