Skip to content

Commit 2a0f3ba

Browse files
authored
Boost CI speed (#6842)
* poc: cache opam actions * it should be a dirname * debug opam-path * then work? * why * should work * almost there? * let me just sleep please * linux system dependencies * caches * install jsoo with cache * cache rewatch build too * revert some * dedupe deps declaration, this should make new cacahe * use bash instead of powershell * fix Windows * invalidate env cache * fix cache lifecycle * fix windows * fix windows cache * poc: use build image via jobs.container * Revert "poc: use build image via jobs.container" This reverts commit 4e4277e. The custom container feature seems to have some compatibility issues and doesn't provide any additional optimization anyway * remove unnecessary setup-python * fix a wrong path * what was happened * fine
1 parent dd4a4bf commit 2a0f3ba

File tree

6 files changed

+115
-18
lines changed

6 files changed

+115
-18
lines changed

.github/workflows/ci.yml

+110-13
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,32 @@ jobs:
5454
- name: Checkout
5555
uses: actions/checkout@v4
5656

57+
- name: Restore build cache
58+
id: build-cache
59+
uses: actions/cache@v4
60+
with:
61+
path: rewatch/target
62+
key: rewatch-build-${{ matrix.rust-target }}-${{ hashFiles('rewatch/src/**', 'rewatch/Cargo.lock') }}
63+
5764
- name: Install musl gcc
58-
if: runner.os == 'Linux'
59-
run: sudo apt-get install -y musl-tools
65+
if: steps.build-cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
66+
run: sudo apt-get install -y --no-install-recommends musl-tools
6067

6168
- name: Set up sccache
69+
if: steps.build-cache.outputs.cache-hit != 'true'
6270
uses: mozilla-actions/[email protected]
6371
with:
6472
version: "v0.8.0"
6573

6674
- name: Install rust toolchain
75+
if: steps.build-cache.outputs.cache-hit != 'true'
6776
uses: dtolnay/rust-toolchain@master
6877
with:
6978
toolchain: stable
7079
targets: ${{matrix.rust-target}}
7180

7281
- name: Build rewatch
82+
if: steps.build-cache.outputs.cache-hit != 'true'
7383
run: cargo build --manifest-path rewatch/Cargo.toml --target ${{matrix.rust-target}} --release
7484

7585
- name: Get artifact dir name
@@ -106,7 +116,7 @@ jobs:
106116
- name: Build ninja binary
107117
uses: docker://ghcr.io/rescript-lang/rescript-ci-build:alpine-3.20-ocaml-5.2.0-01
108118
with:
109-
args: sh -c "cd ninja && LDFLAGS=-static python3 configure.py --bootstrap"
119+
args: sh -c "cd ninja && LDFLAGS=-static python configure.py --bootstrap"
110120

111121
- name: "Upload artifacts"
112122
uses: actions/upload-artifact@v4
@@ -213,17 +223,44 @@ jobs:
213223
chmod +x rewatch/rewatch
214224
chmod +x _build/install/default/bin/*
215225
226+
- name: Install dependencies (Linux)
227+
if: runner.os == 'Linux'
228+
uses: awalsh128/[email protected]
229+
with:
230+
# See https://github.com/ocaml/setup-ocaml/blob/b2105f9/packages/setup-ocaml/src/unix.ts#L9
231+
packages: bubblewrap darcs g++-multilib gcc-multilib mercurial musl-tools rsync
232+
version: v1
233+
234+
- name: Setup Python for ninja build
235+
uses: actions/setup-python@v5
236+
with:
237+
python-version: '3.10'
238+
239+
- name: Restore OPAM environment
240+
id: cache-opam-env
241+
uses: actions/cache/restore@v4
242+
with:
243+
path: |
244+
${{ runner.tool_cache }}/opam
245+
~/.opam
246+
_opam
247+
.opam-path
248+
.opam-env
249+
D:\cygwin
250+
D:\.opam
251+
key: opam-env-v8-${{ matrix.os }}-${{ hashFiles('dune-project') }}
252+
216253
- name: Use OCaml ${{matrix.ocaml_compiler}}
217254
uses: ocaml/setup-ocaml@v2
218-
if: matrix.os != 'windows-latest'
255+
if: steps.cache-opam-env.outputs.cache-hit != 'true' && matrix.os != 'windows-latest'
219256
with:
220257
ocaml-compiler: ${{matrix.ocaml_compiler}}
221258
opam-pin: false
222259
opam-depext: false
223260

224-
- name: Use OCaml ${{matrix.ocaml_compiler}} (Win)
261+
- name: Use OCaml ${{matrix.ocaml_compiler}} (Windows)
225262
uses: ocaml/setup-ocaml@v2
226-
if: matrix.os == 'windows-latest'
263+
if: steps.cache-opam-env.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
227264
with:
228265
ocaml-compiler: ocaml-variants.5.2.0+options,ocaml-option-mingw
229266
opam-pin: false
@@ -233,10 +270,74 @@ jobs:
233270
sunset: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
234271
default: https://github.com/ocaml/opam-repository.git
235272
236-
- name: "Install OPAM dependencies"
273+
- name: Get OPAM environment
274+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
275+
run: |
276+
command -v opam | tee .opam-path
277+
opam env > .opam-env
278+
279+
- name: Install OPAM dependencies
280+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
237281
run: opam install . --deps-only
238282

239-
- name: "Build compiler"
283+
- name: Cache OPAM environment
284+
if: steps.cache-opam-env.outputs.cache-hit != 'true'
285+
uses: actions/cache/save@v4
286+
with:
287+
path: |
288+
${{ runner.tool_cache }}/opam
289+
~/.opam
290+
_opam
291+
.opam-path
292+
.opam-env
293+
D:\cygwin
294+
D:\.opam
295+
key: opam-env-v8-${{ matrix.os }}-${{ hashFiles('dune-project') }}
296+
297+
- name: Use cached OPAM environment
298+
if: steps.cache-opam-env.outputs.cache-hit == 'true'
299+
run: |
300+
# https://github.com/ocaml/setup-ocaml/blob/b2105f9/packages/setup-ocaml/src/installer.ts#L33
301+
echo "OPAMVERBOSE=$RUNNER_DEBUG" >> "$GITHUB_ENV"
302+
echo "OPAMCOLOR=always" >> "$GITHUB_ENV"
303+
echo "OPAMCONFIRMLEVEL=unsafe-yes" >> "$GITHUB_ENV"
304+
echo "OPAMERRLOGLEN=0" >> "$GITHUB_ENV"
305+
echo "OPAMPRECISETRACKING=1" >> "$GITHUB_ENV"
306+
echo "OPAMYES=1" >> "$GITHUB_ENV"
307+
308+
if [[ "$RUNNER_OS" != "Windows" ]]; then
309+
echo "OPAMROOT=$HOME/.opam" >> "$GITHUB_ENV"
310+
else
311+
echo "OPAMROOT=D:\\.opam" >> "$GITHUB_ENV"
312+
fi
313+
314+
if [[ "$RUNNER_OS" != "Windows" ]]; then
315+
OPAM_PATH="$(cat .opam-path)"
316+
chmod +x "$OPAM_PATH"
317+
dirname "$OPAM_PATH" >> "$GITHUB_PATH"
318+
319+
else
320+
fsutil behavior query SymlinkEvaluation
321+
fsutil behavior set symlinkEvaluation R2L:1 R2R:1
322+
fsutil behavior query SymlinkEvaluation
323+
324+
CYGWIN="winsymlinks:native"
325+
CYGWIN_ROOT="D:\\cygwin"
326+
CYGWIN_ROOT_BIN="D:\\cygwin\\bin"
327+
CYGWIN_ROOT_WRAPPERBIN="D:\\cygwin\\wrapperbin"
328+
329+
echo "HOME=$USERPROFILE" >> "$GITHUB_ENV"
330+
echo "MSYS=winsymlinks:native" >> "$GITHUB_ENV"
331+
echo "CYGWIN=$CYGWIN" >> "$GITHUB_ENV"
332+
echo "CYGWIN_ROOT=$CYGWIN_ROOT" >> "$GITHUB_ENV"
333+
echo "CYGWIN_ROOT_BIN=$CYGWIN_ROOT_BIN" >> "$GITHUB_ENV"
334+
echo "CYGWIN_ROOT_WRAPPERBIN=$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_ENV"
335+
336+
echo "$CYGWIN_ROOT_WRAPPERBIN" >> "$GITHUB_PATH"
337+
fi
338+
shell: bash
339+
340+
- name: Build compiler
240341
if: runner.os != 'Linux'
241342
run: opam exec -- dune build --display quiet --profile release
242343

@@ -248,7 +349,7 @@ jobs:
248349
- name: Install npm packages
249350
run: npm ci --ignore-scripts
250351

251-
- name: "Windows: Use MSVC for ninja build"
352+
- name: Setup MSVC for ninja build (Windows)
252353
if: runner.os == 'Windows'
253354
uses: TheMrMilchmann/setup-msvc-dev@v3
254355
with:
@@ -304,10 +405,6 @@ jobs:
304405
run: node scripts/ciTest.js -mocha -theme -format
305406

306407
# Build the playground compiler on the fastest runner (ubuntu-latest)
307-
- name: Install JSOO
308-
if: matrix.os == 'ubuntu-latest'
309-
run: opam install js_of_ocaml.5.8.1
310-
311408
- name: Build playground compiler
312409
if: matrix.os == 'ubuntu-latest'
313410
run: |

dune-project

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
(= 0.26.2))
2525
(cppo
2626
(= 1.6.9))
27-
(js_of_ocaml-compiler
27+
(js_of_ocaml
2828
(= 5.8.1))
2929
(ounit2
3030
(= 2.2.7))

ninja/misc/ci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
22

33
import os
44

ninja/misc/output_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
22

33
"""Runs ./ninja and checks if the output is correct.
44

rescript.opam

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ depends: [
1010
"ocaml" {>= "4.10"}
1111
"ocamlformat" {= "0.26.2"}
1212
"cppo" {= "1.6.9"}
13-
"js_of_ocaml-compiler" {= "5.8.1"}
13+
"js_of_ocaml" {= "5.8.1"}
1414
"ounit2" {= "2.2.7"}
1515
"reanalyze" {= "2.25.1"}
1616
"dune"

scripts/buildNinjaBinary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require("path");
55

66
const platform = process.platform;
77
const ninjaDir = path.join(__dirname, "..", "ninja");
8-
const buildCommand = "python3 configure.py --bootstrap --verbose";
8+
const buildCommand = "python configure.py --bootstrap --verbose";
99

1010
if (platform === "win32") {
1111
// On Windows, the build uses the MSVC compiler which needs to be on the path.

0 commit comments

Comments
 (0)