GeezerVison is showing github.com — feat: expose cache-primary-key output (#597) [v5 backport] (#1089) · actions/setup-java@513edc4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -145,6 +145,8 @@ When the option `cache-dependency-path` is specified, the hash is based on the m | 145 | 145 |
| 146 | 146 | 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). | 147 | 147 |
| | 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 | + | 148 | 150 | The cache input is optional, and caching is turned off by default. | 149 | 151 |
| 150 | 152 | **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 Copy file name to clipboardExpand all lines: __tests__/cache.test.ts +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,6 +78,10 @@ describe('dependency cache', () => { | 78 | 78 | ReturnType<typeof glob.hashFiles>, | 79 | 79 | Parameters<typeof glob.hashFiles> | 80 | 80 | >; | | 81 | + let spySetOutput: jest.SpyInstance< | | 82 | + ReturnType<typeof core.setOutput>, | | 83 | + Parameters<typeof core.setOutput> | | 84 | + >; | 81 | 85 |
| 82 | 86 | beforeEach(() => { | 83 | 87 | spyCacheRestore = jest | @@ -86,6 +90,7 @@ describe('dependency cache', () => { | 86 | 90 | Promise.resolve(undefined) | 87 | 91 | ); | 88 | 92 | spyGlobHashFiles = jest.spyOn(glob, 'hashFiles'); | | 93 | + spySetOutput = jest.spyOn(core, 'setOutput').mockImplementation(() => {}); | 89 | 94 | spyWarning.mockImplementation(() => null); | 90 | 95 | }); | 91 | 96 |
| @@ -120,6 +125,15 @@ describe('dependency cache', () => { | 120 | 125 | expect(spyWarning).not.toHaveBeenCalled(); | 121 | 126 | expect(spyInfo).toHaveBeenCalledWith('maven cache is not found'); | 122 | 127 | }); | | 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 | + }); | 123 | 137 | it('downloads cache based on maven-wrapper.properties', async () => { | 124 | 138 | createDirectory(join(workspace, '.mvn')); | 125 | 139 | createDirectory(join(workspace, '.mvn', 'wrapper')); | |
Collapse file Copy file name to clipboardExpand all lines: action.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -103,6 +103,8 @@ outputs: | 103 | 103 | description: 'Path to where the java environment has been installed (same as $JAVA_HOME)' | 104 | 104 | cache-hit: | 105 | 105 | 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.' | 106 | 108 | runs: | 107 | 109 | using: 'node24' | 108 | 110 | main: 'dist/setup/index.js' | |
Collapse file Copy file name to clipboardExpand all lines: dist/cleanup/index.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52056,6 +52056,7 @@ function restore(id, cacheDependencyPath) { | 52056 | 52056 | const primaryKey = yield computeCacheKey(packageManager, cacheDependencyPath); | 52057 | 52057 | core.debug(`primary key is ${primaryKey}`); | 52058 | 52058 | core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey); | | 52059 | + core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey); | 52059 | 52060 | // No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269) | 52060 | 52061 | const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey); | 52061 | 52062 | if (matchedKey) { | |
Collapse file Copy file name to clipboardExpand all lines: dist/setup/index.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -77921,6 +77921,7 @@ function restore(id, cacheDependencyPath) { | 77921 | 77921 | const primaryKey = yield computeCacheKey(packageManager, cacheDependencyPath); | 77922 | 77922 | core.debug(`primary key is ${primaryKey}`); | 77923 | 77923 | core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey); | | 77924 | + core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey); | 77924 | 77925 | // No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269) | 77925 | 77926 | const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey); | 77926 | 77927 | if (matchedKey) { | |
Collapse file Copy file name to clipboardExpand all lines: src/cache.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -118,6 +118,7 @@ export async function restore(id: string, cacheDependencyPath: string) { | 118 | 118 | const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath); | 119 | 119 | core.debug(`primary key is ${primaryKey}`); | 120 | 120 | core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey); | | 121 | + core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey); | 121 | 122 |
| 122 | 123 | // No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269) | 123 | 124 | const matchedKey = await cache.restoreCache(packageManager.path, primaryKey); | |
|