-
Notifications
You must be signed in to change notification settings - Fork 4
393 lines (331 loc) Β· 12.2 KB
/
Copy pathpublish-pypi.yml
File metadata and controls
393 lines (331 loc) Β· 12.2 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
name: Publish Python Package to PyPI
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (semantic version)'
required: true
type: string
dry_run:
description: 'Run in dry-run mode only'
required: false
type: boolean
default: true
repository:
description: 'PyPI repository (pypi or testpypi)'
required: false
type: choice
options:
- 'pypi'
- 'testpypi'
default: 'pypi'
push:
tags:
- 'v*'
- 'python-v*'
- 'pypi-v*'
permissions:
contents: write
packages: write
id-token: write # For PyPI trusted publishing
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
validate:
name: Validate Python Package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Validate package metadata
working-directory: crates/terraphim_automata_py
run: |
python -c "import tomllib; pkg = tomllib.load(open('pyproject.toml', 'rb')); print('Package name:', pkg['project']['name']); print('Version:', pkg['project']['version'])"
- name: Validate version format
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]]; then
VERSION=$(echo "${{ github.ref }}" | sed 's#refs/tags/python-v##; s#refs/tags/pypi-v##; s#refs/tags/v##')
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: $VERSION"
exit 1
fi
echo "Version to publish: $VERSION"
fi
build:
name: Build Python Distributions
runs-on: ${{ matrix.os }}
needs: validate
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: macos-latest
target: aarch64-apple-darwin
macos-arch: arm64
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: ${{ matrix.python-version }}
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ matrix.target }}-pypi-${{ hashFiles('**/Cargo.lock') }}
- name: Install Python build dependencies
working-directory: crates/terraphim_automata_py
run: |
uv pip install --system pip maturin pytest pytest-benchmark build
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
working-directory: crates/terraphim_automata_py
args: --release --out dist --find-interpreter --target ${{ matrix.target }}
sccache: 'false'
manylinux: auto
- name: Upload wheel artifacts
uses: actions/upload-artifact@v5
with:
name: wheels-${{ matrix.os }}-py${{ matrix.python-version }}
path: crates/terraphim_automata_py/dist/*.whl
if-no-files-found: error
build-sdist:
name: Build Source Distribution
runs-on: ubuntu-latest
needs: validate
# Note: sdist build may fail due to maturin bug with workspace path dependencies
# Wheel builds are the primary artifacts, sdist is optional
continue-on-error: true
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Build source distribution
uses: PyO3/maturin-action@v1
with:
working-directory: crates/terraphim_automata_py
command: sdist
args: --out dist
- name: Upload sdist artifact
uses: actions/upload-artifact@v5
with:
name: sdist
path: crates/terraphim_automata_py/dist/*.tar.gz
if-no-files-found: error
test:
name: Test Package
runs-on: ${{ matrix.os }}
needs: build
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Download test distributions
uses: actions/download-artifact@v4
with:
name: wheels-${{ matrix.os }}-py${{ matrix.python-version }}
path: ${{ github.workspace }}/dist
- name: Install test dependencies
working-directory: crates/terraphim_automata_py
run: |
uv pip install --system pytest pytest-benchmark pytest-cov black mypy ruff
uv pip install --system terraphim-automata --find-links=${{ github.workspace }}/dist
- name: Run tests
working-directory: crates/terraphim_automata_py
run: |
# Run Python tests
python -m pytest python/tests/ -v --cov=terraphim_automata --cov-report=term-missing
# Test basic import
python -c "import terraphim_automata; print('OK: Package imports successfully')"
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
# Note: build-sdist is optional due to maturin bug, wheels are sufficient
needs: [build, test]
permissions:
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install 1Password CLI
uses: 1password/install-cli-action@v2
- name: Get PyPI token from 1Password (or use secret)
id: token
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
run: |
TOKEN=""
if [[ -n "${OP_SERVICE_ACCOUNT_TOKEN}" ]]; then
TOKEN=$(op read "op://TerraphimPlatform/pypi.token/password" 2>/dev/null || true)
fi
if [[ -z "$TOKEN" ]]; then
echo "PyPI token not found in 1Password, using GitHub secret"
TOKEN="${{ secrets.PYPI_API_TOKEN }}"
fi
if [[ -z "$TOKEN" ]]; then
echo "No PyPI token available from 1Password or GitHub secrets"
exit 1
fi
echo "token=$TOKEN" >> $GITHUB_OUTPUT
- name: Determine version
id: version
run: |
VERSION="${{ inputs.version }}"
if [[ -z "$VERSION" ]]; then
# Extract version from tag
if [[ "${{ github.ref }}" == refs/tags/python-v* ]]; then
VERSION=${GITHUB_REF#refs/tags/python-v}
elif [[ "${{ github.ref }}" == refs/tags/pypi-v* ]]; then
VERSION=${GITHUB_REF#refs/tags/pypi-v}
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "π¦ Publishing version: $VERSION"
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Make publish script executable
run: chmod +x ./scripts/publish-pypi.sh
- name: Collect distributions
run: |
mkdir -p crates/terraphim_automata_py/dist
find dist -name "*.whl" -exec cp {} crates/terraphim_automata_py/dist/ \; || true
find dist -name "*.tar.gz" -exec cp {} crates/terraphim_automata_py/dist/ \; || true
echo "π¦ Found distributions:"
ls -la crates/terraphim_automata_py/dist/
- name: Run publish script
env:
PYPI_TOKEN: ${{ steps.token.outputs.token }}
run: |
# Prepare script arguments
ARGS="--version ${{ steps.version.outputs.version }} --token $PYPI_TOKEN --use-existing-dist"
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
ARGS="$ARGS --dry-run"
fi
if [[ "${{ inputs.repository }}" == "testpypi" ]]; then
ARGS="$ARGS --repository testpypi"
fi
# Run publish script
./scripts/publish-pypi.sh $ARGS
- name: Verify published packages
if: inputs.dry_run != 'true'
run: |
PACKAGE_NAME="terraphim-automata"
PACKAGE_VERSION="${{ steps.version.outputs.version }}"
# Try to install from PyPI (or TestPyPI)
if [[ "${{ inputs.repository }}" == "testpypi" ]]; then
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "$PACKAGE_NAME==$PACKAGE_VERSION" || echo "β οΈ Package not yet visible on TestPyPI"
else
python -m pip install "$PACKAGE_NAME==$PACKAGE_VERSION" || echo "β οΈ Package not yet visible on PyPI"
fi
echo "π Package verification complete"
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/') && inputs.dry_run != 'true'
uses: softprops/action-gh-release@v2
continue-on-error: true
with:
name: "terraphim-automata ${{ github.ref_name }}"
token: ${{ secrets.GITHUB_TOKEN }}
body: |
## Python Package Release
**Package**: `terraphim-automata`
**Version**: ${{ github.ref_name }}
**Repository**: ${{ inputs.repository }}
### π Installation
```bash
pip install terraphim-automata
```
or for development:
```bash
pip install terraphim-automata[dev]
```
### β¨ Features
- **Fast Autocomplete**: Sub-millisecond prefix search
- **Knowledge Graph Integration**: Semantic connectivity analysis
- **Native Performance**: Rust backend with PyO3 bindings
- **Cross-Platform**: Linux, macOS, Windows support
- **Python 3.9+**: Modern Python support
### π Performance
- **Autocomplete Index**: ~749 bytes
- **Knowledge Graph**: ~856 bytes
- **Native Extension**: Optimized binary wheels
### π Links
- [PyPI package](https://pypi.org/project/terraphim-automata)
- [Documentation](https://github.com/terraphim/terraphim-ai/tree/main/crates/terraphim_automata_py)
---
π€ Generated on: $(date)
draft: false
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
- name: Notify completion
if: inputs.dry_run != 'true'
run: |
echo "π PyPI publishing workflow completed successfully!"
echo "π¦ Package: terrraphim-automata"
echo "π Repository: ${{ inputs.repository }}"