-
Notifications
You must be signed in to change notification settings - Fork 455
379 lines (300 loc) · 10.8 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
name: CI
on:
push:
branches: [master]
# 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]
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 statically linked Linux binaries in an Alpine-based Docker container
# See https://ocamlpro.com/blog/2021_09_02_generating_static_and_portable_executables_with_ocaml
# for more info.
# The container already comes with all required tools pre-installed
# (see https://github.com/rescript-lang/docker-rescript-ci-build/blob/main/Dockerfile).
static-binaries-linux:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, buildjet-2vcpu-ubuntu-2204-arm]
runs-on: ${{matrix.os}}
container:
image: ghcr.io/rescript-lang/rescript-ci-build:v1.1.0
steps:
# See https://github.com/actions/runner/issues/801#issuecomment-1374967227.
- name: Workaround for Github actions runner on Alpine arm64
if: runner.arch == 'ARM64'
run: sed -i "s:ID=alpine:ID=NotpineForGHA:" /etc/os-release
- name: Checkout
uses: actions/checkout@v3
- name: Build compiler binaries
run: opam exec -- dune build --display quiet --profile static
- name: Build ninja binary
working-directory: ninja
env:
LDFLAGS: -static
run: python3 configure.py --bootstrap --verbose
- name: "Upload artifacts"
uses: actions/upload-artifact@v3
with:
name: static-binaries-linux-${{runner.arch}}
path: |
_build/install/default/bin
ninja/ninja
# The full build including tests does not work on Linux ARM because setup-ocaml fails.
# Therefore, only upload the binaries from the static build
upload-linux-arm64-binaries:
needs:
- static-binaries-linux
runs-on: buildjet-2vcpu-ubuntu-2204-arm
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download static linux binaries
if: runner.os == 'Linux'
uses: actions/download-artifact@v3
with:
name: static-binaries-linux-${{ runner.arch }}
- name: Make static linux binaries executable
if: runner.os == 'Linux'
run: |
chmod +x ninja/ninja
chmod +x _build/install/default/bin/*
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Copy exes to platform bin dirs
run: node ./scripts/copyExes.js
- name: Prepare artifact upload
run: node .github/workflows/get_artifact_info.js
- name: "Upload artifacts: binaries"
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}
path: ${{ env.artifact_path }}
build:
needs: static-binaries-linux
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest, macos-arm]
ocaml_compiler: [4.14.0]
runs-on: ${{matrix.os}}
env:
DUNE_PROFILE: release
steps:
- name: "Windows: Set git to use LF"
if: runner.os == 'Windows'
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2 # to be able to check for changes in subfolder jscomp/syntax later
- name: Download static linux binaries
if: runner.os == 'Linux'
uses: actions/download-artifact@v3
with:
name: static-binaries-linux-${{ runner.arch }}
- name: Make static linux binaries executable
if: runner.os == 'Linux'
run: |
chmod +x ninja/ninja
chmod +x _build/install/default/bin/*
- name: Use OCaml ${{matrix.ocaml_compiler}}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{matrix.ocaml_compiler}}
opam-pin: false
opam-depext: false
- name: "Install OPAM dependencies"
run: opam install . --deps-only
- name: "Build compiler"
if: runner.os != 'Linux'
run: opam exec -- dune build --display quiet --profile release
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install npm packages
run: npm ci --ignore-scripts
- name: "Windows: Use MSVC for ninja build"
if: runner.os == 'Windows'
uses: TheMrMilchmann/setup-msvc-dev@v2
with:
arch: x64
- name: Build ninja
if: runner.os != 'Linux'
run: node scripts/buildNinjaBinary.js
- name: Copy exes to platform bin dirs
run: node ./scripts/copyExes.js
- name: "Check if syntax subfolder has changed"
id: syntax-diff
shell: bash
run: |
if git diff --name-only --exit-code HEAD^ HEAD -- jscomp/syntax; then
echo "syntax_status=unchanged" >> $GITHUB_ENV
else
echo "syntax_status=changed" >> $GITHUB_ENV
fi
- name: "Syntax: Run roundtrip tests"
if: ${{ env.syntax_status == 'changed' && runner.os != 'Windows' }}
run: opam exec -- make test-syntax-roundtrip
- name: "Syntax: Run tests (Windows)"
if: ${{ env.syntax_status == 'changed' && runner.os == 'Windows' }}
run: opam exec -- make test-syntax
- name: Build runtime/stdlib
if: runner.os != 'Windows'
run: |
opam exec -- node ./scripts/ninja.js config
opam exec -- node ./scripts/ninja.js build
- name: Check for changes in lib folder
run: git diff --exit-code lib/js lib/es6
- name: Populate lib/ocaml
run: ./scripts/prebuilt.js
- name: Run tests
if: runner.os != 'Windows'
run: node scripts/ciTest.js -all
- name: Run tests (Windows)
if: runner.os == 'Windows'
run: node scripts/ciTest.js -mocha -theme -format
# Build the playground compiler on our fastest runner (macOS ARM)
- name: Install JSOO
if: matrix.os == 'macos-arm'
run: opam install js_of_ocaml.4.0.0
- name: Build playground compiler
if: matrix.os == 'macos-arm'
run: |
opam exec -- node packages/playground-bundling/scripts/generate_cmijs.js
opam exec -- dune build --profile browser
cp ./_build/default/jscomp/jsoo/jsoo_playground_main.bc.js playground/compiler.js
- name: Test playground compiler
if: matrix.os == 'macos-arm'
run: node playground/playground_test.js
- name: Upload playground compiler to CDN
if: ${{ matrix.os == 'macos-arm' && startsWith(github.ref, 'refs/tags/v') }}
env:
KEYCDN_USER: ${{ secrets.KEYCDN_USER }}
KEYCDN_PASSWORD: ${{ secrets.KEYCDN_PASSWORD }}
run: sh playground/upload_bundle.sh
- name: Prepare artifact upload
run: node .github/workflows/get_artifact_info.js
- name: "Upload artifacts: binaries"
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}
path: ${{ env.artifact_path }}
- name: "Upload artifacts: lib/ocaml"
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: lib-ocaml
path: lib/ocaml
package:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: NPM install
run: npm ci --ignore-scripts
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Move artifacts
run: ./scripts/moveArtifacts.sh
- name: Check artifact list
run: node ./scripts/makeArtifactList.js -check
- name: npm pack (rescript)
run: npm pack
- name: Copy JS files to stdlib package
run: mkdir -p packages/std/lib && cp -R lib/es6 lib/js packages/std/lib
- name: npm pack (@rescript/std)
run: npm pack
working-directory: packages/std
- name: Prepare package upload
# For pull requests, pass the correct commit SHA explicitly as GITHUB_SHA points to the wrong commit.
run: node .github/workflows/prepare_package_upload.js ${{ github.event.pull_request.head.sha }}
- name: "Upload artifact: npm packages"
uses: actions/upload-artifact@v3
with:
name: npm-packages
path: |
rescript-${{ env.rescript_version }}.tgz
rescript-std-${{ env.rescript_version }}.tgz
outputs:
rescript_version: ${{ env.rescript_version }}
installationTest:
needs: package
strategy:
fail-fast: false
matrix:
os:
[
macos-latest,
macos-arm,
ubuntu-latest,
buildjet-2vcpu-ubuntu-2204-arm,
windows-latest,
]
runs-on: ${{matrix.os}}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: npm-packages
path: packages/test
- name: Install ReScript package
run: npm i rescript-${{ needs.package.outputs.rescript_version }}.tgz
shell: bash
working-directory: packages/test
- name: Test installation
run: npx rescript -h && npx rescript build && cat src/Test.bs.js
shell: bash
working-directory: packages/test
publish:
needs: [package, installationTest]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org # Needed to make auth work for publishing
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: npm-packages
- name: Publish packages on npm with tag "ci"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
run: |
npm publish rescript-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
npm publish rescript-std-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
- name: Update Website Playground
env:
NEXT_REVALIDATE_SECRET_TOKEN: ${{ secrets.NEXT_REVALIDATE_SECRET_TOKEN }}
run: ./playground/website_update_playground.sh
shell: bash