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
64 changes: 53 additions & 11 deletions __tests__/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,16 @@ describe('dependency cache', () => {
});
describe('save', () => {
let spyCacheSave: any;
let spyGlobCreate: jest.Mock;

beforeEach(() => {
spyCacheSave = (cache.saveCache as any).mockImplementation(
(paths: string[], key: string) => Promise.resolve(0)
);
spyGlobCreate = glob.create as jest.Mock;
spyGlobCreate.mockResolvedValue({
glob: jest.fn(() => Promise.resolve(['wrapper-path']))
});
spyWarning.mockImplementation(() => null);
});

Expand Down Expand Up @@ -543,7 +548,7 @@ describe('dependency cache', () => {

await save('maven');
expect(spyCacheSave).toHaveBeenCalledWith(
[join(os.homedir(), '.m2', 'wrapper', 'dists')],
['wrapper-path'],
'setup-java-maven-wrapper-key'
);
expect(spyWarning).not.toHaveBeenCalled();
Expand Down Expand Up @@ -572,6 +577,11 @@ describe('dependency cache', () => {
});
it('does not fail the post step when the wrapper distribution path is missing', async () => {
createFile(join(workspace, 'pom.xml'));
createDirectory(join(workspace, '.mvn'));
createDirectory(join(workspace, '.mvn', 'wrapper'));
createFile(
join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties')
);
(core.getState as jest.Mock<any>).mockImplementation((name: any) => {
switch (name) {
case 'cache-primary-key':
Expand All @@ -584,17 +594,19 @@ describe('dependency cache', () => {
return '';
}
});
spyCacheSave.mockImplementation((paths: string[]) =>
paths.includes(join(os.homedir(), '.m2', 'wrapper', 'dists'))
? Promise.reject(
new cache.ValidationError(
'Path Validation Error: Path(s) specified in the action for caching do(es) not exist'
)
)
: Promise.resolve(0)
);
spyGlobCreate.mockResolvedValue({
glob: jest.fn(() => Promise.resolve([]))
});

await expect(save('maven')).resolves.toBeUndefined();
expect(spyCacheSave).not.toHaveBeenCalledWith(
[join(os.homedir(), '.m2', 'wrapper', 'dists')],
expect.any(String)
);
expect(spyCacheSave).toHaveBeenCalledWith(
[join(os.homedir(), '.m2', 'repository')],
'setup-java-cache-primary-key'
);
expect(spyWarning).not.toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -666,7 +678,7 @@ describe('dependency cache', () => {

await save('gradle');
expect(spyCacheSave).toHaveBeenCalledWith(
[join(os.homedir(), '.gradle', 'wrapper')],
['wrapper-path'],
'setup-java-gradle-wrapper-key'
);
expect(spyWarning).not.toHaveBeenCalled();
Expand All @@ -693,6 +705,36 @@ describe('dependency cache', () => {
expect.any(String)
);
});
it('does not fail the post step when the wrapper distribution path is missing', async () => {
createFile(join(workspace, 'build.gradle'));
createFile(join(workspace, 'gradle-wrapper.properties'));
(core.getState as jest.Mock<any>).mockImplementation((name: any) => {
switch (name) {
case 'cache-primary-key':
return 'setup-java-cache-primary-key';
case 'cache-matched-key':
return 'setup-java-cache-matched-key';
case 'cache-primary-key-gradle-wrapper':
return 'setup-java-gradle-wrapper-key';
default:
return '';
}
});
spyGlobCreate.mockResolvedValue({
glob: jest.fn(() => Promise.resolve([]))
});

await expect(save('gradle')).resolves.toBeUndefined();
expect(spyCacheSave).not.toHaveBeenCalledWith(
[join(os.homedir(), '.gradle', 'wrapper')],
expect.any(String)
);
expect(spyCacheSave).toHaveBeenCalledWith(
[join(os.homedir(), '.gradle', 'caches')],
'setup-java-cache-primary-key'
);
expect(spyWarning).not.toHaveBeenCalled();
});
});
describe('for sbt', () => {
it('uploads cache even if no build.sbt found', async () => {
Expand Down
10 changes: 9 additions & 1 deletion dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97988,8 +97988,16 @@ async function saveAdditionalCache(packageManager, additionalCache) {
info(`Cache hit occurred on the ${additionalCache.name} primary key ${primaryKey}, not saving cache.`);
return;
}
const globber = await create(additionalCache.path.join('\n'), {
implicitDescendants: false
});
const cachePaths = await globber.glob();
if (cachePaths.length === 0) {
core_debug(`${additionalCache.name} cache paths do not exist, not saving cache.`);
return;
}
try {
const cacheId = await cache_saveCache(additionalCache.path, primaryKey);
const cacheId = await cache_saveCache(cachePaths, primaryKey);
if (cacheId === -1) {
core_debug(`${additionalCache.name} cache was not saved for the key: ${primaryKey}`);
return;
Expand Down
10 changes: 9 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129229,8 +129229,16 @@ async function saveAdditionalCache(packageManager, additionalCache) {
core.info(`Cache hit occurred on the ${additionalCache.name} primary key ${primaryKey}, not saving cache.`);
return;
}
const globber = await glob.create(additionalCache.path.join('\n'), {
implicitDescendants: false
});
const cachePaths = await globber.glob();
if (cachePaths.length === 0) {
core.debug(`${additionalCache.name} cache paths do not exist, not saving cache.`);
return;
}
try {
const cacheId = await cache.saveCache(additionalCache.path, primaryKey);
const cacheId = await cache.saveCache(cachePaths, primaryKey);
if (cacheId === -1) {
core.debug(`${additionalCache.name} cache was not saved for the key: ${primaryKey}`);
return;
Expand Down
14 changes: 13 additions & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,20 @@ async function saveAdditionalCache(
);
return;
}

const globber = await glob.create(additionalCache.path.join('\n'), {
implicitDescendants: false
});
const cachePaths = await globber.glob();
if (cachePaths.length === 0) {
core.debug(
`${additionalCache.name} cache paths do not exist, not saving cache.`
);
return;
}

try {
const cacheId = await cache.saveCache(additionalCache.path, primaryKey);
const cacheId = await cache.saveCache(cachePaths, primaryKey);
if (cacheId === -1) {
core.debug(
`${additionalCache.name} cache was not saved for the key: ${primaryKey}`
Expand Down
Loading