feat: expose cache-primary-key output (#597) [v5 backport] (#1089)

* feat: expose cache-primary-key output (#597)

Backport of the cache-primary-key output to the v5 release line.

Expose the primary cache key computed by the caching logic as a new
`cache-primary-key` action output, so workflows can compose the built-in
setup-java cache key with actions/cache or actions/cache/restore across
steps and dependent jobs.

- src/cache.ts: set the `cache-primary-key` output in restore()
- action.yml: declare the new output
- README.md: document the new output
- __tests__/cache.test.ts: assert the output is set
- dist: rebuild (CommonJS)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Apply PR #1088 review suggestions to v5 backport

Port the review feedback from the main-line PR (#1088) into the v5 backport:
- src/cache.ts: use the STATE_CACHE_PRIMARY_KEY constant for the output name
  instead of a duplicated string literal
- action.yml / README.md: clarify that the output is also empty when caching
  is skipped (e.g. the cache service is unavailable)
- dist: rebuild

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Bruno Borges
2026-07-08 16:04:08 -04:00
committed by GitHub
parent 62df799a9c
commit 513edc4f87
6 changed files with 21 additions and 0 deletions

View File

@@ -52056,6 +52056,7 @@ function restore(id, cacheDependencyPath) {
const primaryKey = yield computeCacheKey(packageManager, cacheDependencyPath);
core.debug(`primary key is ${primaryKey}`);
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey);
if (matchedKey) {