-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add cache-primary-key and cache-matched-key outputs to actions/cache #1604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds functionality to expose the new outputs "cache-primary-key" and "cache-matched-key" from the cache restore process via the actions/cache action.
- Updated stateProvider.ts to invoke a new helper function (stateToOutput) to set these outputs.
- Updated action.yml, test files, and documentation (README.md) to support and validate these new outputs.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/stateProvider.ts | Refactored setState implementations to trigger output setting for new keys. |
| action.yml | Added definitions for the new outputs with appropriate descriptions. |
| tests/stateProvider.test.ts | Updated expected output calls to reflect the additional outputs. |
| tests/restoreImpl.test.ts | Updated output expectations in tests to include the new outputs. |
| tests/restore.test.ts | Updated tests to check for the new outputs in various cache restore scenarios. |
| README.md | Updated documentation to include descriptions of the new outputs. |
| const stateToOutputMap = new Map<string, string>([ | ||
| [State.CacheMatchedKey, Outputs.CacheMatchedKey], | ||
| [State.CachePrimaryKey, Outputs.CachePrimaryKey] | ||
| ]); |
Copilot
AI
May 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding a brief comment above the 'stateToOutput' function explaining its purpose and usage to aid future maintainability.
| ]); | |
| ]); | |
| /** | |
| * Maps a state key to an output key using `stateToOutputMap` and sets the corresponding output value. | |
| * This function ensures that state changes are reflected in the output for subsequent steps. | |
| */ |
|
EDIT: I missed that the examples were using |
Add
cache-primary-keyandcache-matched-keyoutputs fromactions/cache/restoreaction toactions/cacheactionDescription
The
actions/cache/restoreaction providescache-hit,cache-primary-keyandcache-matched-keyoutputs, but theactions/cacheonly exposescache-hit.Motivation and Context
Currently, determining the cache key that was matched requires using restore/save separately. This PR enables using the primary/matched cache keys in subsequent steps using
actions/cache.How Has This Been Tested?
Updated test code in the repo. Also the PR branch from another repo
Screenshots (if appropriate):
Types of changes
Checklist: