forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
562 lines (477 loc) · 18.4 KB
/
ci.yml
File metadata and controls
562 lines (477 loc) · 18.4 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
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
560
561
562
name: CI
on:
push:
branches: [master, 11.0_release]
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-*"
pull_request:
branches: [master, 11.0_release]
concurrency:
group: ci-${{ github.ref }}-1
# Cancel previous builds for pull requests only.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
OCAMLRUNPARAM: b
jobs:
build-rewatch:
strategy:
fail-fast: false
matrix:
include:
- os: macos-13 # x64
rust-target: x86_64-apple-darwin
node-target: darwin-x64
- os: macos-14 # ARM
rust-target: aarch64-apple-darwin
node-target: darwin-arm64
- os: ubuntu-24.04 # x64
rust-target: x86_64-unknown-linux-musl
node-target: linux-x64
- os: ubuntu-24.04-arm # ARM
rust-target: aarch64-unknown-linux-musl
node-target: linux-arm64
- os: windows-latest
rust-target: x86_64-pc-windows-gnu
node-target: win32-x64
runs-on: ${{matrix.os}}
env:
RUST_BACKTRACE: "1"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Restore build cache
id: build-cache
uses: actions/cache@v4
with:
path: rewatch/target
key: rewatch-build-v2-${{ matrix.rust-target }}-${{ hashFiles('rewatch/src/**', 'rewatch/Cargo.lock') }}
- name: Install musl gcc
if: steps.build-cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: sudo apt-get install -y --no-install-recommends musl-tools
- name: Install rust toolchain
if: steps.build-cache.outputs.cache-hit != 'true'
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{ matrix.rust-target }}
- name: Build rewatch
if: steps.build-cache.outputs.cache-hit != 'true'
run: |
cargo build --manifest-path rewatch/Cargo.toml --target ${{ matrix.rust-target }} --release
- name: Copy rewatch binary
run: |
cp rewatch/target/${{ matrix.rust-target }}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch.exe
shell: bash
- name: "Upload artifact: rewatch binary"
uses: actions/upload-artifact@v4
with:
name: rewatch-${{ matrix.node-target }}
path: rewatch.exe
if-no-files-found: error
build-compiler:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04 # x64
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
upload_binaries: true
upload_libs: true
node-target: linux-x64
- os: ubuntu-24.04-arm # ARM
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
upload_binaries: true
# Build the playground compiler and run the benchmarks on the fastest runner
build_playground: true
benchmarks: true
node-target: linux-arm64
- os: macos-13 # x64
ocaml_compiler: 5.3.0
upload_binaries: true
node-target: darwin-x64
- os: macos-14 # ARM
ocaml_compiler: 5.3.0
upload_binaries: true
node-target: darwin-arm64
- os: windows-latest
ocaml_compiler: 5.3.0
upload_binaries: true
node-target: win32-x64
# Verify that the compiler still builds with older OCaml versions
- os: ubuntu-24.04
ocaml_compiler: ocaml-variants.5.2.1+options,ocaml-option-static
- os: ubuntu-24.04
ocaml_compiler: ocaml-variants.5.0.0+options,ocaml-option-static
- os: ubuntu-24.04
ocaml_compiler: ocaml-variants.4.14.2+options,ocaml-option-static
runs-on: ${{matrix.os}}
env:
# setup-ocaml opam version cannot be configured
# we do track its version manually
OPAM_VERSION: 2.3.0
DUNE_PROFILE: release
steps:
- name: "Windows: Set git config"
if: runner.os == 'Windows'
run: |
git config --system core.autocrlf false
git config --system core.eol lf
git config --system core.longpaths true
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: yarn
node-version-file: .nvmrc
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
uses: awalsh128/cache-apt-pkgs-action@v1.4.3
with:
# See https://github.com/ocaml/setup-ocaml/blob/b2105f9/packages/setup-ocaml/src/unix.ts#L9
packages: bubblewrap darcs g++-multilib gcc-multilib mercurial musl-tools rsync
version: v3
# matrix.ocaml_compiler may contain commas
- name: Get OPAM cache key
shell: bash
run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" | sed 's/,/-/g' >> $GITHUB_ENV
- name: Restore OPAM environment
id: cache-opam-env
uses: actions/cache/restore@v4
with:
path: |
${{ runner.tool_cache }}/opam
~/.opam
_opam
.opam-path
D:\cygwin
D:\.opam
key: ${{ env.opam_cache_key }}
- name: Use OCaml ${{matrix.ocaml_compiler}}
uses: ocaml/setup-ocaml@v3.2.5
if: steps.cache-opam-env.outputs.cache-hit != 'true'
with:
ocaml-compiler: ${{matrix.ocaml_compiler}}
opam-pin: false
- name: Get OPAM executable path
if: steps.cache-opam-env.outputs.cache-hit != 'true'
uses: actions/github-script@v7
with:
script: |
const opamPath = await io.which('opam', true);
console.log('opam executable found: %s', opamPath);
const fs = require('fs/promises');
await fs.writeFile('.opam-path', opamPath, 'utf-8');
console.log('stored path to .opam-path');
- name: Install OPAM dependencies
if: steps.cache-opam-env.outputs.cache-hit != 'true'
run: opam install . --deps-only --with-test
- name: Cache OPAM environment
if: steps.cache-opam-env.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
${{ runner.tool_cache }}/opam
~/.opam
_opam
.opam-path
D:\cygwin
D:\.opam
key: ${{ env.opam_cache_key }}
- name: Use cached OPAM environment
if: steps.cache-opam-env.outputs.cache-hit == 'true'
run: |
# https://github.com/ocaml/setup-ocaml/blob/b2105f9/packages/setup-ocaml/src/installer.ts#L33
echo "OPAMVERBOSE=$RUNNER_DEBUG" >> "$GITHUB_ENV"
echo "OPAMCOLOR=always" >> "$GITHUB_ENV"
echo "OPAMCONFIRMLEVEL=unsafe-yes" >> "$GITHUB_ENV"
echo "OPAMERRLOGLEN=0" >> "$GITHUB_ENV"
echo "OPAMPRECISETRACKING=1" >> "$GITHUB_ENV"
echo "OPAMYES=1" >> "$GITHUB_ENV"
if [[ "$RUNNER_OS" != "Windows" ]]; then
echo "OPAMROOT=$HOME/.opam" >> "$GITHUB_ENV"
else
echo "OPAMROOT=D:\\.opam" >> "$GITHUB_ENV"
fi
OPAM_PATH="$(cat .opam-path)"
chmod +x "$OPAM_PATH"
dirname "$OPAM_PATH" >> "$GITHUB_PATH"
if [[ "$RUNNER_OS" == "Windows" ]]; then
fsutil behavior query SymlinkEvaluation
fsutil behavior set symlinkEvaluation R2L:1 R2R:1
fsutil behavior query SymlinkEvaluation
CYGWIN="winsymlinks:native"
CYGWIN_ROOT="D:\\cygwin"
CYGWIN_ROOT_BIN="D:\\cygwin\\bin"
CYGWIN_ROOT_WRAPPERBIN="D:\\cygwin\\wrapperbin"
echo "HOME=$USERPROFILE" >> "$GITHUB_ENV"
echo "MSYS=winsymlinks:native" >> "$GITHUB_ENV"
echo "CYGWIN=$CYGWIN" >> "$GITHUB_ENV"
echo "CYGWIN_ROOT=$CYGWIN_ROOT" >> "$GITHUB_ENV"
echo "CYGWIN_ROOT_BIN=$CYGWIN_ROOT_BIN" >> "$GITHUB_ENV"
echo "CYGWIN_ROOT_WRAPPERBIN=$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_ENV"
echo "$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_PATH"
fi
shell: bash
- name: Compiler build state key
id: compiler-build-state-key
shell: bash
run: |
echo "value=compiler-build-state-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" \
| sed 's/,/-/g' >> "$GITHUB_OUTPUT"
- name: Restore compiler build state
if: github.base_ref == 'master' || github.ref == 'refs/heads/master'
id: compiler-build-state
uses: actions/cache/restore@v4
with:
path: |
D:\.cache\dune
~/.cache/dune
_build
key: ${{ steps.compiler-build-state-key.outputs.value }}
- name: Build compiler
if: runner.os != 'Linux'
run: opam exec -- dune build --display quiet --profile release
- name: Build compiler (Linux static)
if: runner.os == 'Linux'
run: opam exec -- dune build --display quiet --profile static
- name: Delete stable compiler build state
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
shell: bash
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete ${{ steps.compiler-build-state-key.outputs.value }} \
-R ${{ github.repository }} \
-B ${{ github.ref }} \
--confirm || echo "not exist"
env:
GH_TOKEN: ${{ github.token }}
- name: Save compiler build state
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: actions/cache/save@v4
with:
path: |
D:\.cache\dune
~/.cache/dune
_build
key: ${{ steps.compiler-build-state-key.outputs.value }}
- name: Install npm packages
run: yarn install
- name: Copy compiler exes to platform bin dir
run: node scripts/copyExes.js --compiler
- name: Restore ninja build cache
id: ninja-build-cache
uses: actions/cache@v4
with:
path: packages/@rescript/${{ matrix.node-target }}/bin/ninja.exe
key: ninja-build-v1-${{ matrix.os }}-${{ hashFiles('ninja/src/**') }}
- name: Setup Python for ninja build
if: steps.ninja-build-cache.outputs.cache-hit != 'true'
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Setup MSVC for ninja build (Windows)
if: steps.ninja-build-cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64
- name: Build ninja
if: steps.ninja-build-cache.outputs.cache-hit != 'true' && runner.os != 'Linux'
run: node scripts/buildNinjaBinary.js
- name: Build ninja (Linux static)
if: steps.ninja-build-cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
env:
LDFLAGS: -static
run: node scripts/buildNinjaBinary.js
- name: Copy ninja exe to platform bin dir
if: steps.ninja-build-cache.outputs.cache-hit != 'true'
run: node scripts/copyExes.js --ninja
- name: "Syntax: Run roundtrip tests"
if: ${{ runner.os != 'Windows' }}
run: opam exec -- make test-syntax-roundtrip
- name: "Syntax: Run tests (Windows)"
if: ${{ runner.os == 'Windows' }}
run: opam exec -- make test-syntax
- name: Build runtime/stdlib
run: ./scripts/buildRuntime.sh
shell: bash
- name: Check for changes in lib folder
run: git diff --exit-code lib/js lib/es6
- name: Version Check
run: ./scripts/prebuilt.js
- name: Run tests
run: node scripts/test.js -all
- name: Check for diffs in tests folder
run: git diff --ignore-cr-at-eol --exit-code tests
- name: Run analysis / tools tests
if: runner.os != 'Windows' && runner.os != 'Linux'
run: opam exec -- make -C tests/analysis_tests test && make -C tests/tools_tests test
- name: Run gentype tests
if: runner.os != 'Windows'
run: make -C tests/gentype_tests/typescript-react-example clean test
- name: Run syntax benchmarks
if: matrix.benchmarks
run: ./_build/install/default/bin/syntax_benchmarks | tee tests/benchmark-output.json
# Benchmarking is disabled for now because of inconsistent run times on different runners
#
# - name: Restore previous benchmark data
# if: matrix.benchmarks
# uses: actions/cache/restore@v4
# with:
# path: ./tests/benchmark-cache
# key: syntax-benchmark-v1
# - name: Create new benchmark data and comment on alert
# # Do not run for PRs created from other repos as those won't be able to write to the pull request
# if: ${{ matrix.benchmarks && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name) }}
# uses: benchmark-action/github-action-benchmark@v1
# with:
# name: Syntax Benchmarks
# tool: customSmallerIsBetter
# output-file-path: tests/benchmark-output.json
# external-data-json-path: ./tests/benchmark-cache/benchmark-data.json
# github-token: ${{ secrets.GITHUB_TOKEN }}
# alert-threshold: "105%"
# comment-always: false
# comment-on-alert: true
# - name: Save benchmark data as new baseline
# if: matrix.benchmarks && github.ref == 'refs/heads/master'
# uses: actions/cache/save@v4
# with:
# path: ./tests/benchmark-cache
# key: syntax-benchmark-v1
- name: Build playground compiler
if: matrix.build_playground
run: opam exec -- make playground playground-cmijs
- name: Test playground compiler
if: matrix.build_playground
run: yarn workspace playground test
- name: Upload playground compiler to CDN
if: ${{ matrix.build_playground && startsWith(github.ref, 'refs/tags/v') }}
env:
KEYCDN_USER: ${{ secrets.KEYCDN_USER }}
KEYCDN_PASSWORD: ${{ secrets.KEYCDN_PASSWORD }}
run: yarn workspace playground upload-bundle
- name: "Upload artifacts: binaries"
if: matrix.upload_binaries
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.node-target }}
path: packages/@rescript/${{ matrix.node-target }}/bin
- name: "Upload artifacts: lib/ocaml"
if: matrix.upload_libs
uses: actions/upload-artifact@v4
with:
name: lib-ocaml
path: lib/ocaml
pkg-pr-new:
needs:
- build-rewatch
- build-compiler
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: yarn
node-version-file: .nvmrc
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: "@(binaries-*|rewatch-*|lib-ocaml)"
- name: Move artifacts into packages
run: .github/workflows/moveArtifacts.sh
shell: bash
- name: Publish packages to pkg.pr.new
run: |
yarn dlx pkg-pr-new publish "." "./packages/@rescript/*"
installationTest:
needs:
- pkg-pr-new
strategy:
fail-fast: false
matrix:
include:
- os: macos-13
node-target: darwin-x64
- os: macos-14
node-target: darwin-arm64
- os: ubuntu-24.04
node-target: linux-x64
- os: ubuntu-24.04-arm
node-target: linux-arm64
- os: windows-latest
node-target: win32-x64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Make test directory
id: tmp-dir
shell: bash
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
dir=$(powershell -Command "[System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString()" | tr -d '\r')
mkdir -p "$dir"
else
dir=$(mktemp -d)
fi
echo "path=$dir" >> "$GITHUB_OUTPUT"
cp -r tests/package_tests/installation_test/* "$dir"
- name: Install ReScript package
run: |
COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
npm i --no-audit \
"https://pkg.pr.new/rescript-lang/rescript@${COMMIT_SHA::7}"
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}
- name: Test installation
run: npx rescript -h && npx rescript build && cat src/Test.res.js
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}
publish:
needs:
- build-rewatch
- build-compiler
- installationTest
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: yarn
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org # Needed to make auth work for publishing
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: "@(binaries-*|rewatch-*|lib-ocaml)"
- name: Move artifacts into packages
run: .github/workflows/moveArtifacts.sh
shell: bash
- name: Publish packages on npm with tag "ci"
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
run: |
yarn workspaces foreach -W --no-private \
npm publish --tag ci
- name: Update Website Playground
env:
NEXT_REVALIDATE_SECRET_TOKEN: ${{ secrets.NEXT_REVALIDATE_SECRET_TOKEN }}
run: yarn workspace playground revalidate
shell: bash