-
Notifications
You must be signed in to change notification settings - Fork 16
521 lines (501 loc) · 20.1 KB
/
ci.yml
File metadata and controls
521 lines (501 loc) · 20.1 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
511
512
513
514
515
516
517
518
519
520
521
name: Continuous integration
on:
push:
branches:
- main
pull_request:
merge_group:
types: [checks_requested]
workflow_dispatch: {}
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
RUSTFLAGS: "--cfg=ci_run"
MIRIFLAGS: "-Zmiri-permissive-provenance" # Required due to warnings in bitvec 1.0.1
CI: true # insta snapshots behave differently on ci
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
# Pinned version for the uv package manager
UV_VERSION: "0.9.7"
UV_FROZEN: 1
# The highest and lowest supported Python versions, used for testing
PYTHON_HIGHEST: "3.14"
PYTHON_LOWEST: "3.10"
# different strings for install action and feature name
# adapted from https://github.com/TheDan64/inkwell/blob/master/.github/workflows/test.yml
LLVM_MAIN_VERSION: "21"
LLVM_VERSION: "21.1"
LLVM_FEATURE_NAME: "21-1"
# Path to the cached tket-c-api library
# When this envvar is set, the `./.github/actions/tket-c-api` action **must** be run to fetch the artifacts
# This config is not required, but speeds up the build by caching the tket-c-api library
# The alternative is to install conan and remove the env var
TKET_C_API_PATH: "${{ github.workspace }}/tket-c-api"
LD_LIBRARY_PATH: ${{ github.workspace }}/tket-c-api/lib
jobs:
# Check if changes were made to the relevant files.
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
changes:
name: Check for changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
rust: ${{ steps.filter.outputs.rust }}
python: ${{ steps.filter.outputs.python }}
extensions: ${{ steps.filter.outputs.extensions }}
qis: ${{ steps.filter.outputs.qis }}
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/check-changes
id: filter
check-rs:
name: Check Rust code 🦀
needs: [changes]
if: ${{ needs.changes.outputs.rust == 'true' }}
runs-on: ubuntu-latest
env:
# Fail on rust compiler warnings.
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- name: Check formatting
run: cargo fmt -- --check
- name: Install LLVM and Clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ env.LLVM_MAIN_VERSION }} main'
sudo apt update
sudo apt install llvm-${{ env.LLVM_MAIN_VERSION }} libpolly-${{ env.LLVM_MAIN_VERSION }}-dev
- name: Run clippy
run: cargo clippy --all-targets --all-features --workspace -- -D warnings
- name: Build docs
run: cargo doc --no-deps --all-features --workspace
env:
RUSTDOCFLAGS: "-Dwarnings"
check-py:
name: Check tket-py 🐍
needs: changes
if: ${{ needs.changes.outputs.python == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
- name: Install LLVM and Clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ env.LLVM_MAIN_VERSION }} main'
sudo apt update
sudo apt install llvm-${{ env.LLVM_MAIN_VERSION }} libpolly-${{ env.LLVM_MAIN_VERSION }}-dev
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- name: Install Python ${{ env.PYTHON_LOWEST }}
run: uv python install ${{ env.PYTHON_LOWEST }}
- name: Setup dependencies
# avoid building qis-compiler
run: uv sync --package=tket --exact --python ${{ env.PYTHON_LOWEST }}
- name: Type check with mypy
run: uv run mypy .
- name: Check formatting with ruff
run: uv run --no-project ruff format --check
- name: Lint with ruff
run: uv run --no-project ruff check
benches:
name: Continuous benchmarking 🏋️
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
runs-on: ubuntu-latest
permissions:
checks: write
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- uses: cargo-bins/cargo-binstall@main
- name: Install cargo-codspeed
run: cargo binstall cargo-codspeed --force
- name: Override criterion with the CodSpeed harness
run: |
cargo add --dev codspeed-criterion-compat --rename criterion --package tket
- name: Build benchmarks
run: cargo codspeed build --profile bench --features portmatching,binary-eccs,rewrite-tracing
- name: Run benchmarks
uses: CodSpeedHQ/action@v4
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: "cargo codspeed run"
mode: "instrumentation"
# Run tests on Rust stable
tests-rs-stable-no-features:
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' }}
runs-on: ubuntu-latest
name: tests (Rust stable, no features)
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: "stable"
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- uses: taiki-e/install-action@nextest
- name: Build with no features
run: cargo nextest r --verbose -p tket -p tket-py -p tket-qsystem --no-default-features --no-run
- name: Tests with no features
run: cargo nextest r --verbose -p tket -p tket-py -p tket-qsystem --no-default-features
# Run tests on Rust stable
tests-rs-stable-all-features:
needs: [changes]
if: ${{ needs.changes.outputs.rust == 'true' }}
runs-on: ubuntu-latest
name: tests (Rust stable, all features)
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: "stable"
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
- name: Install LLVM and Clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ env.LLVM_MAIN_VERSION }} main'
sudo apt update
sudo apt install llvm-${{ env.LLVM_MAIN_VERSION }} libpolly-${{ env.LLVM_MAIN_VERSION }}-dev
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- uses: taiki-e/install-action@nextest
- name: Build with all features
run: cargo nextest r --verbose --workspace --all-features --no-run
- name: Tests with all features
run: cargo nextest r --verbose --workspace --all-features
# Run tests on other toolchains
tests-rs-other:
needs: [changes]
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
# Stable is covered by `tests-stable-no-features` and `tests-stable-all-features`
# Nightly is covered by `tests-nightly-coverage`
# MSRV is covered by `tests-msrv`
rust: [beta]
name: tests (Rust ${{ matrix.rust }})
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Install LLVM and Clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ env.LLVM_MAIN_VERSION }} main'
sudo apt update
sudo apt install llvm-${{ env.LLVM_MAIN_VERSION }} libpolly-${{ env.LLVM_MAIN_VERSION }}-dev
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
- uses: taiki-e/install-action@nextest
- name: Build with no features
run: cargo nextest r --verbose --workspace --no-default-features --no-run
- name: Tests with no features
run: cargo nextest r --verbose --workspace --no-default-features
- name: Build with all features
run: cargo nextest r --verbose --workspace --all-features --no-run
- name: Tests with all features
run: cargo nextest r --verbose --workspace --all-features
tests-nightly-coverage:
needs: [changes]
# Run only if there are changes in the relevant files
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
runs-on: ubuntu-latest
name: tests (Rust nightly, coverage)
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- uses: dtolnay/rust-toolchain@master
with:
# Nightly is required to count doctests coverage
toolchain: "nightly"
components: llvm-tools-preview
- name: Install LLVM and Clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ env.LLVM_MAIN_VERSION }} main'
sudo apt update
sudo apt install llvm-${{ env.LLVM_MAIN_VERSION }} libpolly-${{ env.LLVM_MAIN_VERSION }}-dev
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run tests with coverage instrumentation
run: |
cargo llvm-cov clean --workspace
cargo llvm-cov --no-report --workspace --no-default-features --doctests
cargo llvm-cov --no-report --workspace --all-features --doctests
- name: Generate coverage report
run: cargo llvm-cov --all-features report --codecov --output-path coverage.json
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v6
with:
files: coverage.json
name: rust
flags: rust
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
# Run tests on the minimum supported rust version, with minimal dependency versions
tests-msrv:
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
runs-on: ubuntu-latest
name: tests (Rust MSRV, min dependencies)
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install MSRV toolchain
id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.91"
- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@master
with:
# Nightly must be installed for `cargo-minimal-versions` to work
toolchain: "nightly"
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
- name: Install LLVM and Clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ env.LLVM_MAIN_VERSION }} main'
sudo apt update
sudo apt install llvm-${{ env.LLVM_MAIN_VERSION }} libpolly-${{ env.LLVM_MAIN_VERSION }}-dev
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- uses: cargo-bins/cargo-binstall@main
- name: Install cargo-minimal-versions
run: |
cargo binstall cargo-hack --force
cargo binstall cargo-minimal-versions --force
- name: Pin transitive dependencies not compatible with our MSRV
# Add new dependencies as needed if the check fails due to
# "package `XXX` cannot be built because it requires rustc YYY or newer, while the currently active rustc version is 1.91.0"
run: |
rm Cargo.lock
# cargo add -p tket insta@2.4.1
- name: Build with no features
run: cargo minimal-versions --direct test --verbose --no-default-features --no-run
- name: Tests with no features
run: cargo minimal-versions --direct test --verbose --no-default-features
- name: Build with all features
run: cargo minimal-versions --direct test --verbose --all-features --no-run
- name: Tests with all features
run: cargo minimal-versions --direct test --verbose --all-features
tests-py:
needs: changes
if: ${{ needs.changes.outputs.python == 'true' }}
runs-on: ubuntu-latest
name: tket-py tests (Python, coverage)
env:
PKGS: tket-py tket-eccs tket-exts
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- name: Install Python ${{ env.PYTHON_LOWEST }}
run: uv python install ${{ env.PYTHON_LOWEST }}
- name: Setup dependencies
# avoid building qis-compiler
run: uv sync --package=tket --exact --python ${{ env.PYTHON_LOWEST }}
- name: Run python tests with coverage instrumentation
run: uv run --no-project pytest --cov=./ --cov-report=xml ${{ env.PKGS }}
- name: Upload python coverage to codecov.io
if: github.event_name != 'merge_group'
uses: codecov/codecov-action@v6
with:
files: ./coverage.xml
# Ensures we only upload this file
disable_search: true
name: python
flags: python
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
tests-qis-compiler:
needs: changes
if: ${{ needs.changes.outputs.qis == 'true' }}
runs-on: ubuntu-latest
name: qis-compiler test
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
- name: Install LLVM and Clang
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ env.LLVM_MAIN_VERSION }} main'
sudo apt update
sudo apt install llvm-${{ env.LLVM_MAIN_VERSION }} libpolly-${{ env.LLVM_MAIN_VERSION }}-dev
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- name: Install Python ${{ env.PYTHON_LOWEST }}
run: uv python install ${{ env.PYTHON_LOWEST }}
- name: Run qis-compiler tests
run: uv run --python ${{ env.PYTHON_LOWEST }} --exact --package selene_hugr_qis_compiler pytest --cov=./ --cov-report=xml qis-compiler
- name: Upload python coverage to codecov.io
if: github.event_name != 'merge_group'
uses: codecov/codecov-action@v6
with:
files: ./coverage.xml
# Ensures we only upload this file
disable_search: true
name: python
flags: qis-compiler
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
# Ensure that serialized extensions match rust implementation
tket-extensions:
needs: [changes, tests-rs-stable-all-features]
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
name: Check standard extensions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: extractions/setup-just@v3
- name: Install tket-c-api library
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
- name: Generate the updated definitions
run: just gen-extensions
- name: Check if the declarations are up to date
run: |
git diff --exit-code --name-only tket-exts/src/tket_exts/data
if [ $? -ne 0 ]; then
echo "The serialized standard extensions are not up to date"
echo "Please run 'just gen-extensions' and commit the changes.
Bump the version of tket-exts according to semver.
"
exit 1
fi
extension-versions:
runs-on: ubuntu-latest
needs: [changes]
if: ${{ needs.changes.outputs.extensions == 'true' }}
name: Check extension versions
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Need full history to compare with main
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Check if extension versions are updated
run: |
# Check against latest tag on the target branch
# When not on a pull request, base_ref should be empty so we default to HEAD
if [ -z "$TARGET_REF" ]; then
BASE_SHA="HEAD~1"
else
BASE_SHA=$(git rev-parse origin/$TARGET_REF)
fi
echo "Comparing to ref: $BASE_SHA"
python ./scripts/check_extension_versions.py $BASE_SHA
env:
TARGET_REF: ${{ github.base_ref }}
# This is a meta job to mark successful completion of the required checks,
# even if they are skipped due to no changes in the relevant files.
required-checks:
name: Required checks 🦀+🐍
needs:
[
changes,
check-rs,
check-py,
tests-rs-stable-no-features,
tests-rs-stable-all-features,
tests-py,
tket-extensions,
extension-versions,
tests-qis-compiler,
]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Debug changes step output
run: |
echo "Rust: ${{ needs.changes.outputs.rust }}"
echo "Python: ${{ needs.changes.outputs.python }}"
- name: Fail if required checks failed
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: |
echo "Required checks failed"
echo "Please check the logs for more information"
exit 1
- name: Pass if required checks passed
run: |
echo "All required checks passed"