Skip to content

Commit a8eade7

Browse files
perf(ci): skip Docker build for Linux cargo check when inputs unchanged
Add hash-based cache check using actions/cache@v4 before Docker builder setup in test.yml. Hash covers Cargo manifests, lockfile, Rust source, cargo config, and the Dockerfile. On cache hit, the entire Docker setup/build/teardown is skipped, eliminating ~65s of orchestration overhead when no Rust source has changed. Expected: ~75s -> ~5s on cache hit (93% reduction). Cache miss path is unchanged β€” full Docker build runs as before. release.yml is unaffected (always builds artifacts).
1 parent ec25d06 commit a8eade7

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

β€Ž.github/workflows/test.ymlβ€Ž

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,41 @@ jobs:
123123
steps:
124124
- uses: actions/checkout@v6
125125

126+
# Linux: skip Docker build when cargo-check inputs haven't changed.
127+
# Hash covers everything the Dockerfile check target copies:
128+
# Cargo manifests, lockfile, Rust source, cargo config, and the
129+
# Dockerfile itself. Cache hit means cargo check already passed
130+
# for these exact inputs β€” no need to spin up Docker at all.
131+
- name: Check cargo-check cache (Linux)
132+
if: runner.os == 'Linux'
133+
id: cargo-check-cache
134+
uses: actions/cache@v4
135+
with:
136+
path: .cargo-check-sentinel
137+
key: linux-cargo-check-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'crates/**/*.rs', 'crates/**/Cargo.toml', 'crates/**/.cargo/**', 'docker/linux/Dockerfile') }}
138+
139+
- name: Skip notice (Linux)
140+
if: runner.os == 'Linux' && steps.cargo-check-cache.outputs.cache-hit == 'true'
141+
run: echo "cargo check inputs unchanged β€” skipping Docker build"
142+
126143
# Linux: containerized cargo check with Blacksmith Docker layer caching
127144
- name: Setup Docker builder (Linux)
128-
if: runner.os == 'Linux'
145+
if: runner.os == 'Linux' && steps.cargo-check-cache.outputs.cache-hit != 'true'
129146
uses: useblacksmith/setup-docker-builder@v1
130147

131148
- name: Cargo check (Linux)
132-
if: runner.os == 'Linux'
149+
if: runner.os == 'Linux' && steps.cargo-check-cache.outputs.cache-hit != 'true'
133150
uses: useblacksmith/build-push-action@v2
134151
with:
135152
context: .
136153
file: docker/linux/Dockerfile
137154
target: check
138155
push: false
139156

157+
- name: Write cargo-check sentinel (Linux)
158+
if: runner.os == 'Linux' && steps.cargo-check-cache.outputs.cache-hit != 'true'
159+
run: date -u > .cargo-check-sentinel
160+
140161
# macOS/Windows: bare-metal setup + cargo check
141162
- name: Setup Tauri build environment
142163
if: runner.os != 'Linux'

β€Ž.gitignoreβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ETC
22
*.db*
33
*.sqlite
4+
.cargo-check-sentinel
45
.playwright-mcp/
56
.sisyphus/
67
.task/

β€Ždocs/builds.mdβ€Ž

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,17 @@ Linux amd64 builds use a multi-stage Dockerfile (`docker/linux/Dockerfile`) for
416416

417417
In CI, [Blacksmith Docker layer caching](https://docs.blacksmith.sh/blacksmith-caching/docker-builds) persists all layers on NVMe-backed sticky disks. After the first run, the `deps` and `cook` layers are cached β€” subsequent runs only rebuild changed source code.
418418

419+
The test workflow (`test.yml`) uses a hash-based skip optimization: before spinning up Docker, it computes a hash of all files that affect `cargo check` output (`Cargo.toml`, `Cargo.lock`, `crates/**/*.rs`, crate manifests, cargo config, and the Dockerfile). If the hash matches a previous successful run (via `actions/cache`), the entire Docker build is skipped. This eliminates ~65s of Docker orchestration overhead on runs where Rust source hasn't changed β€” reducing the Linux job from ~75s to ~5s on cache hit.
420+
419421
```yaml
420-
# test.yml β€” cargo check only
421-
- uses: useblacksmith/setup-docker-builder@v1
422-
- uses: useblacksmith/build-push-action@v2
422+
# test.yml β€” cargo check only (with hash-based skip)
423+
- uses: actions/cache@v4 # check if inputs changed
424+
- uses: useblacksmith/setup-docker-builder@v1 # skip if cache hit
425+
- uses: useblacksmith/build-push-action@v2 # skip if cache hit
423426
with:
424427
target: check
425428

426-
# release.yml β€” full build + bundle, extract artifacts
429+
# release.yml β€” full build + bundle, extract artifacts (no skip)
427430
- uses: useblacksmith/setup-docker-builder@v1
428431
- uses: useblacksmith/build-push-action@v2
429432
with:

0 commit comments

Comments
Β (0)