Commit bf572be5

bf572be576e3Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

ci: cache build/test-results across CI runs

Each test rebuilds its parse→analyze→codegen→cc→link→run chain on every CI invocation; the per-test fork-exec cost adds up enough that Windows takes ~2x the Linux/macOS wall time.

Cache build/test-results keyed on the hash of every file that affects a test outcome (test/, compiler sources, runtime sources, Makefile). On hit, refresh .ok mtimes so make's incremental tracking skips them through the stamp dependency that make all just touched. Any input change misses the cache and reruns every test; no restore-keys fallback, since a partial-match restore + mtime touch would risk trusting stale .ok files ([[test-ok-stale]]).

Expected to help most on CI retries of the same commit (flaky-test reruns) and docs-only PRs. Per-PR effect for normal compiler/test work is limited because any change to test/ or the compiler invalidates the whole cache. We'll see if it pays for itself.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
bf572be576e3
Parent
2a8d002f5436

.github/workflows/ci.ymlmodifiedView file

@@ -45,6 +45,19 @@
4545 if: runner.os == 'macOS'
4646 run: echo "/opt/homebrew/opt/coreutils/libexec/gnubin" >> "$GITHUB_PATH"
4747
48+ # When every input the test result depends on is unchanged
49+ # (test/, compiler source, runtime source, Makefile), the
50+ # prior run's `.ok` stamps are still valid. Pulling them down
51+ # lets `make test` short-circuit each test via mtime tracking.
52+ # The hash key is the sole invalidator — any change to any
53+ # input file misses the cache and reruns every test. See
54+ # the post-build `touch` step for why mtimes need a refresh.
55+ - name: Restore test-results cache
56+ uses: actions/cache@v4
57+ with:
58+ path: build/test-results
59+ key: tests-${{ matrix.os }}-${{ matrix.cc }}-${{ hashFiles('test/**', 'spinel_parse.c', 'spinel_analyze.rb', 'spinel_codegen.rb', 'compiler_helpers.rb', 'node_table_loader.rb', 'lib/**', 'Makefile') }}
60+
4861 - name: Fetch libprism sources
4962 run: make deps
5063
@@ -54,6 +67,17 @@
5467 - name: Build (parse + regexp + codegen)
5568 run: make -j$(getconf _NPROCESSORS_ONLN) LTO=0 all
5669
70+ # `make all` just touched the compiler-binary stamps that every
71+ # `.ok` depends on, so without this refresh, make would treat
72+ # every cached `.ok` as stale and rerun each test. The cache
73+ # key already covers every input that affects the test outcome,
74+ # so bumping mtimes here is safe.
75+ - name: Refresh test-results mtimes
76+ run: |
77+ if [ -d build/test-results ]; then
78+ find build/test-results -name '*.ok' -exec touch {} +
79+ fi
80+
5781 - name: Run tests
5882 # OPT=-O0 cuts cc time per test (each .rb compiles its own
5983 # generated C with $(CFLAGS) -Werror). Type-checking still
@@ -120,12 +144,27 @@
120144 make --version | head -1
121145 sccache --version
122146
147+ # See the posix job for the cache contract. Windows is the
148+ # biggest beneficiary because its per-test fork-exec cost
149+ # dwarfs the cache-restore step.
150+ - name: Restore test-results cache
151+ uses: actions/cache@v4
152+ with:
153+ path: build/test-results
154+ key: tests-windows-mingw-gcc-${{ hashFiles('test/**', 'spinel_parse.c', 'spinel_analyze.rb', 'spinel_codegen.rb', 'compiler_helpers.rb', 'node_table_loader.rb', 'lib/**', 'Makefile') }}
155+
123156 - name: Fetch libprism sources
124157 run: make deps
125158
126159 - name: Build (parse + regexp + codegen)
127160 run: make -j$(nproc) LTO=0 all
128161
162+ - name: Refresh test-results mtimes
163+ run: |
164+ if [ -d build/test-results ]; then
165+ find build/test-results -name '*.ok' -exec touch {} +
166+ fi
167+
129168 - name: Run tests
130169 run: make -j$(nproc) test OPT=-O0
131170