Skip to content

Conversation

@AndreKurait
Copy link

Summary

When running on PR or push events, prefer cache entries from the base commit (PR base branch) or previous commit (push before SHA) over generic fallbacks. This improves cache hit rates for incremental builds.

Changes

Modified sources/src/caching/cache-key.ts to add a new restore key that targets the base/previous commit SHA.

Restore key hierarchy is now:

  1. Exact SHA match
  2. Same job+matrix (any SHA)
  3. Same job+matrix with base/previous commit SHA (NEW)
  4. Same job (any matrix)
  5. Same OS/environment

Event Support

  • pull_request / pull_request_target: Uses payload.pull_request.base.sha
  • push: Uses payload.before (skips Git null SHA for new branches)
  • Other events: No base commit key added (falls back to existing behavior)

Rationale

For PR workflows, the cache from the base branch is often more relevant than a random previous run. This change prioritizes that cache entry while maintaining backward compatibility with the existing fallback chain.

When running on PR or push events, prefer cache entries from the base
commit (PR base branch) or previous commit (push before SHA) over
generic fallbacks. This improves cache hit rates for incremental builds.

Restore key hierarchy is now:
1. Exact SHA match
2. Same job+matrix (any SHA)
3. Same job+matrix with base/previous commit SHA (NEW)
4. Same job (any matrix)
5. Same OS/environment

Signed-off-by: Andre Kurait <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant