-
Notifications
You must be signed in to change notification settings - Fork 94
417 lines (340 loc) · 16 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
env:
# We aim to always test with the latest stable Rust toolchain, however we pin to a specific
# version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still
# come automatically. If the version specified here is no longer the latest stable version,
# then please feel free to submit a PR that adjusts it along with the potential clippy fixes.
RUST_STABLE_VER: "1.82" # In quotes because otherwise (e.g.) 1.70 would be interpreted as 1.7
# The purpose of checking with the minimum supported Rust toolchain is to detect its staleness.
# If the compilation fails, then the version specified here needs to be bumped up to reality.
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
# plus all the README.md files of the affected packages.
RUST_MIN_VER: "1.82"
# List of packages that will be checked with the minimum supported Rust version.
# This should be limited to packages that are intended for publishing.
RUST_MIN_VER_PKGS: "-p piet -p piet-common -p piet-cairo -p piet-coregraphics -p piet-direct2d -p piet-svg -p piet-web"
# List of packages that can not target Wasm.
NO_WASM_PKGS: "--exclude piet-cairo --exclude piet-coregraphics --exclude piet-direct2d --exclude piet-svg"
# List of packages that can not target Windows.
NO_WINDOWS_PKGS: "--exclude piet-cairo --exclude piet-coregraphics --exclude piet-web"
# List of packages that can not target macOS.
NO_MACOS_PKGS: "--exclude piet-cairo --exclude piet-direct2d --exclude piet-web"
# List of packages that can not target Ubuntu.
NO_UBUNTU_PKGS: "--exclude piet-coregraphics --exclude piet-direct2d --exclude piet-web"
# Rationale
#
# We don't run clippy with --all-targets because then even --lib and --bins are compiled with
# dev dependencies enabled, which does not match how they would be compiled by users.
# A dev dependency might enable a feature that we need for a regular dependency,
# and checking with --all-targets would not find our feature requirements lacking.
# This problem still applies to cargo resolver version 2.
# Thus we split all the targets into two steps, one with --lib --bins
# and another with --tests --benches --examples.
# Also, we can't give --lib --bins explicitly because then cargo will error on binary-only packages.
# Luckily the default behavior of cargo with no explicit targets is the same but without the error.
#
# We use cargo-hack for a similar reason. Cargo's --workspace will do feature unification across
# the whole workspace. While cargo-hack will instead check each workspace package separately.
#
# Using cargo-hack also allows us to more easily test the feature matrix of our packages.
# We use --each-feature & --optional-deps which will run a separate check for every feature.
#
# The MSRV jobs run only cargo check because different clippy versions can disagree on goals and
# running tests introduces dev dependencies which may require a higher MSRV than the bare package.
#
# We don't save caches in the merge-group cases, because those caches will never be re-used (apart
# from the very rare cases where there are multiple PRs in the merge queue).
# This is because GitHub doesn't share caches between merge queues and the main branch.
name: CI
on:
pull_request:
merge_group:
# We run on push, even though the commit is the same as when we ran in merge_group.
# This allows the cache to be primed.
# See https://github.com/orgs/community/discussions/66430
push:
branches:
- main
jobs:
fmt:
name: formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
components: rustfmt
- name: cargo fmt
run: cargo fmt --all --check
- name: install ripgrep
run: |
sudo apt update
sudo apt install ripgrep
- name: check copyright headers
run: bash .github/copyright.sh
clippy-stable:
name: cargo clippy
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
components: clippy
- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- name: install native dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update; sudo apt-get install libgtk-3-dev
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
- name: cargo clippy (windows)
run: cargo hack clippy --workspace ${{ env.NO_WINDOWS_PKGS }} --locked --optional-deps --each-feature -- -D warnings
if: contains(matrix.os, 'windows')
- name: cargo clippy (auxiliary) (windows)
run: cargo hack clippy --workspace ${{ env.NO_WINDOWS_PKGS }} --locked --optional-deps --each-feature --tests --benches --examples -- -D warnings
if: contains(matrix.os, 'windows')
- name: cargo clippy (macos)
run: cargo hack clippy --workspace ${{ env.NO_MACOS_PKGS }} --locked --optional-deps --each-feature -- -D warnings
if: contains(matrix.os, 'macos')
- name: cargo clippy (auxiliary) (macos)
run: cargo hack clippy --workspace ${{ env.NO_MACOS_PKGS }} --locked --optional-deps --each-feature --tests --benches --examples -- -D warnings
if: contains(matrix.os, 'macos')
- name: cargo clippy (ubuntu)
run: cargo hack clippy --workspace ${{ env.NO_UBUNTU_PKGS }} --locked --optional-deps --each-feature -- -D warnings
if: contains(matrix.os, 'ubuntu')
- name: cargo clippy (auxiliary) (ubuntu)
run: cargo hack clippy --workspace ${{ env.NO_UBUNTU_PKGS }} --locked --optional-deps --each-feature --tests --benches --examples -- -D warnings
if: contains(matrix.os, 'ubuntu')
clippy-stable-wasm:
name: cargo clippy (wasm32)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
targets: wasm32-unknown-unknown
components: clippy
- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
- name: cargo clippy
run: cargo hack clippy --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --optional-deps --each-feature -- -D warnings
- name: cargo clippy (auxiliary)
run: cargo hack clippy --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --optional-deps --each-feature --tests --benches --examples -- -D warnings
test-stable:
name: cargo test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
- name: install native dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update; sudo apt-get install libgtk-3-dev
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
- name: cargo test (windows)
run: cargo test --workspace ${{ env.NO_WINDOWS_PKGS }} --locked --all-features
if: contains(matrix.os, 'windows')
- name: cargo test (macos)
run: cargo test --workspace ${{ env.NO_MACOS_PKGS }} --locked --all-features
if: contains(matrix.os, 'macos')
- name: cargo test (ubuntu)
run: cargo test --workspace ${{ env.NO_UBUNTU_PKGS }} --locked --all-features
if: contains(matrix.os, 'ubuntu')
test-stable-wasm:
name: cargo test (wasm32)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
targets: wasm32-unknown-unknown
- name: install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
# TODO: Find a way to make tests work. Until then the tests are merely compiled.
- name: cargo test compile
run: cargo test --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --all-features --no-run
- name: test chrome
run: wasm-pack test --headless --chrome piet-common
- name: test firefox
run: wasm-pack test --headless --firefox piet-common
check-msrv:
name: cargo check (msrv)
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: install msrv toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_MIN_VER }}
- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- name: install native dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update; sudo apt-get install libgtk-3-dev
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
- name: cargo check (windows)
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} ${{ env.NO_WINDOWS_PKGS }} --locked --optional-deps --each-feature
if: contains(matrix.os, 'windows')
- name: cargo check (macos)
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} ${{ env.NO_MACOS_PKGS }} --locked --optional-deps --each-feature
if: contains(matrix.os, 'macos')
- name: cargo check (ubuntu)
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} ${{ env.NO_UBUNTU_PKGS }} --locked --optional-deps --each-feature
if: contains(matrix.os, 'ubuntu')
check-msrv-wasm:
name: cargo check (msrv) (wasm32)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install msrv toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_MIN_VER }}
targets: wasm32-unknown-unknown
- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
- name: cargo check
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --optional-deps --each-feature
doc:
name: cargo doc
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: install nightly toolchain
uses: dtolnay/rust-toolchain@nightly
- name: install native dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update; sudo apt-get install libgtk-3-dev
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
# We test documentation using nightly to match docs.rs. This prevents potential breakages
- name: cargo doc (windows)
run: cargo doc --workspace ${{ env.NO_WINDOWS_PKGS }} --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples
if: contains(matrix.os, 'windows')
- name: cargo doc (macos)
run: cargo doc --workspace ${{ env.NO_MACOS_PKGS }} --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples
if: contains(matrix.os, 'macos')
- name: cargo doc (ubuntu)
run: cargo doc --workspace ${{ env.NO_UBUNTU_PKGS }} --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples
if: contains(matrix.os, 'ubuntu')
- name: cargo doc (wasm32)
run: cargo doc --workspace ${{ env.NO_WASM_PKGS }} --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples --target wasm32-unknown-unknown
if: contains(matrix.os, 'ubuntu')
# If this fails, consider changing your text or adding something to .typos.toml
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: check typos
uses: crate-ci/[email protected]
compare-snapshots:
name: compare snapshots
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: 'true'
- name: install native dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update; sudo apt-get install libgtk-3-dev
- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}
# The use of always() allows for multiple scale factor steps to always run even if one of them fails.
- name: generate and compare (1.00) (ubuntu+cairo)
run: cargo run --manifest-path=piet-cairo/Cargo.toml --example=test-picture -- --all --scale=1 --out=cairo_samples --compare=./piet/snapshots/cairo
if: contains(matrix.os, 'ubuntu') && always()
- name: generate and compare (2.00) (ubuntu+cairo)
run: cargo run --manifest-path=piet-cairo/Cargo.toml --example=test-picture -- --all --scale=2 --out=cairo_samples --compare=./piet/snapshots/cairo
if: contains(matrix.os, 'ubuntu') && always()
- name: upload failures (ubuntu+cairo)
uses: actions/upload-artifact@v4
with:
name: cairo-failure
path: cairo_samples
if: contains(matrix.os, 'ubuntu') && failure()
- name: generate and compare (1.00) (macos)
run: cargo run --manifest-path=piet-coregraphics/Cargo.toml --example=test-picture -- --all --scale=1 --out=coregraphics_samples --compare=./piet/snapshots/coregraphics
if: contains(matrix.os, 'macos') && always()
- name: generate and compare (2.00) (macos)
run: cargo run --manifest-path=piet-coregraphics/Cargo.toml --example=test-picture -- --all --scale=2 --out=coregraphics_samples --compare=./piet/snapshots/coregraphics
if: contains(matrix.os, 'macos') && always()
- name: upload failures (macos)
uses: actions/upload-artifact@v4
with:
name: coregraphics-failure
path: coregraphics_samples
if: contains(matrix.os, 'macos') && failure()
- name: generate and compare (1.00) (d2d)
run: cargo run --manifest-path=piet-direct2d/Cargo.toml --example=test-picture -- --all --scale=1 --out=d2d_samples --compare=./piet/snapshots/d2d
if: contains(matrix.os, 'windows') && always()
- name: generate and compare (2.00) (d2d)
run: cargo run --manifest-path=piet-direct2d/Cargo.toml --example=test-picture -- --all --scale=2 --out=d2d_samples --compare=./piet/snapshots/d2d
if: contains(matrix.os, 'windows') && always()
- name: upload failures (d2d)
uses: actions/upload-artifact@v4
with:
name: d2d-failure
path: d2d_samples
if: contains(matrix.os, 'windows') && failure()