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
63 changes: 54 additions & 9 deletions __tests__/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,20 @@ describe('dependency cache', () => {
ReturnType<typeof cache.saveCache>,
Parameters<typeof cache.saveCache>
>;
let spyGlobCreate: jest.SpyInstance<
ReturnType<typeof glob.create>,
Parameters<typeof glob.create>
>;

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

Expand Down Expand Up @@ -469,17 +476,24 @@ 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')
);
createStateForWrapperRestore('maven-wrapper', false);
spyCacheSave.mockImplementation((paths: string[], key: string) => {
if (paths.includes(join(os.homedir(), '.m2', 'wrapper', 'dists'))) {
return Promise.reject(
new cache.ValidationError('Path Validation Error')
);
}
return Promise.resolve(0);
});
spyGlobCreate.mockResolvedValue(createGlobber([]));

await expect(save('maven')).resolves.not.toThrow();
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();
});
});
describe('for gradle', () => {
Expand Down Expand Up @@ -553,6 +567,23 @@ 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'));
createStateForWrapperRestore('gradle-wrapper', false);
spyGlobCreate.mockResolvedValue(createGlobber([]));

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 Expand Up @@ -663,6 +694,20 @@ function createDirectory(path: string) {
fs.mkdirSync(path);
}

function createGlobber(
paths: string[]
): Awaited<ReturnType<typeof glob.create>> {
return {
getSearchPaths: () => [],
glob: () => Promise.resolve(paths),
globGenerator: async function* () {
for (const path of paths) {
yield path;
}
}
};
}

function projectRoot(workspace: string): string {
if (os.platform() === 'darwin') {
return `/private${workspace}`;
Expand Down
8 changes: 8 additions & 0 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50898,6 +50898,14 @@ function saveAdditionalCache(packageManager, additionalCache) {
core.info(`Cache hit occurred on the ${additionalCache.name} primary key ${primaryKey}, not saving cache.`);
return;
}
const globber = yield glob.create(additionalCache.path.join('\n'), {
implicitDescendants: false
});
const cachePaths = yield globber.glob();
if (cachePaths.length === 0) {
core.debug(`${additionalCache.name} cache paths do not exist, not saving cache.`);
return;
}
try {
const cacheId = yield cache.saveCache(additionalCache.path, primaryKey);
if (cacheId === -1) {
Expand Down
8 changes: 8 additions & 0 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76733,6 +76733,14 @@ function saveAdditionalCache(packageManager, additionalCache) {
core.info(`Cache hit occurred on the ${additionalCache.name} primary key ${primaryKey}, not saving cache.`);
return;
}
const globber = yield glob.create(additionalCache.path.join('\n'), {
implicitDescendants: false
});
const cachePaths = yield globber.glob();
if (cachePaths.length === 0) {
core.debug(`${additionalCache.name} cache paths do not exist, not saving cache.`);
return;
}
try {
const cacheId = yield cache.saveCache(additionalCache.path, primaryKey);
if (cacheId === -1) {
Expand Down
12 changes: 12 additions & 0 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ 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);
if (cacheId === -1) {
Expand Down
Loading