-
-
Notifications
You must be signed in to change notification settings - Fork 68
536 lines (463 loc) · 16.4 KB
/
ci.yml
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
name: CI
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
# Needed so we can run it manually
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
jobs:
ci-everything:
name: All CI stages
runs-on: ubuntu-latest
needs:
- lint
- rust-tests
- rust-fuzz
- rust-rustdoc-wasm
- python-tests
- wasm-tests
- js-lint
if: ${{ success() || failure() }} # Run this job even if a dependency has failed.
steps:
- name: Job outcomes
run: |
echo "lint: ${{ needs.lint.result }}"
echo "rust-tests: ${{ needs.rust-tests.result }}"
echo "rust-fuzz: ${{ needs.rust-fuzz.result }}"
echo "python-tests: ${{ needs.python-tests.result }}"
echo "wasm-tests: ${{ needs.wasm-tests.result }}"
echo "js-lint: ${{ needs.js-lint.result }}"
echo "rust-rustdoc-wasm: ${{ needs.rust-rustdoc-wasm.result }}"
# Fail this required job if any of its dependent jobs have failed.
#
# Do not attempt to consolidate these steps into one step, it won't work.
# Multi-line `if` clauses are not evaluated properly: see the intermediate commits in
# https://github.com/obi1kenobi/cargo-semver-checks/pull/405
- if: ${{ needs.lint.result != 'success' }}
run: exit 1
- if: ${{ needs.rust-tests.result != 'success' }}
run: exit 1
- if: ${{ needs.rust-fuzz.result != 'success' }}
run: exit 1
- if: ${{ needs.python-tests.result != 'success' }}
run: exit 1
- if: ${{ needs.wasm-tests.result != 'success' }}
run: exit 1
- if: ${{ needs.js-lint.result != 'success' }}
run: exit 1
- if: ${{ needs.rust-rustdoc-wasm.result != 'success' }}
run: exit 1
python-tests:
name: Python tests and maturin build
runs-on: ubuntu-latest
needs:
- rust-tests
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: pytrustfall/.venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
cd pytrustfall
poetry install --no-interaction --no-root
- name: maturin build and test
run: |
cd pytrustfall
source .venv/bin/activate
maturin develop
pytest
maturin build --interpreter python -o target/wheels/
- name: Set environment variables
id: branch-info
run: |
set -ex
echo "COMMIT=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "TAG_NAME=$(.github/workflows/get_py_prerelease_name.sh)" >> $GITHUB_OUTPUT
echo "PYTHON_BINDINGS_CHANGED=$(.github/workflows/python_bindings_changed.sh)" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
if: steps.branch-info.outputs.PYTHON_BINDINGS_CHANGED != 0
with:
name: pytrustfall-wheels
path: pytrustfall/target/wheels/
retention-days: 1
- name: Make a new prerelease
uses: ncipollo/release-action@v1
if: steps.branch-info.outputs.BRANCH_NAME == 'main' && steps.branch-info.outputs.PYTHON_BINDINGS_CHANGED != 0
with:
artifacts: "pytrustfall/target/wheels/*.whl,pytrustfall/target/wheels/*.tar.gz"
commit: ${{ steps.branch-info.outputs.COMMIT }}
tag: ${{ steps.branch-info.outputs.TAG_NAME }}
generateReleaseNotes: true
prerelease: true
token: ${{ secrets.GITHUB_TOKEN }}
lint:
name: Check lint and rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy
- name: cargo clippy
run: cargo clippy --workspace --all-features --all-targets --no-deps -- -D warnings --allow deprecated
- name: cargo fmt
run: cargo fmt -- --check
- name: cargo doc
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --workspace --all-features --no-deps --document-private-items
rust-tests:
name: Run tests
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: 0
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true
- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- name: Set up sccache
uses: mozilla-actions/sccache-action@v0.0.4
- name: Clear sccache stats
run: sccache --zero-stats
# Test all crates except trustfall_stubgen,
# which is only tested if it has changed since its tests are a bit long.
#
# `--all-targets` also tests example and bench targets, but explicitly excludes doctests.
# We'll test doctests separately in their own step.
# https://github.com/rust-lang/cargo/issues/6669
- name: cargo test
run: cargo test --workspace --all-targets --all-features --exclude trustfall_stubgen
# Run doctests separately, since `--all-targets` above explicitly excludes doctests.
# https://github.com/rust-lang/cargo/issues/6669
- name: run doctests
run: cargo test --workspace --all-features --doc
- name: test trustfall_stubgen if it has changed
run: |
git fetch origin main
# `git diff --quiet` exits non-zero if there are changes
git diff --quiet HEAD origin/main -- ./trustfall_stubgen || (cd trustfall_stubgen/ && cargo test --all-features)
- name: Show sccache stats
run: sccache --show-stats
rust-fuzz:
name: Check fuzz targets
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
./trustfall_core/fuzz
- name: cargo clippy
run: |
cd trustfall_core/fuzz
cargo clippy --workspace --all-features --all-targets --no-deps -- -D warnings --allow deprecated
- name: cargo fmt
run: |
cd trustfall_core/fuzz
cargo fmt -- --check
- name: cargo doc
env:
RUSTDOCFLAGS: -D warnings
run: |
cd trustfall_core/fuzz
cargo doc --workspace --all-features --no-deps --document-private-items
rust-rustdoc-wasm:
name: Check rustdoc WASM target
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
./experiments/trustfall_rustdoc
- name: cargo clippy
run: |
cd experiments/trustfall_rustdoc
cargo clippy --all-features --all-targets --no-deps -- -D warnings --allow deprecated
- name: cargo fmt
run: |
cd experiments/trustfall_rustdoc
cargo fmt -- --check
- name: cargo doc
env:
RUSTDOCFLAGS: -D warnings
run: |
cd experiments/trustfall_rustdoc
cargo doc --all-features --no-deps --document-private-items
wasm-tests:
name: WASM tests
runs-on: ubuntu-latest
needs:
- rust-tests
permissions:
contents: write
env:
CARGO_INCREMENTAL: 0
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Set up sccache
uses: mozilla-actions/sccache-action@v0.0.4
- name: Clear sccache stats
run: sccache --zero-stats
- name: Run cargo test and wasm-pack tests
run: |
cd trustfall_wasm
wasm-pack test --headless --firefox
wasm-pack test --headless --chrome
- name: Set environment variables
id: branch-info
run: |
set -ex
echo "COMMIT=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "TAG_NAME=$(.github/workflows/get_wasm_prerelease_name.sh)" >> $GITHUB_OUTPUT
echo "WASM_CHANGED=$(.github/workflows/wasm_pkg_changed.sh)" >> $GITHUB_OUTPUT
- name: Build WASM module
if: steps.branch-info.outputs.WASM_CHANGED != 0
run: |
cd trustfall_wasm
wasm-pack build --no-typescript
cp src/trustfall_wasm.d.ts pkg/
cd pkg/
tar -czvf ../trustfall_wasm.tar.gz --exclude='.gitignore' .
- name: Upload artifact
uses: actions/upload-artifact@v4
if: steps.branch-info.outputs.WASM_CHANGED != 0
with:
name: wasm-module
path: trustfall_wasm/pkg/
retention-days: 1
- name: Make a new prerelease
uses: ncipollo/release-action@v1
if: steps.branch-info.outputs.BRANCH_NAME == 'main' && steps.branch-info.outputs.WASM_CHANGED != 0
with:
artifacts: "trustfall_wasm/trustfall_wasm.tar.gz"
commit: ${{ steps.branch-info.outputs.COMMIT }}
tag: ${{ steps.branch-info.outputs.TAG_NAME }}
generateReleaseNotes: true
prerelease: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Show sccache stats
run: sccache --show-stats
js-lint:
name: Run JS linters
runs-on: ubuntu-latest
defaults:
run:
working-directory: experiments/schemaless_wasm/www/
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust + caching # necessary for `npm run build:wasm` later
uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build wasm package
run: npm run build:wasm
- name: Run linters
run: npm run lint
pre-publish-checks:
name: pre-publish checks
if: github.ref == 'refs/heads/main'
needs:
- ci-everything
- check-trustfall-examples-and-expensive-tests
runs-on: ubuntu-latest
steps:
- run: exit 0
check-trustfall-examples-and-expensive-tests:
name: pre-publish checks
if: github.ref == 'refs/heads/main'
needs:
- rust-tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false
rustflags: ""
- name: Publishing?
id: version
run: |
set +e
.github/workflows/is_crate_version_already_uploaded.sh trustfall
export TRUSTFALL="$?"
.github/workflows/is_crate_version_already_uploaded.sh trustfall_core
export TRUSTFALL_CORE="$?"
.github/workflows/is_crate_version_already_uploaded.sh trustfall_derive
export TRUSTFALL_DERIVE="$?"
if [[ "$TRUSTFALL" == "7" && "$TRUSTFALL_CORE" == "7" && "$TRUSTFALL_DERIVE" == "7" ]]; then
echo 'is_new_version=no' >> $GITHUB_OUTPUT
elif [[ "$TRUSTFALL" == "0" || "$TRUSTFALL_CORE" == "0" || "$TRUSTFALL_DERIVE" == "0" ]]; then
echo 'is_new_version=yes' >> $GITHUB_OUTPUT
else
# Unexpected outcome, indicates a bug.
exit 1
fi
- uses: Swatinem/rust-cache@v2
if: steps.version.outputs.is_new_version == 'yes'
- name: feeds example
if: steps.version.outputs.is_new_version == 'yes'
run: |
cd trustfall
cargo run --example feeds refresh
cargo run --example feeds query ./examples/feeds/example_queries/feed_content.ron
cargo run --example feeds query ./examples/feeds/example_queries/feed_links.ron
cargo run --example feeds query ./examples/feeds/example_queries/game_reviews.ron
- name: hackernews example
if: steps.version.outputs.is_new_version == 'yes'
run: |
cd trustfall
cargo run --example hackernews query ./examples/hackernews/example_queries/front_page_stories_with_links.ron 1
cargo run --example hackernews query ./examples/hackernews/example_queries/latest_links_by_high_karma_users.ron 1
- name: weather example
if: steps.version.outputs.is_new_version == 'yes'
run: |
cd trustfall
cargo run --example weather refresh
cargo run --example weather query ./examples/weather/example_queries/boston_weather.ron
cargo run --example weather query ./examples/weather/example_queries/high_winds.ron
- name: trustfall_stubgen tests
if: steps.version.outputs.is_new_version == 'yes'
run: |
cd trustfall_stubgen
cargo test --all-features --all-targets
attempt-publish-trustfall-filetests-macros:
name: publish trustfall_filetests_macros
if: github.ref == 'refs/heads/main'
needs:
- pre-publish-checks
uses: ./.github/workflows/publish-rust.yml
with:
crate-name: trustfall_filetests_macros
secrets:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
attempt-publish-trustfall-core:
name: publish trustfall_core
if: github.ref == 'refs/heads/main'
needs:
- pre-publish-checks
- attempt-publish-trustfall-filetests-macros
uses: ./.github/workflows/publish-rust.yml
with:
crate-name: trustfall_core
secrets:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
attempt-publish-trustfall-derive:
name: publish trustfall_derive
if: github.ref == 'refs/heads/main'
needs:
- pre-publish-checks
- attempt-publish-trustfall-core
uses: ./.github/workflows/publish-rust.yml
with:
crate-name: trustfall_derive
secrets:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
attempt-publish-trustfall:
name: publish trustfall
if: github.ref == 'refs/heads/main'
needs:
- pre-publish-checks
- attempt-publish-trustfall-core
- attempt-publish-trustfall-derive
uses: ./.github/workflows/publish-rust.yml
with:
crate-name: trustfall
secrets:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
attempt-publish-trustfall-stubgen:
name: publish trustfall_stubgen
if: github.ref == 'refs/heads/main'
needs:
- pre-publish-checks
- attempt-publish-trustfall
uses: ./.github/workflows/publish-rust.yml
with:
crate-name: trustfall_stubgen
secrets:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
attempt-publish-pytrustfall:
name: publish python trustfall
if: github.ref == 'refs/heads/main'
needs:
- pre-publish-checks
- attempt-publish-trustfall-core
uses: ./.github/workflows/publish-python.yml