GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: expose cache-primary-key output (#597) [v5 backport] (#1089) · actions/setup-java@513edc4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.md
  • __tests__
    • cache.test.ts
  • action.yml
  • dist
    • cleanup
      • index.js
    • setup
      • index.js
  • src
    • cache.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ When the option `cache-dependency-path` is specified, the hash is based on the m
145145

146146
The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs).
147147

148+
The workflow output `cache-primary-key` exposes the primary cache key computed by the action for the configured build tool. It is useful for composing with [`actions/cache`](https://github.com/actions/cache) or [`actions/cache/restore`](https://github.com/actions/cache/tree/main/restore) in later steps or dependent jobs that need to reuse the exact same key. It is empty when caching is not enabled or when caching is skipped (for example, when the cache service is unavailable).
149+
148150
The cache input is optional, and caching is turned off by default.
149151

150152
**Maven Wrapper:** when `cache: 'maven'` is enabled, the action also caches and restores the Maven Wrapper distribution downloaded to `~/.m2/wrapper/dists` (in addition to the local repository), so wrapper-based (`./mvnw`) builds don't re-download the wrapper on every run. This is keyed on `**/.mvn/wrapper/maven-wrapper.properties` as shown above.
Collapse file

‎__tests__/cache.test.ts‎

Copy file name to clipboardExpand all lines: __tests__/cache.test.ts
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ describe('dependency cache', () => {
7878
ReturnType<typeof glob.hashFiles>,
7979
Parameters<typeof glob.hashFiles>
8080
>;
81+
let spySetOutput: jest.SpyInstance<
82+
ReturnType<typeof core.setOutput>,
83+
Parameters<typeof core.setOutput>
84+
>;
8185

8286
beforeEach(() => {
8387
spyCacheRestore = jest
@@ -86,6 +90,7 @@ describe('dependency cache', () => {
8690
Promise.resolve(undefined)
8791
);
8892
spyGlobHashFiles = jest.spyOn(glob, 'hashFiles');
93+
spySetOutput = jest.spyOn(core, 'setOutput').mockImplementation(() => {});
8994
spyWarning.mockImplementation(() => null);
9095
});
9196

@@ -120,6 +125,15 @@ describe('dependency cache', () => {
120125
expect(spyWarning).not.toHaveBeenCalled();
121126
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found');
122127
});
128+
it('sets the cache-primary-key output', async () => {
129+
createFile(join(workspace, 'pom.xml'));
130+
131+
await restore('maven', '');
132+
expect(spySetOutput).toHaveBeenCalledWith(
133+
'cache-primary-key',
134+
expect.stringContaining('setup-java-')
135+
);
136+
});
123137
it('downloads cache based on maven-wrapper.properties', async () => {
124138
createDirectory(join(workspace, '.mvn'));
125139
createDirectory(join(workspace, '.mvn', 'wrapper'));
Collapse file

‎action.yml‎

Copy file name to clipboardExpand all lines: action.yml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ outputs:
103103
description: 'Path to where the java environment has been installed (same as $JAVA_HOME)'
104104
cache-hit:
105105
description: 'A boolean value to indicate an exact match was found for the primary key'
106+
cache-primary-key:
107+
description: 'The primary cache key computed by the action for the configured build tool. Empty when caching is not enabled or when caching is skipped (e.g. cache service unavailable). Useful for composing with actions/cache or actions/cache/restore across jobs.'
106108
runs:
107109
using: 'node24'
108110
main: 'dist/setup/index.js'
Collapse file

‎dist/cleanup/index.js‎

Copy file name to clipboardExpand all lines: dist/cleanup/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52056,6 +52056,7 @@ function restore(id, cacheDependencyPath) {
5205652056
const primaryKey = yield computeCacheKey(packageManager, cacheDependencyPath);
5205752057
core.debug(`primary key is ${primaryKey}`);
5205852058
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
52059+
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
5205952060
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
5206052061
const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey);
5206152062
if (matchedKey) {
Collapse file

‎dist/setup/index.js‎

Copy file name to clipboardExpand all lines: dist/setup/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77921,6 +77921,7 @@ function restore(id, cacheDependencyPath) {
7792177921
const primaryKey = yield computeCacheKey(packageManager, cacheDependencyPath);
7792277922
core.debug(`primary key is ${primaryKey}`);
7792377923
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
77924+
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
7792477925
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
7792577926
const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey);
7792677927
if (matchedKey) {
Collapse file

‎src/cache.ts‎

Copy file name to clipboardExpand all lines: src/cache.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export async function restore(id: string, cacheDependencyPath: string) {
118118
const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath);
119119
core.debug(`primary key is ${primaryKey}`);
120120
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
121+
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
121122

122123
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
123124
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.