Skip to content

Commit ec868c0

Browse files
brunoborgesCopilot
andcommitted
Address cache.ts review feedback
- saveAdditionalCache: handle @actions/cache ValidationError (thrown when the cache paths do not resolve, e.g. the wrapper distribution was never downloaded) by skipping instead of failing the post step. Add a test. - Point the Gradle wrapper cache comment at issue #269 (Gradle wrapper cache churn) instead of the Maven-specific #1095. Co-authored-by: Copilot App <[email protected]>
1 parent 90f4585 commit ec868c0

4 files changed

Lines changed: 54 additions & 3 deletions

File tree

‎__tests__/cache.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,33 @@ describe('dependency cache', () => {
570570
expect.any(String)
571571
);
572572
});
573+
it('does not fail the post step when the wrapper distribution path is missing', async () => {
574+
createFile(join(workspace, 'pom.xml'));
575+
(core.getState as jest.Mock<any>).mockImplementation((name: any) => {
576+
switch (name) {
577+
case 'cache-primary-key':
578+
return 'setup-java-cache-primary-key';
579+
case 'cache-matched-key':
580+
return 'setup-java-cache-matched-key';
581+
case 'cache-primary-key-maven-wrapper':
582+
return 'setup-java-maven-wrapper-key';
583+
default:
584+
return '';
585+
}
586+
});
587+
spyCacheSave.mockImplementation((paths: string[]) =>
588+
paths.includes(join(os.homedir(), '.m2', 'wrapper', 'dists'))
589+
? Promise.reject(
590+
new cache.ValidationError(
591+
'Path Validation Error: Path(s) specified in the action for caching do(es) not exist'
592+
)
593+
)
594+
: Promise.resolve(0)
595+
);
596+
597+
await expect(save('maven')).resolves.toBeUndefined();
598+
expect(spyWarning).not.toHaveBeenCalled();
599+
});
573600
});
574601
describe('for gradle', () => {
575602
it('uploads cache even if no build.gradle found', async () => {

‎dist/cleanup/index.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99700,7 +99700,7 @@ const supportedPackageManager = [
9970099700
// The Gradle wrapper distribution only depends on the wrapper properties,
9970199701
// which change very rarely, so it is cached separately from the Gradle
9970299702
// caches. This keeps it available across the frequent *.gradle* changes
99703-
// that rotate the main cache key. See issue #1095.
99703+
// that rotate the main cache key. See issue #269.
9970499704
additionalCaches: [
9970599705
{
9970699706
name: 'gradle-wrapper',
@@ -99900,6 +99900,13 @@ async function saveAdditionalCache(packageManager, additionalCache) {
9990099900
}
9990199901
catch (error) {
9990299902
const err = error;
99903+
if (err.name === ValidationError.name) {
99904+
// The cache paths did not resolve, e.g. the wrapper distribution was
99905+
// never downloaded because a system build tool was used or the download
99906+
// failed. Optional wrapper caches must not fail the post step, so skip.
99907+
core_debug(`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`);
99908+
return;
99909+
}
9990399910
if (err.name === ReserveCacheError.name) {
9990499911
info(err.message);
9990599912
}

‎dist/setup/index.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130922,7 +130922,7 @@ const supportedPackageManager = [
130922130922
// The Gradle wrapper distribution only depends on the wrapper properties,
130923130923
// which change very rarely, so it is cached separately from the Gradle
130924130924
// caches. This keeps it available across the frequent *.gradle* changes
130925-
// that rotate the main cache key. See issue #1095.
130925+
// that rotate the main cache key. See issue #269.
130926130926
additionalCaches: [
130927130927
{
130928130928
name: 'gradle-wrapper',
@@ -131122,6 +131122,13 @@ async function saveAdditionalCache(packageManager, additionalCache) {
131122131122
}
131123131123
catch (error) {
131124131124
const err = error;
131125+
if (err.name === cache.ValidationError.name) {
131126+
// The cache paths did not resolve, e.g. the wrapper distribution was
131127+
// never downloaded because a system build tool was used or the download
131128+
// failed. Optional wrapper caches must not fail the post step, so skip.
131129+
core.debug(`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`);
131130+
return;
131131+
}
131125131132
if (err.name === cache.ReserveCacheError.name) {
131126131133
core.info(err.message);
131127131134
}

‎src/cache.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const supportedPackageManager: PackageManager[] = [
8585
// The Gradle wrapper distribution only depends on the wrapper properties,
8686
// which change very rarely, so it is cached separately from the Gradle
8787
// caches. This keeps it available across the frequent *.gradle* changes
88-
// that rotate the main cache key. See issue #1095.
88+
// that rotate the main cache key. See issue #269.
8989
additionalCaches: [
9090
{
9191
name: 'gradle-wrapper',
@@ -333,6 +333,16 @@ async function saveAdditionalCache(
333333
} catch (error) {
334334
const err = error as Error;
335335

336+
if (err.name === cache.ValidationError.name) {
337+
// The cache paths did not resolve, e.g. the wrapper distribution was
338+
// never downloaded because a system build tool was used or the download
339+
// failed. Optional wrapper caches must not fail the post step, so skip.
340+
core.debug(
341+
`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`
342+
);
343+
return;
344+
}
345+
336346
if (err.name === cache.ReserveCacheError.name) {
337347
core.info(err.message);
338348
} else {

0 commit comments

Comments
 (0)