Skip to content

Commit 9cccc1c

Browse files
committed
[CI] fix opam setup
1 parent 3ba21f1 commit 9cccc1c

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
2323
- name: Build Claml
2424
run: |
25-
./build.sh
25+
./build.sh --user-opam-switch
2626
27-
- name: Run test (regression)
28-
run: eval $(opam env) && make test
27+
- name: Run test
28+
run: eval -- exec make test

build.sh

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,52 @@ export OPAMYES=1
77
NCPU="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)"
88
OCAML_VERSION="5.1.0"
99
CLAML_OPAM_SWITCH=claml-"$OCAML_VERSION+flambda"
10-
opam init --compiler=$OCAML_VERSION -j $NCPU --no-setup
1110

12-
switch_exists=no
13-
for installed_switch in $(opam switch list --short); do
14-
if [[ "$installed_switch" == "$CLAML_OPAM_SWITCH" ]]; then
15-
switch_exists=yes
16-
break
17-
fi
11+
USER_OPAM_SWITCH=no
12+
13+
function usage() {
14+
echo "Usage: $0 [options]"
15+
echo
16+
echo " options:"
17+
echo " -h,--help show this message"
18+
echo " --user-opam-switch use the current opam switch to install haechi (default: $OPAM_SWITCH)"
19+
echo
20+
echo " examples:"
21+
echo " $0 # build haechi with default options"
22+
echo " $0 --user-opam-switch # build haechi in the current opam switch (e.g., for Github CI)"
23+
}
24+
25+
while [[ $# -gt 0 ]]; do
26+
opt_key="$1"
27+
case $opt_key in
28+
--user-opam-switch)
29+
USER_OPAM_SWITCH=yes
30+
shift
31+
continue
32+
;;
33+
esac
1834
done
19-
if [ "$switch_exists" = "no" ]; then
20-
opam switch create $CLAML_OPAM_SWITCH $OCAML_VERSION
21-
else
22-
opam switch $CLAML_OPAM_SWITCH
35+
36+
function setup_opam() {
37+
opam init --compiler=$OCAML_VERSION -j $NCPU --no-setup
38+
39+
switch_exists=no
40+
for installed_switch in $(opam switch list --short); do
41+
if [[ "$installed_switch" == "$CLAML_OPAM_SWITCH" ]]; then
42+
switch_exists=yes
43+
break
44+
fi
45+
done
46+
47+
if [ "$switch_exists" = "no" ]; then
48+
opam switch create $CLAML_OPAM_SWITCH $OCAML_VERSION
49+
else
50+
opam switch $CLAML_OPAM_SWITCH
51+
fi
52+
}
53+
54+
if [ "$USER_OPAM_SWITCH" == "no" ]; then
55+
setup_opam
2356
fi
2457

2558
eval $(SHELL=bash opam config env --switch=$CLAML_OPAM_SWITCH)

0 commit comments

Comments
 (0)