1+ name : Examples
2+
3+ on :
4+ push :
5+ branches : [ "main" ]
6+ paths :
7+ - " .github/workflows/examples.yml"
8+ - " examples/**"
9+ - " basis-library/**"
10+ - " mlton/**"
11+ - " runtime/**"
12+ - " include/**"
13+ - " Makefile"
14+ - " Makefile.config"
15+ - " default.nix"
16+ - " Dockerfile.amd64"
17+ - " Dockerfile.arm64"
18+ - " docker-bake.hcl"
19+ pull_request :
20+ branches : [ "main" ]
21+ paths :
22+ - " .github/workflows/examples.yml"
23+ - " examples/**"
24+ - " basis-library/**"
25+ - " mlton/**"
26+ - " runtime/**"
27+ - " include/**"
28+ - " Makefile"
29+ - " Makefile.config"
30+ - " default.nix"
31+ - " Dockerfile.amd64"
32+ - " Dockerfile.arm64"
33+ - " docker-bake.hcl"
34+
35+ jobs :
36+ build-and-run-examples :
37+ runs-on : ubuntu-latest
38+ timeout-minutes : 45
39+
40+ steps :
41+ - name : Checkout repository
42+ uses : actions/checkout@v4
43+
44+ - name : Install dependencies
45+ run : |
46+ sudo apt-get update
47+ sudo apt-get install -y mlton libgmp-dev gcc make
48+
49+ - name : Cache MPL compiler
50+ id : cache-mpl
51+ uses : actions/cache@v4
52+ with :
53+ path : build
54+ key : mpl-${{ runner.os }}-${{ hashFiles('mlton/**', 'runtime/**', 'include/**', 'basis-library/**', 'Makefile', 'Makefile.config') }}
55+
56+ - name : Build MPL compiler
57+ if : steps.cache-mpl.outputs.cache-hit != 'true'
58+ run : make --silent
59+
60+ - name : Build examples
61+ run : make -C examples --silent
62+
63+ - name : Run examples smoke tests
64+ run : |
65+ set -euo pipefail
66+ cd examples
67+
68+ # Strip timing information from program output.
69+ # Removes "... in X.XXXXs" and "Finished in: X.XXXXs" substrings,
70+ # then removes any resulting blank lines.
71+ strip_timing() {
72+ sed -E \
73+ -e 's/[Ff]inished in:? [0-9]+\.[0-9]+s\.?//g' \
74+ -e 's/ in [0-9]+\.[0-9]+s\.?//g' \
75+ -e 's/[[:space:]]+$//' \
76+ | sed '/^$/d'
77+ }
78+
79+ fail=0
80+ check_output() {
81+ local name="$1"
82+ shift
83+ local actual
84+ actual=$("$@" 2>&1 | strip_timing)
85+ local expected
86+ expected=$(cat "expected/${name}.ok")
87+ if [ "$actual" != "$expected" ]; then
88+ echo "FAIL: $name"
89+ diff <(echo "$actual") <(echo "$expected") || true
90+ fail=1
91+ else
92+ echo "PASS: $name"
93+ fi
94+ }
95+
96+ check_output fib ./bin/fib -N 20
97+ check_output random ./bin/random -N 1000 -seed 1
98+ check_output primes ./bin/primes -N 10000
99+ check_output msort ./bin/msort -N 20000
100+ check_output dmm ./bin/dmm -N 16
101+ check_output ray bash -c './bin/ray -m 32 -n 32 -s rgbbox -f ray_result.ppm && echo "ray_result.ppm checksum: $(md5sum ray_result.ppm | cut -d" " -f1)"'
102+ check_output nn ./bin/nn -N 500
103+ check_output nqueens ./bin/nqueens -N 10
104+ check_output coins ./bin/coins -N 100 -repeat 1
105+ check_output tokens ./bin/tokens expected/input.txt
106+ check_output dedup ./bin/dedup expected/input.txt
107+ check_output seam-carve bash -c './bin/seam-carve ray_result.ppm -num-seams 5 -output seam_result.gif && echo "seam_result.gif checksum: $(md5sum seam_result.gif | cut -d" " -f1)"'
108+ check_output reverb bash -c './bin/reverb expected/test.wav -output reverb_result.wav && echo "reverb_result.wav checksum: $(md5sum reverb_result.wav | cut -d" " -f1)"'
109+
110+ if [ "$fail" -ne 0 ]; then
111+ echo "Some output checks failed!"
112+ exit 1
113+ fi
0 commit comments