diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index f9a91a9e..072b406c 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -570,6 +570,33 @@ describe('dependency cache', () => { expect.any(String) ); }); + it('does not fail the post step when the wrapper distribution path is missing', async () => { + createFile(join(workspace, 'pom.xml')); + (core.getState as jest.Mock).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-maven-wrapper': + return 'setup-java-maven-wrapper-key'; + default: + 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) + ); + + await expect(save('maven')).resolves.toBeUndefined(); + expect(spyWarning).not.toHaveBeenCalled(); + }); }); describe('for gradle', () => { it('uploads cache even if no build.gradle found', async () => { diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index e2e65877..e710603c 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -99700,7 +99700,7 @@ const supportedPackageManager = [ // The Gradle wrapper distribution only depends on the wrapper properties, // which change very rarely, so it is cached separately from the Gradle // caches. This keeps it available across the frequent *.gradle* changes - // that rotate the main cache key. See issue #1095. + // that rotate the main cache key. See issue #269. additionalCaches: [ { name: 'gradle-wrapper', @@ -99900,6 +99900,13 @@ async function saveAdditionalCache(packageManager, additionalCache) { } catch (error) { const err = error; + if (err.name === ValidationError.name) { + // The cache paths did not resolve, e.g. the wrapper distribution was + // never downloaded because a system build tool was used or the download + // failed. Optional wrapper caches must not fail the post step, so skip. + core_debug(`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`); + return; + } if (err.name === ReserveCacheError.name) { info(err.message); } diff --git a/dist/setup/index.js b/dist/setup/index.js index d0bd8b8b..4df595bc 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -130922,7 +130922,7 @@ const supportedPackageManager = [ // The Gradle wrapper distribution only depends on the wrapper properties, // which change very rarely, so it is cached separately from the Gradle // caches. This keeps it available across the frequent *.gradle* changes - // that rotate the main cache key. See issue #1095. + // that rotate the main cache key. See issue #269. additionalCaches: [ { name: 'gradle-wrapper', @@ -131122,6 +131122,13 @@ async function saveAdditionalCache(packageManager, additionalCache) { } catch (error) { const err = error; + if (err.name === cache.ValidationError.name) { + // The cache paths did not resolve, e.g. the wrapper distribution was + // never downloaded because a system build tool was used or the download + // failed. Optional wrapper caches must not fail the post step, so skip. + core.debug(`${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}`); + return; + } if (err.name === cache.ReserveCacheError.name) { core.info(err.message); } diff --git a/src/cache.ts b/src/cache.ts index 9783aaee..1ca7e762 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -85,7 +85,7 @@ const supportedPackageManager: PackageManager[] = [ // The Gradle wrapper distribution only depends on the wrapper properties, // which change very rarely, so it is cached separately from the Gradle // caches. This keeps it available across the frequent *.gradle* changes - // that rotate the main cache key. See issue #1095. + // that rotate the main cache key. See issue #269. additionalCaches: [ { name: 'gradle-wrapper', @@ -333,6 +333,16 @@ async function saveAdditionalCache( } catch (error) { const err = error as Error; + if (err.name === cache.ValidationError.name) { + // The cache paths did not resolve, e.g. the wrapper distribution was + // never downloaded because a system build tool was used or the download + // failed. Optional wrapper caches must not fail the post step, so skip. + core.debug( + `${additionalCache.name} cache paths do not exist, not saving cache: ${err.message}` + ); + return; + } + if (err.name === cache.ReserveCacheError.name) { core.info(err.message); } else {