Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

stuartleeks
Copy link

Add cache-primary-key and cache-matched-key outputs from actions/cache/restore action to actions/cache action

Description

The actions/cache/restore action provides cache-hit, cache-primary-key and cache-matched-key outputs, but the actions/cache only exposes cache-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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (add or update README or docs)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Copilot Copilot AI review requested due to automatic review settings May 8, 2025 17:03
@stuartleeks stuartleeks requested a review from a team as a code owner May 8, 2025 17:03
Copy link

@Copilot Copilot AI left a 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]
]);
Copy link
Preview

Copilot AI May 8, 2025

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.

Suggested change
]);
]);
/**
* 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.
*/

Copilot uses AI. Check for mistakes.

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