Add source-keyed target cache support#349
Open
garysassano wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #348
Summary
This adds an opt-in
target-keyinput for source-keyed workspace target caching.When
target-keyis set together withcache-targets: trueandcache-workspace-crates: true,rust-cachenow caches workspace target directories separately from Cargo home/dependency state:Existing behavior is unchanged unless
target-keyis provided.Why
cache-workspace-crates: trueis useful for workspaces that intentionally cache local crate artifacts. However, the current target cache key intentionally focuses on Rust/Cargo environment, manifests, lockfiles, and config rather than workspace source contents.That is the right default for dependency-oriented caching, but it creates a corner case for users who opt into workspace crate artifact caching:
This PR preserves the current default while providing an escape hatch for the users who deliberately want workspace target artifacts to be keyed by source state.
API
The action does not try to compute a source key itself. The user can choose the fingerprint that matches their repository, for example:
If
target-keyis set withoutcache-targets: trueorcache-workspace-crates: true, the action warns and falls back to existing behavior.Implementation Notes
CacheConfignow records independent cargo and target cache state when the target cache mode is enabled.cache-hitistrueonly when all active cache groups are exact hits.target-keyis empty.Example generated keys:
Verification
Local checks:
I also tested this against a private production-sized Rust workspace with 30 Cargo packages and 11 independent binary artifact builds. The relevant results were:
full match: truein every binary job.Representative log lines from the second run:
Comparison from that private workflow:
3m02srust-cache@v2and notarget-key1m14s18s-42starget-key37s0.3sPer-binary timings
GitHub reports step durations rounded to whole seconds. A
0sCargo build phase means the measured step was below one second.2m47s2m09s1m07s34s35s0s2m33s1m55s1m11s38s36s0s3m02s1m56s1m11s39s36s1s2m56s2m17s1m14s42s37s0s2m37s2m01s1m11s42s35s0s2m27s1m50s51s18s35s0s2m35s1m58s1m10s38s35s1s2m32s1m55s59s28s36s1s2m33s1m55s1m09s38s35s1s2m38s2m01s1m13s42s36s1s2m33s1m55s59s22s34s1sRepresentative upstream baseline log shape:
With this PR and a source-keyed target cache, the repeated run restored exact target-cache hits and reduced the Cargo build phases to roughly
0.3s, with noCompilinglines.Compatibility
target-keyis set.directories are cached separately and source changes create new target keys.
That tradeoff is intentional for workloads that need true repeated-run no-op
behavior for workspace artifacts.