Fork of daniellemaywood.uk/gleam — Wasm codegen work
1name: ci
2on:
3 pull_request:
4 push:
5 branches:
6 - main
7 workflow_dispatch:
8
9env:
10 CARGO_TERM_COLOR: always
11 RUSTFLAGS: "-D warnings"
12 CARGO_INCREMENTAL: 0
13 CARGO_PROFILE_DEV_DEBUG: 0
14 CARGO_PROFILE_TEST_DEBUG: 0
15 CROSS_CONTAINER_UID: 0
16
17permissions:
18 contents: read
19
20concurrency:
21 group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
22 cancel-in-progress: true
23
24jobs:
25 test:
26 name: test
27 runs-on: ${{ matrix.os }}
28 timeout-minutes: 30
29 strategy:
30 fail-fast: false
31 matrix:
32 toolchain: [stable]
33 target:
34 - x86_64-unknown-linux-gnu
35 - x86_64-unknown-linux-musl
36 - aarch64-unknown-linux-gnu
37 - aarch64-unknown-linux-musl
38 - x86_64-apple-darwin
39 - x86_64-pc-windows-msvc
40 include:
41 - os: ubuntu-latest
42 target: x86_64-unknown-linux-gnu
43 use-cross: false
44 run-integration-tests: true
45 - os: ubuntu-latest
46 target: x86_64-unknown-linux-musl
47 use-cross: true
48 run-integration-tests: true
49 - os: ubuntu-latest
50 target: aarch64-unknown-linux-gnu
51 use-cross: true
52 run-integration-tests: false # Cannot run aarch64 binaries on x86_64
53 - os: ubuntu-latest
54 target: aarch64-unknown-linux-musl
55 use-cross: true
56 run-integration-tests: false # Cannot run aarch64 binaries on x86_64
57 # macos>=14 runs exclusively on aarch64 and will thus fail to execute properly for x64
58 - os: macos-13 # intel
59 target: x86_64-apple-darwin
60 use-cross: false
61 run-integration-tests: true
62 - os: macos-latest # aarch64
63 toolchain: stable
64 target: aarch64-apple-darwin
65 use-cross: false
66 run-integration-tests: true
67 - os: windows-latest
68 target: x86_64-pc-windows-msvc
69 use-cross: false
70 run-integration-tests: true
71 steps:
72 - name: Checkout repository
73 uses: actions/checkout@v4
74
75 - name: Install musl-tools incl. musl-gcc
76 uses: awalsh128/cache-apt-pkgs-action@v1
77 with:
78 # musl-tools provide `musl-gcc` which is required for `ring` which is required for `rustls` et al.
79 packages: musl-tools
80 version: 1.1
81 if: ${{ matrix.target == 'x86_64-unknown-linux-musl'}}
82
83 - name: Install Rust toolchain
84 uses: dtolnay/rust-toolchain@stable
85 with:
86 toolchain: ${{ matrix.toolchain }}
87 target: ${{ matrix.target }}
88
89 - name: Install Erlang (non-macos)
90 uses: erlef/setup-beam@v1
91 with:
92 otp-version: "26.1"
93 elixir-version: "1.16.1"
94 rebar3-version: "3"
95 if: ${{ runner.os != 'macOS' }} # setup-beam does not support macOS
96
97 - name: Install Erlang (macos)
98 run: |
99 brew install erlang rebar3 elixir
100 mix local.hex --force
101 if: ${{ runner.os == 'macOS' }} # setup-beam does not support macOS
102
103 - name: Handle Rust dependencies caching
104 uses: Swatinem/rust-cache@v2
105 with:
106 key: v1-${{ matrix.target }}
107
108 - name: Install Gleam
109 uses: clechasseur/rs-cargo@v2
110 with:
111 command: install
112 args: "--path compiler-cli --target ${{ matrix.target }} --debug --locked"
113 use-cross: ${{ matrix.use-cross }}
114 if: ${{ matrix.run-integration-tests }}
115
116 - name: Run tests
117 uses: clechasseur/rs-cargo@v2
118 with:
119 command: test
120 args: "--workspace --target ${{ matrix.target }}"
121 use-cross: ${{ matrix.use-cross }}
122
123 - name: test/project_erlang (non-windows)
124 run: |
125 gleam run && cd src && gleam run && cd ..
126 gleam check
127 gleam test && cd src && gleam test && cd ..
128 gleam docs build
129 working-directory: ./test/project_erlang
130 if: ${{ runner.os != 'Windows' && matrix.run-integration-tests }}
131
132 - name: test/project_erlang (windows)
133 run: |
134 gleam run && cd src && gleam run && cd ..
135 gleam check
136 gleam test && cd src && gleam test && cd ..
137 gleam docs build
138 working-directory: ./test/project_erlang_windows
139 if: ${{ runner.os == 'Windows' && matrix.run-integration-tests }}
140
141 - name: test/project_erlang export erlang-shipment (non-windows)
142 run: |
143 gleam export erlang-shipment
144 ./build/erlang-shipment/entrypoint.sh run
145 working-directory: ./test/project_erlang
146 if: ${{ runner.os != 'Windows' && matrix.run-integration-tests }}
147
148 - name: test/project_erlang export erlang-shipment (windows)
149 run: |
150 gleam export erlang-shipment
151 .\build\erlang-shipment\entrypoint.ps1 run
152 working-directory: ./test/project_erlang_windows
153 if: ${{ runner.os == 'Windows' && matrix.run-integration-tests }}
154
155 - name: test/project_erlang export package-interface (non-windows)
156 run: |
157 gleam export package-interface --out="interface.json"
158 cat interface.json
159 working-directory: ./test/project_erlang
160 if: ${{ runner.os != 'Windows' && matrix.run-integration-tests }}
161
162 - name: test/project_erlang export package-interface (windows)
163 run: |
164 gleam export package-interface --out="interface.json"
165 cat interface.json
166 working-directory: ./test/project_erlang_windows
167 if: ${{ runner.os == 'Windows' && matrix.run-integration-tests }}
168
169 - name: test/external_only_javascript
170 run: ./test.sh
171 working-directory: ./test/external_only_javascript
172 if: ${{ matrix.run-integration-tests }}
173 env:
174 GLEAM_COMMAND: gleam
175
176 - name: test/external_only_erlang
177 run: ./test.sh
178 working-directory: ./test/external_only_erlang
179 if: ${{ matrix.run-integration-tests }}
180 env:
181 GLEAM_COMMAND: gleam
182
183 - name: test/root_package_not_compiled_when_running_dep
184 run: ./test.sh
185 working-directory: ./test/root_package_not_compiled_when_running_dep
186 if: ${{ matrix.run-integration-tests }}
187 env:
188 GLEAM_COMMAND: gleam
189
190 - name: test/project_javascript
191 run: |
192 gleam run
193 gleam check
194 gleam test
195 gleam docs build
196 working-directory: ./test/project_javascript
197 if: ${{ matrix.run-integration-tests }}
198
199 - name: test/project_path_deps
200 run: |
201 gleam update
202 gleam check
203 working-directory: ./test/project_path_deps/project_a
204 if: ${{ matrix.run-integration-tests }}
205
206 - name: Test project generation
207 run: |
208 gleam new lib_project
209 cd lib_project
210 gleam run
211 gleam test
212
213 # Test adding of deps
214 gleam add exception # No specifier
215 gleam add gleam_http@3 # Version specifier
216 gleam test
217
218 # Test documentation generation
219 gleam docs build
220
221 # Assert that module metadata has been written
222 ls build/dev/erlang/lib_project/_gleam_artefacts/lib_project.cache
223
224 # Assert that HTML docs and their assets have been written
225 ls build/dev/docs/lib_project/index.html
226 ls build/dev/docs/lib_project/lib_project.html
227 ls build/dev/docs/lib_project/css/atom-one-light.min.css
228 ls build/dev/docs/lib_project/css/atom-one-dark.min.css
229 ls build/dev/docs/lib_project/css/index.css
230 ls build/dev/docs/lib_project/js/highlight.min.js
231 ls build/dev/docs/lib_project/js/highlightjs-gleam.js
232 ls build/dev/docs/lib_project/js/highlightjs-erlang.min.js
233 ls build/dev/docs/lib_project/js/highlightjs-elixir.min.js
234 ls build/dev/docs/lib_project/js/highlightjs-javascript.min.js
235 ls build/dev/docs/lib_project/js/highlightjs-typescript.min.js
236 ls build/dev/docs/lib_project/js/lunr.min.js
237 ls build/dev/docs/lib_project/js/index.js
238 ls build/dev/docs/lib_project/fonts/karla-v23-bold-latin-ext.woff2
239 ls build/dev/docs/lib_project/fonts/karla-v23-bold-latin.woff2
240 ls build/dev/docs/lib_project/fonts/karla-v23-regular-latin-ext.woff2
241 ls build/dev/docs/lib_project/fonts/karla-v23-regular-latin.woff2
242 ls build/dev/docs/lib_project/fonts/ubuntu-mono-v15-regular-cyrillic-ext.woff2
243 ls build/dev/docs/lib_project/fonts/ubuntu-mono-v15-regular-cyrillic.woff2
244 ls build/dev/docs/lib_project/fonts/ubuntu-mono-v15-regular-greek-ext.woff2
245 ls build/dev/docs/lib_project/fonts/ubuntu-mono-v15-regular-greek.woff2
246 ls build/dev/docs/lib_project/fonts/ubuntu-mono-v15-regular-latin-ext.woff2
247 ls build/dev/docs/lib_project/fonts/ubuntu-mono-v15-regular-latin.woff2
248 if: ${{ matrix.run-integration-tests }}
249
250 test-wasm:
251 runs-on: ubuntu-latest
252 timeout-minutes: 30
253 steps:
254 - name: Checkout repository
255 uses: actions/checkout@v4
256
257 - name: Install Rust toolchain
258 uses: dtolnay/rust-toolchain@stable
259 with:
260 toolchain: stable
261 target: wasm32-unknown-unknown
262
263 - uses: actions/setup-node@v4
264 with:
265 node-version: "18"
266
267 - name: Install wasm-pack
268 run: |
269 curl -sSL https://rustwasm.github.io/wasm-pack/installer/init.sh | sh
270
271 - name: Run wasm tests
272 run: wasm-pack test --node compiler-wasm
273
274 rustfmt:
275 name: rustfmt
276 runs-on: ubuntu-latest
277 timeout-minutes: 10
278 steps:
279 - name: Checkout repository
280 uses: actions/checkout@v4
281
282 - name: Install Rust toolchain
283 uses: dtolnay/rust-toolchain@stable
284 with:
285 toolchain: stable
286 components: rustfmt
287
288 - run: cargo fmt --all -- --check
289
290 validate:
291 name: validate
292 runs-on: ubuntu-latest
293 timeout-minutes: 10
294 steps:
295 - name: Checkout repository
296 uses: actions/checkout@v4
297
298 - name: Ensure no merge commits
299 uses: NexusPHP/no-merge-commits@v2.1.0
300 if: github.event_name == 'pull_request'
301 with:
302 token: ${{ secrets.GITHUB_TOKEN }}
303
304 - name: Install Rust toolchain
305 uses: dtolnay/rust-toolchain@stable
306 with:
307 toolchain: stable
308
309 - name: Install cargo-deny
310 run: |
311 set -e
312 curl -L https://github.com/EmbarkStudios/cargo-deny/releases/download/0.14.18/cargo-deny-0.14.18-x86_64-unknown-linux-musl.tar.gz | tar xzf -
313 mv cargo-deny-*-x86_64-unknown-linux-musl/cargo-deny cargo-deny
314 echo `pwd` >> $GITHUB_PATH
315
316 - name: Validate deps
317 run: cargo deny check
318
319 lint-build:
320 name: lint-build
321 runs-on: ubuntu-latest
322 timeout-minutes: 10
323 steps:
324 - name: Checkout repository
325 uses: actions/checkout@v4
326
327 - name: Install Rust toolchain
328 uses: dtolnay/rust-toolchain@stable
329 with:
330 toolchain: stable
331 components: clippy
332
333 - name: Handle Rust dependencies caching
334 uses: Swatinem/rust-cache@v2
335 with:
336 key: v1-linux-gnu
337
338 - name: Run linter
339 run: cargo clippy --workspace
340
341 - run: cargo build
342
343 - name: Upload artifact (Ubuntu)
344 uses: actions/upload-artifact@v4
345 with:
346 name: gleam
347 path: target/debug/gleam
348
349 test-projects:
350 name: test-projects
351 needs: lint-build
352 runs-on: ubuntu-latest
353 timeout-minutes: 10
354 steps:
355 - name: Checkout repository
356 uses: actions/checkout@v4
357
358 - name: Install Deno
359 uses: denoland/setup-deno@v2
360 with:
361 deno-version: v2.x
362
363 - name: Install Bun
364 uses: oven-sh/setup-bun@v2
365
366 - name: Install Erlang
367 uses: erlef/setup-beam@v1
368 with:
369 otp-version: "26.1"
370 elixir-version: "1.16.1"
371 rebar3-version: "3"
372
373 - name: Download Gleam binary from previous job
374 uses: actions/download-artifact@v4
375 with:
376 name: gleam
377 path: ./test
378
379 - name: Configure test projects to use Gleam binary
380 run: |
381 echo $PWD/ >> $GITHUB_PATH
382 chmod +x ./gleam
383 sed -i 's/cargo run --quiet --/gleam/' */Makefile
384 sed -i 's/cargo run --/gleam/' */Makefile
385 working-directory: ./test
386
387 - name: test/language Erlang
388 run: make clean erlang
389 working-directory: ./test/language
390
391 - name: test/language JavaScript with NodeJS
392 run: make clean nodejs
393 working-directory: ./test/language
394
395 - name: test/language JavaScript with Deno
396 run: make clean deno
397 working-directory: ./test/language
398
399 - name: test/language JavaScript with Bun
400 run: make clean bun
401 working-directory: ./test/language
402
403 - name: test/compile_package0
404 run: make
405 working-directory: ./test/compile_package0
406
407 - name: test/compile_package1
408 run: make
409 working-directory: ./test/compile_package1
410
411 - name: Test JavaScript prelude
412 run: make
413 working-directory: ./test/javascript_prelude
414
415 - name: Test export of hex tarball
416 run: make test
417 working-directory: ./test/hextarball
418
419 - name: Test running modules
420 run: make test
421 working-directory: ./test/running_modules
422
423 - name: test/multi_namespace
424 run: ./test.sh
425 working-directory: ./test/multi_namespace
426
427 - name: Test FFI in subdirectories
428 run: make
429 working-directory: ./test/subdir_ffi
430
431 - name: test/unicode_path
432 run: make
433 working-directory: ./test/unicode_path ⭐