Skip to content

Commit 6ccdf25

Browse files
committed
ci(dylint): gate stale-cache invalidation on partial restore
Only delete `target/dylint` when `actions/cache` reported a primary-key miss. The `cache-hit` output is `true` only when the exact `key` matched, which means the cached `target/dylint/libraries/...so` was built for the current `dylint.toml`. Any `restore-keys` fallback (including the looser third entry that ignores `dylint.toml`) leaves `cache-hit` as `false`, and that is the case where the cached `.so` may not match the in-tree `dylint.toml`. Always running the cleanup needlessly rebuilds the perfectionist library and its dependency chain on every run, which makes the `target` portion of the cache useless.
1 parent 7310d32 commit 6ccdf25

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

.github/workflows/dylint.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- uses: actions/checkout@v6
1515

1616
- name: Cache
17+
id: cache
1718
uses: actions/cache@v5
1819
timeout-minutes: 2
1920
continue-on-error: true
@@ -39,14 +40,17 @@ jobs:
3940
shell: bash
4041
run: cargo install --locked cargo-dylint dylint-link
4142

42-
# The third entry in `restore-keys` above falls back to any cache for the
43-
# same `rust-toolchain`, including caches built against an older
44-
# `dylint.toml`. `cargo dylint` does not always detect a changed `git`
45-
# `rev`/`tag` and may reuse the cached `libperfectionist.so` from the
46-
# prior `dylint.toml`. Removing the dylint cache directory forces a
47-
# fresh library build for the current `dylint.toml`. The `~/.cargo`
48-
# registry cache is preserved, so dependency downloads stay fast.
43+
# When the primary cache key did not match exactly, the cache was either
44+
# missed entirely or restored from one of the looser `restore-keys`
45+
# entries. The third entry ignores `dylint.toml`, so the restored
46+
# `target/dylint/libraries/libperfectionist.so` may have been built from
47+
# a different `dylint.toml`. `cargo dylint` does not always detect a
48+
# changed `git` `rev`/`tag` and reuses the cached `.so` as-is. Remove
49+
# the dylint build directory in this case so the library rebuilds from
50+
# the in-tree `dylint.toml`. On an exact cache hit the `.so` matches
51+
# the current `dylint.toml` and the rebuild is skipped.
4952
- name: Invalidate stale dylint build artifacts
53+
if: steps.cache.outputs.cache-hit != 'true'
5054
shell: bash
5155
run: rm -rf target/dylint
5256

0 commit comments

Comments
 (0)