-
Notifications
You must be signed in to change notification settings - Fork 8
343 lines (275 loc) · 11.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
name: CI
on:
push:
branches:
- main
tags:
- '*'
pull_request:
## We specify a concurrency group with automated cancellation. This means that
## other pushes on the same `github.ref` (eg. other pushes to the same pull
## request) cancel previous occurrences of the CI.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
## ========================= [ OPAM-based CI ] ========================= ##
opam-based:
strategy:
fail-fast: false
matrix:
include:
- {os: ubuntu, ocaml: 4.11.x} ## in Debian stable (as of 2023-05-11)
- {os: ubuntu, ocaml: 4.11.x, lower-bounds: lower-bounds, doc: no-doc}
- {os: ubuntu, ocaml: 4.12.x}
- {os: ubuntu, ocaml: 4.13.x}
# {os: ubuntu, ocaml: 4.14.x} ## main supported version
- {os: ubuntu, ocaml: 4.14.x, lower-bounds: lower-bounds, doc: no-doc}
- {os: ubuntu, ocaml: 4.14.x, deploy-doc: deploy-doc}
- {os: ubuntu, ocaml: 4.14.1, bytecode: bytecode}
- {os: macos, ocaml: 4.14.x}
- {os: windows, ocaml: 4.14.x, tests: no-tests}
- {os: ubuntu, ocaml: 5.0.x}
## NOTE: The `ocaml/setup-ocaml@v2` action does not support `4.14.x`
## versions for `ocaml-variants` and such, hence the detailed version.
## NOTE: After OCaml 5.0.0, `ocaml-option-bytecode-only` can be used
## directly with `ocaml-base-compiler`, probably?
## NOTE: Tests are written in a Unix-like way and therefore cannot
## run correctly on Windows.
## NOTE: `lower-bounds` implies to not build the documentation because
## `opam-0install`, the solver we use, does not support it. Therefore
## we don't even install those dependencies to begin with.
## Grant GITHUB_TOKEN the permissions required to make a pages deployment
permissions:
pages: write
id-token: write
runs-on: ${{ matrix.os }}-latest
steps:
- name: Determine OPAM flags
shell: bash ## for Windows
run: |
if ${{ matrix.doc != 'no-doc' }}; then
with_doc=--with-doc
fi
if ${{ matrix.tests != 'no-tests' }}; then
with_test=--with-test
fi
echo "OPAM_FLAGS=$with_doc $with_test" >> "$GITHUB_ENV"
- name: Checkout repository
uses: actions/checkout@v4
- name: Use OCaml ${{ matrix.ocaml }}
if: matrix.bytecode != 'bytecode'
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml }}
- name: (Bytecode) Use OCaml ${{ matrix.ocaml }}
if: matrix.bytecode == 'bytecode'
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ocaml-variants.${{ matrix.ocaml }}+options,ocaml-option-bytecode-only
- name: Install Dune
run: opam install dune --yes
- name: Install OPAM dependencies
run: opam install . --deps-only ${{ env.OPAM_FLAGS }}
- name: (Lower bounds) Install OPAM-0install
if: matrix.lower-bounds == 'lower-bounds'
run: |
opam install opam-0install
- name: (Lower bounds) Ask OPAM-0install for an install plan
if: matrix.lower-bounds == 'lower-bounds'
run: |
## Based on: https://sim642.eu/blog/2022/03/13/ocaml-dependencies-lower-bounds-ci/
## Note the current version of `ocaml-base-compiler`
obc=ocaml-base-compiler.$(opam exec -- ocamlc --version)
## Ask `opam-0install` to get us the oldest possible dependencies for
## Morbig, while keeping the exact same version of
## `ocaml-base-compiler`.
opam exec -- \
opam-0install --prefer-oldest $OPAM_FLAGS morbig.dev $obc \
| sed 's|morbig.dev||' \
> lower-bounds
## Log what we are aiming for
printf '\e[36m<><>\e[0m Packages to install \e[36m><><><><><><><><><><><><><><><><><><><><><><><><><><><>\e[0m\n'
printf '`opam-0install` suggests installing the following packages:\n'
cat lower-bounds | tr ' ' '\n' | sed 's|^\([^.]*\)\.|\t\1\t|' | column -t
- name: (Lower bounds) Downgrade OPAM dependencies
if: matrix.lower-bounds == 'lower-bounds'
run: opam install --yes $(cat lower-bounds)
- name: Try building
run: opam exec -- make
- name: Try building documentation
if: matrix.doc != 'no-doc'
run: opam exec -- make doc
- name: Run tests
if: matrix.tests != 'no-tests'
run: opam exec -- make check
- name: Try installing
run: opam exec -- make install
- name: Try building examples
## NOTE: Examples are written in a Unix-like way and cannot build on a
## bytecode-only infrastructure.
if: runner.os != 'Windows' && matrix.bytecode != 'bytecode'
run: opam exec -- make examples
- name: Try uninstalling
if: matrix.lower-bounds != 'lower-bounds'
run: opam exec -- make uninstall
- name: (Lower bounds) Try uninstalling
## NOTE: Old versions of Dune (< 3.1.0) fail when they cannot remove
## `bin` or `lib/morbig` in the prefix. But `bin` is very rarely empty.
## Until it is reasonable to require Dune >= 3.1.0, we keep this special
## case for the part of the CI interested in lower bounds.
if: matrix.lower-bounds == 'lower-bounds'
run: opam exec -- make uninstall || true
- name: Try cleaning
run: opam exec -- make clean
- name: Build documentation for auto-deployment
if: matrix.doc != 'no-doc'
run: opam exec -- make doc
- name: Upload documentation artifact
if: matrix.doc != 'no-doc'
uses: actions/upload-pages-artifact@v2
with:
path: doc/
- name: Deploy to GitHub pages
uses: actions/deploy-pages@v2
if: github.event_name == 'push'
&& github.ref == 'refs/heads/main'
&& matrix.deploy-doc == 'deploy-doc'
## ========================= [ APT-based CI ] ========================== ##
apt-based:
runs-on: ubuntu-latest
steps:
- name: Install OCaml & dependencies
run: |
sudo apt-get install \
build-essential ocaml dune menhir libmenhir-ocaml-dev \
libppx-deriving-yojson-ocaml-dev libppx-visitors-ocaml-dev \
libyojson-ocaml-dev
- name: Checkout repository
uses: actions/checkout@v4
- name: Try building
run: make
## No odoc in Debian stable, sadly, so no documentation!
## REVIEW: Ubuntu 22.10 does have a package `ocaml-odoc` though.
# - name: Try building documentation
# run: make doc
## Ubuntu 22.10 only has Alcotest 1.6 which is not recent enough for our
## tests. Therefore, tests are disabled on this platform.
# - name: Run tests
# run: make check
- name: Try installing
run: sudo make install
- name: Try building examples
run: make examples
- name: Try uninstalling
run: sudo make uninstall
## Not working (as of 2023-03-31), `dune clean` complains about:
##
## Error: unlink: _build/default/.dune/configurator: Permission denied
##
## Maybe related to https://github.com/ocaml/dune/issues/3857.
# - name: Try cleaning
# run: make clean
## ======================== [ Docker-based CI ] ======================== ##
docker-based:
strategy:
fail-fast: false
matrix:
include:
- {tag: alpine, deploy-image: deploy-image}
- {tag: archlinux}
- {tag: centos, tests: no-tests} ## only has Alcotest 1.6 (as of 2023-05-11)
- {tag: debian}
- {tag: debian-testing}
- {tag: debian-unstable}
- {tag: fedora}
- {tag: opensuse}
- {tag: oraclelinux}
- {tag: ubuntu}
- {tag: ubuntu-lts}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build Docker image
run: |
docker build \
--tag morbig \
. \
--build-arg tag=${{matrix.tag}} \
--build-arg doc=${{matrix.doc != 'no-doc'}} \
--build-arg tests=${{matrix.tests != 'no-tests'}}
- name: Run tests
run: |
docker run --entrypoint /bin/sh morbig -c '
set -e
eval $(opam env)
cd /home/opam/morbig
if ${{ matrix.tests != 'no-tests' }}; then
make check
fi
if ${{ matrix.doc != 'no-doc' }}; then
make doc
fi
make install
make examples
make uninstall
'
- name: Login to Docker Hub
if: github.event_name == 'push' && matrix.deploy-image == 'deploy-image'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Rename Docker image
if: github.event_name == 'push' && matrix.deploy-image == 'deploy-image'
run: docker image tag morbig colisanr/morbig:${GITHUB_REF##*/}
- name: Push to Docker Hub
if: github.event_name == 'push' && matrix.deploy-image == 'deploy-image'
run: docker push colisanr/morbig:${GITHUB_REF##*/}
## ========================= [ Nix-based CI ] ========================== ##
nix-based:
strategy:
fail-fast: false
matrix:
package:
- with-nixpkgs
- with-opam-nix
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v22
with:
extra_nix_config: |
## Access token to avoid triggering GitHub's rate limiting.
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Install Nix dependencies
run: |
nix develop .#${{ matrix.package }} --print-build-logs --command true
- name: Build in development Shell
run: |
nix develop .#${{ matrix.package }} --command make
- name: Build documentation in development Shell
run: |
nix develop .#${{ matrix.package }} --command make doc
- name: Run tests in development Shell
run: |
nix develop .#${{ matrix.package }} --command make check
- name: Build with Nix
run: |
nix build .#${{ matrix.package }} --print-build-logs
nix-flake-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v22
with:
extra_nix_config: |
## Access token to avoid triggering GitHub's rate limiting.
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Run flake checks
run: nix flake check . --print-build-logs