-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
559 lines (471 loc) · 16.1 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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
name: CI
on:
merge_group:
pull_request:
types: ["opened", "reopened", "synchronize"]
push:
branches:
- main
env:
CI: 1
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: "always"
DIFF: 0
# For faster CI
RUST_LOG: "off"
# https://github.com/actions/setup-node/issues/899#issuecomment-1819151595
SKIP_YARN_COREPACK_CHECK: 1
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: "${{ github.event_name == 'pull_request' }}"
jobs:
cargo-fmt:
name: Cargo fmt
runs-on: ubuntu-latest
env:
RUST_LOG: "0"
steps:
- uses: actions/checkout@v4
# We explicitly do this to cache properly.
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt
- run: cargo fmt --all -- --check
cargo-clippy:
name: Cargo clippy
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: clippy
- run: cargo clippy --all --all-targets -- -D warnings
cargo-deny:
name: Check license of dependencies
runs-on: ubuntu-latest
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
- name: Install cargo-deny
uses: taiki-e/install-action@v2
with:
tool: [email protected]
- name: Check licenses
run: |
cargo deny check
cargo-check:
name: Check
runs-on: ${{ matrix.os }}
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
# We explicitly do this to cache properly.
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
# MSRV is current stable for ES crates and nightly for other languages
# toolchain: stable
# override: true
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "yarn"
- name: Install node dependencies
shell: bash
run: |
corepack enable
yarn
# Ensure that all components are compilable.
- name: Run cargo check for all targets
run: cargo check --all --all-targets
test-wasm:
name: Test wasm
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pkg:
- binding_core_wasm
- binding_minifier_wasm
- binding_typescript_wasm
steps:
- uses: actions/checkout@v4
- shell: bash
run: corepack enable
# We explicitly do this to cache properly.
- uses: actions-rs/toolchain@v1
with:
profile: minimal
- name: Patch
shell: bash
run: |
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update -p swc_core -p swc_fast_ts_strip
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "yarn"
- name: Install node dependencies
shell: bash
run: |
corepack enable
yarn
- name: Test
run: |
(cd bindings/${{ matrix.pkg }} && ./scripts/test.sh)
list-cargo-tests:
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
name: List crates
runs-on: ubuntu-latest
outputs:
settings: ${{ steps.list-tests.outputs.settings }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node
- name: List crates
id: list-tests
run: echo "settings=$(npx zx ./scripts/github/get-test-matrix.mjs)" >> $GITHUB_OUTPUT
cargo-test:
name: Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }}
runs-on: ${{ matrix.settings.os }}
needs:
- list-cargo-tests
strategy:
fail-fast: false
matrix:
settings: ${{fromJson(needs.list-cargo-tests.outputs.settings)}}
steps:
- name: Handle line endings
shell: bash
if: runner.os == 'Windows'
run: |
git config --system core.autocrlf false
git config --system core.eol lf
- uses: actions/checkout@v4
with:
submodules: true
- run: corepack enable
# Source map format
- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "yarn"
# We explicitly do this to cache properly.
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
target: wasm32-wasi
# MSRV is current stable for ES crates and nightly for other languages
# toolchain: stable
# override: true
- uses: denoland/setup-deno@v1
if: matrix.settings.crate == 'swc_bundler'
with:
deno-version: v1.x
- name: Install node dependencies
shell: bash
run: |
corepack enable
yarn
# I don't want to think deeply about this
yarn global add jest@27 mocha || \
yarn global add jest@27 mocha || \
yarn global add jest@27 mocha || \
yarn global add jest@27 mocha || \
yarn global add jest@27 mocha || \
yarn global add jest@27 mocha || \
yarn global add jest@27 mocha || \
yarn global add jest@27 mocha || true
- name: Configure path (windows)
shell: bash
if: runner.os == 'Windows'
run: |
echo $(yarn global bin) >> $GITHUB_PATH
- name: Verify dependencies
shell: bash
run: |
yarn jest --version && yarn mocha --version
- name: Configure execution cache
shell: bash
run: |
mkdir -p .swc-exec-cache
echo "SWC_ECMA_TESTING_CACHE_DIR=$(pwd)/.swc-exec-cache" >> $GITHUB_ENV
- name: Cache execution results
uses: actions/cache@v3
if: ${{ matrix.settings.crate }} == 'swc' || ${{ startsWith(matrix.settings.crate, 'swc_ecma_transforms_') }}
with:
path: |
.swc-exec-cache
key: swc-exec-cache-${{ matrix.settings.crate }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
swc-exec-cache-${{ matrix.settings.crate }}
- name: Run cargo test
if: matrix.settings.crate != 'swc_plugin_runner' && matrix.settings.crate != 'swc_ecma_parser' && matrix.settings.crate != 'swc_ecma_minifier' && matrix.settings.crate != 'swc_core' && matrix.settings.crate != 'swc_ecma_quote' && matrix.settings.crate != 'swc_cli' && matrix.settings.crate != 'binding_core_wasm'
run: |
cargo test -p ${{ matrix.settings.crate }}
- name: Run cargo test (core)
if: matrix.settings.crate == 'swc_core'
run: |
rustup target add wasm32-unknown-unknown
cargo test -p swc_core --features ecma_quote --features common --features ecma_utils
- name: Run cargo test (binding_core_wasm)
if: matrix.settings.crate == 'binding_core_wasm'
run: |
cargo test --manifest-path ./bindings/binding_core_wasm/Cargo.toml
- name: Run cargo test (cli)
if: matrix.settings.crate == 'swc_cli'
run: |
cargo test --manifest-path ./bindings/swc_cli/Cargo.toml --features plugin
- name: Run cargo test (plugin)
if: matrix.settings.crate == 'swc_plugin_runner'
run: |
# export CARGO_TARGET_DIR=$(pwd)/target
cargo test -p swc_plugin_runner --release --features plugin_transform_schema_v1 --features rkyv-impl --features ecma --features css
- name: Run cargo test (swc_ecma_minifier)
if: matrix.settings.crate == 'swc_ecma_minifier'
run: |
cargo test -p swc_ecma_minifier --features concurrent
- name: Run cargo test (swc_ecma_parser)
if: matrix.settings.crate == 'swc_ecma_parser'
run: |
cargo test -p swc_ecma_parser --features verify
- name: Run cargo test (all features)
if: matrix.settings.crate == 'swc_ecma_parser' || matrix.settings.crate == 'swc_ecma_loader'
run: |
cargo test -p ${{ matrix.settings.crate }} --all-features
- name: Run cargo test (transforms with stacker)
if: matrix.settings.crate == 'swc_ecma_transforms'
run: |
cargo test -p ${{ matrix.settings.crate }} --all-features --features swc_ecma_utils/stacker
- name: Run cargo test (concurrent)
if: runner.os == 'Linux' && matrix.settings.crate != 'swc_ecma_minifier'
shell: bash
run: |
./scripts/github/test-concurrent.sh ${{ matrix.settings.crate }}
- name: Install cargo-hack
uses: taiki-e/install-action@v2
if: matrix.settings.os == 'ubuntu-latest'
with:
tool: [email protected]
- name: Check compilation
if: matrix.settings.os == 'ubuntu-latest'
run: |
./scripts/github/run-cargo-hack.sh ${{ matrix.settings.crate }}
node-test:
name: Test node bindings - ${{ matrix.os }}
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
# - ubuntu-latest
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@v4
- shell: bash
run: corepack enable
# We explicitly do this to cache properly.
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "yarn"
- name: Patch
shell: bash
run: |
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update -p swc_core -p swc_fast_ts_strip
- name: Set platform name
run: |
export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
echo "PLATFORM_NAME=$NODE_PLATFORM_NAME" >> $GITHUB_ENV
shell: bash
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Prepare
run: |
rustup target add wasm32-wasi
corepack enable
yarn
- name: Build
working-directory: packages/core
run: |
yarn build:dev
- name: Test
working-directory: packages/core
run: |
yarn test
integration-test:
name: "Test with @swc/cli"
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- shell: bash
run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "yarn"
- name: Set platform name
run: |
export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
echo "PLATFORM_NAME=$NODE_PLATFORM_NAME" >> $GITHUB_ENV
shell: bash
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Patch
shell: bash
run: |
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update -p swc_core -p swc_fast_ts_strip
- name: Prepare
run: |
rustup target add wasm32-wasi
corepack enable
yarn
yarn build:dev
# Avoid no space left on device, copyfile
cargo clean
(cd ./bindings && cargo clean)
npm install -g @swc/[email protected]
npm link
npm install -g file:$PWD
- name: Print info
run: |
npm list -g
- name: (swc) three.js
run: |
# mkdir -p tests/integration/three-js
# yarn global add qunit failonlyreporter
# Download three.js
# git clone --depth 1 https://github.com/mrdoob/three.js.git -b r117 tests/integration/three-js/repo
# TODO
# swc -C isModule=unknown -C test=\".*.js$\" -C module.type=commonjs --sync tests/integration/three-js/repo/ -d tests/integration/three-js/build/
# TODO
# (cd tests/integration/three-js/build/test && qunit -r failonlyreporter unit/three.source.unit.js)
# terser: contains with statement in test
# Rome.js: I forgot the cause, but it didn't work.
# jQuery: browser only (window.document is required)
- name: (swc) redux
run: |
# mkdir -p tests/integration/redux
# yarn global add qunit failonlyreporter
# Download
# git clone --depth 1 https://github.com/reduxjs/redux.git -b v4.1.0 tests/integration/redux/repo
# TODO
# swc --sync tests/integration/redux/repo/src/ -d tests/integration/redux/repo/lib/
# echo "module.exports=require('./index')" > tests/integration/redux/repo/lib/redux.js
# TODO
# swc --sync tests/integration/redux/repo/src/ -d tests/integration/redux/repo/test/
# TODO
# swc --sync tests/integration/redux/repo/test/ -d tests/integration/redux/repo/test/
# TODO
# (cd tests/integration/redux/repo && yarn)
# TODO
# (cd tests/integration/redux/repo && npx jest '.*.js' --modulePathIgnorePatterns 'typescript')
- name: (swcpack) example react app
run: |
export NODE_OPTIONS="--unhandled-rejections=warn"
(cd crates/swc_node_bundler/tests/integration/react && npm install && npx spack)
miri:
name: Miri
runs-on: ubuntu-latest
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
strategy:
fail-fast: false
matrix:
crate:
- better_scoped_tls
- string_enum
- swc
- swc_bundler
- swc_ecma_codegen
- swc_ecma_minifier
steps:
- uses: actions/checkout@v4
with:
submodules: true
- shell: bash
run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "yarn"
- name: Install node dependencies
shell: bash
run: |
corepack enable
yarn
- name: Print rustup toolchain version
shell: bash
id: rustup-version
run: |
export RUST_TOOLCHAIN="$(cat rust-toolchain | tr -d '\n')"
echo "Rust toolchain: $RUST_TOOLCHAIN"
echo "RUST_TOOLCHAIN=$RUST_TOOLCHAIN" >> "$GITHUB_OUTPUT"
- name: Install
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "${{ steps.rustup-version.outputs.RUST_TOOLCHAIN }}"
components: miri
- run: cargo miri test -p ${{ matrix.crate }} --no-fail-fast
continue-on-error: true
env:
MIRIFLAGS: "-Zmiri-disable-isolation"
done:
needs:
- cargo-fmt
- cargo-clippy
- cargo-deny
- cargo-check
- test-wasm
- cargo-test
- node-test
- integration-test
if: >-
${{ always() && !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ubuntu-latest
name: Done
steps:
- run: exit 1
if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'skipped') || contains(needs.*.result, 'cancelled')) }}