Skip to content

Commit a893e00

Browse files
kingpanther13claude
andcommitted
ci(test): cache apt downloads and node_modules for the unit-tests job
The unit-tests "Install git and Node.js" step was 44 s — almost all of it network download of the nodejs / npm .deb. The "Install JS test dependencies" step is 1 s when node_modules is fresh but can grow as deps change. - Cache /var/cache/apt/archives keyed on a stable string (apt package set rarely changes). Disable docker-clean and set Keep-Downloaded- Packages so the cached .debs survive install for the next run. apt install still runs (unpacks from local cache, ~3-5 s) but skips the network leg. - Cache tests/js/node_modules keyed on package-lock.json so dep bumps invalidate cleanly. `npm ci` short-circuits when the tree matches. Expected first-cold-cache run: unchanged (~45 s install). Cache hits: ~5 s for both steps combined. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f04c5d3 commit a893e00

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

.github/workflows/pr.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,28 @@ jobs:
128128
timeout-minutes: 5
129129

130130
steps:
131+
- name: Restore apt download cache
132+
# Cache /var/cache/apt/archives so the nodejs .deb (~30 MB) and its
133+
# deps don't re-download on every PR — the bulk of "Install git and
134+
# Node.js" was the network download, not the extract. apt-get
135+
# install still runs (unpack is fast); we're just skipping the
136+
# download leg on cache hit.
137+
uses: actions/cache@v5
138+
with:
139+
path: /var/cache/apt/archives
140+
key: apt-trixie-git-nodejs-npm-v1
141+
131142
- name: Install git and Node.js
132143
# Node + npm power the JS behaviour tests under tests/src/unit/
133144
# (harness in tests/js/) — they spawn `node tests/js/harness.mjs`
134145
# to drive rendered <script> bodies through JSDOM. Without node
135146
# the tests skip; install here so coverage actually runs.
136147
run: |
148+
# Keep cached .debs after install so the cache stays warm for
149+
# future runs (default Debian behaviour deletes them).
150+
rm -f /etc/apt/apt.conf.d/docker-clean
151+
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' \
152+
> /etc/apt/apt.conf.d/keep-downloaded
137153
apt-get update -qq
138154
apt-get install -y -qq git nodejs npm >/dev/null 2>&1
139155
@@ -144,9 +160,19 @@ jobs:
144160
- name: Install Python dependencies
145161
run: uv sync --all-extras --dev
146162

163+
- name: Restore JS test node_modules cache
164+
# Lockfile-keyed so a dependency bump invalidates cleanly. `npm ci`
165+
# is still safe to run on cache hit (it short-circuits when the
166+
# tree already matches the lockfile).
167+
uses: actions/cache@v5
168+
with:
169+
path: tests/js/node_modules
170+
key: tests-js-node-modules-${{ hashFiles('tests/js/package-lock.json') }}
171+
147172
- name: Install JS test dependencies (jsdom, esbuild)
148173
# `npm ci` enforces package-lock.json — same reproducibility
149-
# discipline as uv.lock on the Python side.
174+
# discipline as uv.lock on the Python side. No-op on cache hit
175+
# if node_modules matches the lockfile.
150176
run: npm ci --prefix tests/js
151177

152178
- name: Run unit tests

0 commit comments

Comments
 (0)