Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ When the option `cache-dependency-path` is specified, the hash is based on the m

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).

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).

The cache input is optional, and caching is turned off by default.

**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.
Expand Down
12 changes: 12 additions & 0 deletions __tests__/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@ describe('dependency cache', () => {
describe('restore', () => {
let spyCacheRestore: any;
let spyGlobHashFiles: any;
let spySetOutput: any;

beforeEach(() => {
spyCacheRestore = (cache.restoreCache as any).mockImplementation(
(paths: string[], primaryKey: string) => Promise.resolve(undefined)
);
spyGlobHashFiles = glob.hashFiles as jest.Mock;
spyGlobHashFiles.mockResolvedValue('hash-stub');
spySetOutput = core.setOutput as jest.Mock;
spySetOutput.mockImplementation(() => null);
spyWarning.mockImplementation(() => null);
});

Expand Down Expand Up @@ -175,6 +178,15 @@ describe('dependency cache', () => {
expect(spyWarning).not.toHaveBeenCalled();
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found');
});
it('sets the cache-primary-key output', async () => {
createFile(join(workspace, 'pom.xml'));

await restore('maven', '');
expect(spySetOutput).toHaveBeenCalledWith(
'cache-primary-key',
expect.stringContaining('setup-java-')
);
});
it('downloads cache based on maven-wrapper.properties', async () => {
createDirectory(join(workspace, '.mvn'));
createDirectory(join(workspace, '.mvn', 'wrapper'));
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ outputs:
description: 'Path to where the java environment has been installed (same as $JAVA_HOME)'
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
cache-primary-key:
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.'
runs:
using: 'node24'
main: 'dist/setup/index.js'
Expand Down
1 change: 1 addition & 0 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99735,6 +99735,7 @@ async function restore(id, cacheDependencyPath) {
const primaryKey = await 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 = await cache.restoreCache(packageManager.path, primaryKey);
if (matchedKey) {
Expand Down
1 change: 1 addition & 0 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130957,6 +130957,7 @@ async function restore(id, cacheDependencyPath) {
const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath);
core_debug(`primary key is ${primaryKey}`);
saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
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 = await restoreCache(packageManager.path, primaryKey);
if (matchedKey) {
Expand Down
1 change: 1 addition & 0 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export async function restore(id: string, cacheDependencyPath: string) {
const primaryKey = await 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 = await cache.restoreCache(packageManager.path, primaryKey);
Expand Down
Loading