-
Notifications
You must be signed in to change notification settings - Fork 2
510 lines (456 loc) · 14.8 KB
/
Copy pathCI.yml
File metadata and controls
510 lines (456 loc) · 14.8 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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
name: Rust CI/CD
on:
push:
branches: ["main"]
tags:
- "v*"
pull_request:
branches: ["main"]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
benchmark:
name: Run Benchmarks
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
# On pull requests, check out the head ref so we can commit to it
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository universe
sudo apt-get update
sudo apt-get install -y build-essential autoconf automake libtool swig python3-dev simstring-bin
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.14"
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
- name: Set up Julia
uses: julia-actions/setup-julia@v2
with:
version: "1"
- name: Cache python dependencies
uses: actions/cache@v5
with:
path: |
.venv
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Run and Compare Benchmarks
run: |
# Install python dependencies
pip install uv
uv venv
source .venv/bin/activate
uv pip install simstring-fast pandas maturin tabulate psutil
rm -rf target/wheels
maturin build --release
uv pip install target/wheels/*.whl
# Install ruby dependencies
gem install simstring_pure descriptive_statistics json
# Install julia dependencies
julia -e 'using Pkg; Pkg.add(["SimString", "BenchmarkTools", "Statistics", "JSON"])'
# Run benchmarks
echo "Running and Comparing Benchmarks..."
python benches/run_benches.py
- name: Prepare for benchmark results commit
if: startsWith(github.ref, 'refs/tags/')
run: |
git stash
git checkout main
git stash pop
- name: Commit benchmark results
if: startsWith(github.ref, 'refs/tags/')
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: "docs(benchmarks): update benchmark results"
file_pattern: BENCHMARKS.md
- name: Post benchmark results to PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const benchmarks = fs.readFileSync('BENCHMARKS.md', 'utf8');
const body = `## Benchmark Results\n\n${benchmarks}`;
const marker = '## Benchmark Results';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(
(comment) =>
comment.user?.login === 'github-actions[bot]' &&
comment.body?.startsWith(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
test:
name: Test on ${{ matrix.os }} / ${{ matrix.rust }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]
include:
- os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
rust: stable
target: aarch64-unknown-linux-gnu
- os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
- os: macos-latest
rust: stable
target: x86_64-apple-darwin
- os: macos-latest
rust: stable
target: aarch64-apple-darwin
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
components: rustfmt, clippy
- name: Install cross
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cargo install cross
- name: Set up cargo cache
if: runner.os != 'macOS'
uses: actions/cache@v5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.14t"
- name: Cache python dependencies
if: runner.os != 'macOS'
uses: actions/cache@v5
with:
path: |
.venv
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: cargo clippy --target ${{ matrix.target }} -- -D warnings
- name: Run clippy (cross)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cross clippy --target ${{ matrix.target }} -- -D warnings
- name: Run tests
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: cargo test --target ${{ matrix.target }} --verbose
- name: Run tests (cross)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cross test --target ${{ matrix.target }} --verbose
- name: Run Python binding tests
shell: bash
run: |
pip install uv
uv venv
if [ "$RUNNER_OS" == "Windows" ]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
uv pip install maturin pytest
rm -rf target/wheels
maturin build --release
uv pip install target/wheels/*.whl
pytest tests/python/ -vv
- name: Build
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: cargo build --target ${{ matrix.target }} --verbose
- name: Build (cross)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cross build --target ${{ matrix.target }} --verbose
- name: Check documentation
run: cargo doc --no-deps --document-private-items
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
command: build
args: --release --out dist
# Build universal2 wheels on macOS
target: ${{ runner.os == 'macOS' && 'universal2-apple-darwin' || '' }}
- name: Upload wheels
uses: actions/upload-artifact@v6
with:
name: wheels-${{ matrix.os }}
path: dist
build_wheels_linux:
name: Build manylinux wheels
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
command: build
args: --release --out dist
manylinux: "2014"
- name: Upload wheels
uses: actions/upload-artifact@v6
with:
name: wheels-linux
path: dist
test_wheels:
name: Test wheels on ${{ matrix.os }} / Python ${{ matrix.python-version }}
needs: [build_wheels, build_wheels_linux]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-14, macos-15, macos-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
exclude:
# Exclude Python 3.10 on macos-14 due to known issues with setup-python
- os: macos-14
python-version: "3.10"
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v7
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: Cache python dependencies
if: runner.os != 'macOS'
uses: actions/cache@v5
with:
path: |
.venv
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install wheel and test dependencies
shell: bash
run: |
pip install uv
uv venv
if [ "$RUNNER_OS" == "Windows" ]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
uv pip install pytest
uv pip install simstring-rust --no-index --find-links dist/ --force-reinstall
- name: Run Python binding tests
shell: bash
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
pytest tests/python/ -vv
publish_to_test_pypi:
name: Publish to TestPyPI
needs: [test_wheels]
runs-on: ubuntu-latest
# Run on pushes to main, but not on tags
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v')
environment:
name: testpypi
url: https://test.pypi.org/p/simstring-rust
permissions:
id-token: write
steps:
- uses: actions/checkout@v6
- uses: actions/download-artifact@v7
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: Publish to TestPyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_REPOSITORY_URL: https://test.pypi.org/legacy/
with:
command: upload
args: --non-interactive --skip-existing dist/*.whl
working-directory: .
before-script-linux: |
sudo apt-get update
sudo apt-get install -y tree
tree .
publish_to_pypi:
name: Publish to PyPI
needs: [test_wheels, publish]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/simstring-rust
permissions:
id-token: write
steps:
- uses: actions/checkout@v6
- uses: actions/download-artifact@v7
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_REPOSITORY_URL: https://upload.pypi.org/legacy/
with:
command: upload
args: --non-interactive --skip-existing dist/*.whl
working-directory: .
before-script-linux: |
sudo apt-get update
sudo apt-get install -y tree
tree .
run-examples:
name: Run Examples
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run Rust example
run: cargo run --example basic --release
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.14"
- name: Cache python dependencies
uses: actions/cache@v5
with:
path: |
.venv
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Run Python example
shell: bash
run: |
pip install uv
uv venv
if [ "$RUNNER_OS" == "Windows" ]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
uv pip install maturin
rm -rf target/wheels
maturin build --release
uv pip install target/wheels/*.whl
python examples/python_basic.py
# Publish to crates.io on new tags
publish:
name: Publish to crates.io
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Check package
run: cargo package
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
release:
name: Create GitHub Release
needs: [publish_to_pypi, publish]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # get all tags
- name: Generate a changelog
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
args: -vv --latest --strip header
env:
OUTPUT: CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: "Release ${{ github.ref_name }}"
body: ${{ steps.git-cliff.outputs.content }}
draft: false
prerelease: contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}