Skip to content

Commit bc26b43

Browse files
committed
poc: cache opam actions
1 parent 1fba8ef commit bc26b43

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,24 @@ jobs:
213213
chmod +x rewatch/rewatch
214214
chmod +x _build/install/default/bin/*
215215
216+
- name: Restore OPAM env
217+
id: cache-opam-env
218+
uses: actions/cache/restore@v4
219+
with:
220+
path: ~/.opam
221+
key: opam-env-${{ runner.os }}-${{ hashFiles('dune-project') }}
222+
216223
- name: Use OCaml ${{matrix.ocaml_compiler}}
217224
uses: ocaml/setup-ocaml@v2
218-
if: matrix.os != 'windows-latest'
225+
if: steps.cache-opam-env.outputs.cache-hit != 'true' && matrix.os != 'windows-latest'
219226
with:
220227
ocaml-compiler: ${{matrix.ocaml_compiler}}
221228
opam-pin: false
222229
opam-depext: false
223230

224231
- name: Use OCaml ${{matrix.ocaml_compiler}} (Win)
225232
uses: ocaml/setup-ocaml@v2
226-
if: matrix.os == 'windows-latest'
233+
if: steps.cache-opam-env.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
227234
with:
228235
ocaml-compiler: ocaml-variants.5.2.0+options,ocaml-option-mingw
229236
opam-pin: false
@@ -234,8 +241,46 @@ jobs:
234241
default: https://github.com/ocaml/opam-repository.git
235242
236243
- name: "Install OPAM dependencies"
244+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
237245
run: opam install . --deps-only
238246

247+
- name: Cache OPAM env
248+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
249+
uses: actions/cache/save@v4
250+
with:
251+
path: ~/.opam
252+
key: opam-env-${{ runner.os }}-${{ hashFiles('dune-project') }}
253+
254+
- name: Get OPAM path
255+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
256+
run: |
257+
which opam > .opam-path
258+
259+
- name: Cache OPAM path
260+
id: cache-opam-path
261+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
262+
uses: actions/cache/save@v4
263+
with:
264+
path: .opam-path
265+
key: opam-path-${{ runner.os }}
266+
267+
- name: Restore OPAM path
268+
if: steps.cache-opam-env.outputs.cache-hit == 'true'
269+
uses: actions/cache/restore@v4
270+
with:
271+
path: .opam-path
272+
key: opam-path-${{ runner.os }}
273+
274+
- name: Use cached OPAM env
275+
if: steps.cache-opam-env.outputs.cache-hit == 'true'
276+
run: |
277+
cat .opam-path >> $GITHUB_PATH
278+
279+
- name: Use cached OPAM env
280+
if: steps.cache-opam-env.outputs.cache-hit == 'true'
281+
run: |
282+
opam env | sed "s/'//g; s/; export .*//g" >> $GITHUB_ENV
283+
239284
- name: "Build compiler"
240285
if: runner.os != 'Linux'
241286
run: opam exec -- dune build --display quiet --profile release

0 commit comments

Comments
 (0)