Skip to content

Commit e9cae76

Browse files
committed
[CI] fix opam setup & add infer cache in Github action
1 parent 4ff0b55 commit e9cae76

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

.github/workflows/check.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ jobs:
1515
- name: Checkout code
1616
uses: actions/checkout@v4
1717
with:
18-
submodules: recursive
18+
submodules: recursive
19+
token: ${{ secrets.ACTION_TOKEN }}
20+
21+
- name: Get submodule commit hash
22+
id: submodule-hash
23+
run: |
24+
HASH=$(git rev-parse --short HEAD:unitcon-infer)
25+
echo "hash=$HASH" >> $GITHUB_OUTPUT
1926
2027
- name: Install required apt packages
2128
run: |
@@ -28,21 +35,31 @@ jobs:
2835
distribution: 'zulu'
2936
java-version: '8'
3037

38+
- name: Cache Infer
39+
id: cache-infer
40+
uses: actions/cache@v4
41+
with:
42+
path: infer.tar
43+
key: infer-tar-${{ steps.submodule-hash.outputs.hash }}
44+
restore-keys: |
45+
infer-tar-${{ steps.submodule-hash.outputs.hash }}
46+
infer-tar-
47+
3148
- name: Set up OCaml
49+
if: steps.cache-infer.outputs.cache-hit != 'true'
3250
uses: ocaml/setup-ocaml@v2
3351
with:
3452
ocaml-compiler: ocaml-variants.4.14.0+options,ocaml-option-flambda
3553

3654
- name: Build Infer
55+
if: steps.cache-infer.outputs.cache-hit != 'true'
3756
shell: bash
3857
run: |
3958
eval $(opam env)
4059
cd unitcon-infer
41-
./build-infer.sh --yes --user-opam-switch java
60+
./build-infer.sh --yes java
4261
cd ..
43-
44-
- name: Tar Infer Artifact
45-
run: tar -cf infer.tar unitcon-infer
62+
tar -cf infer.tar unitcon-infer
4663
4764
- name: Upload Infer Artifact
4865
uses: actions/upload-artifact@v4
@@ -63,9 +80,11 @@ jobs:
6380
- env:
6481
OUTPUT1: ${{ needs.infer-build.outputs.output1 }}
6582
run: echo "Infer artifact-id is $OUTPUT1"
66-
83+
6784
- name: Checkout code
6885
uses: actions/checkout@v4
86+
with:
87+
token: ${{ secrets.ACTION_TOKEN }}
6988

7089
- name: Set up JAVA
7190
uses: actions/setup-java@v4
@@ -81,7 +100,6 @@ jobs:
81100
with:
82101
path: |
83102
~/.opam
84-
./_opam
85103
key: ${{ env.cache-name }}-build-${{ hashFiles('setup.sh') }}
86104
restore-keys: |
87105
${{ env.cache-name }}-build-${{ hashFiles('setup.sh') }}
@@ -106,6 +124,7 @@ jobs:
106124
uses: actions/download-artifact@v4
107125
with:
108126
name: infer-artifact
127+
github-token: ${{ secrets.ACTION_TOKEN }}
109128

110129
- name: Untar Infer Artifact
111130
run: tar -xf infer.tar
@@ -118,4 +137,4 @@ jobs:
118137
- name: Run test (regression)
119138
shell: bash
120139
run: |
121-
eval $(opam env) && make coverage
140+
eval $(opam env) && make coverage

setup.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,34 @@
22
set -e
33
export OPAMYES=1
44

5+
NCPU="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)"
56
OCAML_VERSION="4.14.0"
67
UNITCON_OPAM_SWITCH=unitcon-"$OCAML_VERSION"+flambda
78
JUNIT_FILE="deps/junit-4.13.2.jar"
89
HAMCREST_FILE="deps/hamcrest-core-1.3.jar"
910
MODE="$1"
1011

11-
build_infer () {
12+
USER_OPAM_SWITCH=no
13+
14+
while [[ $# -gt 1 ]]; do
15+
opt_key="$2"
16+
case $opt_key in
17+
--user-opam-switch)
18+
USER_OPAM_SWITCH=yes
19+
shift
20+
continue
21+
;;
22+
esac
23+
done
24+
25+
function build_infer() {
1226
git submodule init
1327
git submodule update
1428
cd unitcon-infer && ./build-infer.sh java
1529
cd ..
1630
}
1731

18-
build_unitcon () {
19-
NCPU="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)"
32+
function setup_opam() {
2033
UNITCON_OPAM_SWITCH_OPTION="--package=ocaml-variants.${OCAML_VERSION}+options,ocaml-option-flambda"
2134
opam init --reinit --bare -j $NCPU --no-setup
2235

@@ -35,6 +48,12 @@ build_unitcon () {
3548
fi
3649

3750
eval $(SHELL=bash opam env --switch=$UNITCON_OPAM_SWITCH)
51+
}
52+
53+
function build_unitcon() {
54+
if [ "$USER_OPAM_SWITCH" == "no" ]; then
55+
setup_opam
56+
fi
3857
opam pin add git+https://github.com/prosyslab/logger.git
3958
opam install -j $NCPU dune ocamlgraph ppx_compare z3 core logger ounit bisect_ppx sawja landmarks landmarks-ppx
4059
opam install yojson.2.2.2
@@ -61,4 +80,4 @@ else
6180
echo "Not supported build mode: $MODE."
6281
echo "Supported build modes: [ all | infer | unitcon ]"
6382
exit 1
64-
fi
83+
fi

0 commit comments

Comments
 (0)