From fae2927552189bbf3c36e81e257715cf69ee4ffc Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Tue, 20 Jul 2021 11:32:37 +0800 Subject: [PATCH] suggest users to run without daemon if fail to save Gradle cache on Windows --- dist/cleanup/index.js | 16 ++++++++++++++++ dist/setup/index.js | 16 ++++++++++++++++ src/cache.ts | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 613d2536..9c81d397 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -64623,12 +64623,28 @@ function save(id) { core.info(error.message); } else { + if (isProbablyGradleDaemonProblem(packageManager, error)) { + core.warning('Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for detail.'); + } throw error; } } }); } exports.save = save; +/** + * @param packageManager the specified package manager by user + * @param error the error thrown by the saveCache + * @returns true if the given error seems related to the {@link https://github.com/actions/cache/issues/454|running Gradle Daemon issue}. + * @see {@link https://github.com/actions/cache/issues/454#issuecomment-840493935|why --no-daemon is necessary} + */ +function isProbablyGradleDaemonProblem(packageManager, error) { + if (packageManager.id !== 'gradle' || process.env['RUNNER_OS'] !== 'Windows') { + return false; + } + const message = error.message || ''; + return message.startsWith('Tar failed with error: '); +} /***/ }), diff --git a/dist/setup/index.js b/dist/setup/index.js index d7e9e49b..be2109c7 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -19019,12 +19019,28 @@ function save(id) { core.info(error.message); } else { + if (isProbablyGradleDaemonProblem(packageManager, error)) { + core.warning('Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for detail.'); + } throw error; } } }); } exports.save = save; +/** + * @param packageManager the specified package manager by user + * @param error the error thrown by the saveCache + * @returns true if the given error seems related to the {@link https://github.com/actions/cache/issues/454|running Gradle Daemon issue}. + * @see {@link https://github.com/actions/cache/issues/454#issuecomment-840493935|why --no-daemon is necessary} + */ +function isProbablyGradleDaemonProblem(packageManager, error) { + if (packageManager.id !== 'gradle' || process.env['RUNNER_OS'] !== 'Windows') { + return false; + } + const message = error.message || ''; + return message.startsWith('Tar failed with error: '); +} /***/ }), diff --git a/src/cache.ts b/src/cache.ts index 3ac8d658..cc01dd56 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -110,7 +110,26 @@ export async function save(id: string) { if (error.name === cache.ReserveCacheError.name) { core.info(error.message); } else { + if (isProbablyGradleDaemonProblem(packageManager, error)) { + core.warning( + 'Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for detail.' + ); + } throw error; } } } + +/** + * @param packageManager the specified package manager by user + * @param error the error thrown by the saveCache + * @returns true if the given error seems related to the {@link https://github.com/actions/cache/issues/454|running Gradle Daemon issue}. + * @see {@link https://github.com/actions/cache/issues/454#issuecomment-840493935|why --no-daemon is necessary} + */ +function isProbablyGradleDaemonProblem(packageManager: PackageManager, error: Error) { + if (packageManager.id !== 'gradle' || process.env['RUNNER_OS'] !== 'Windows') { + return false; + } + const message = error.message || ''; + return message.startsWith('Tar failed with error: '); +}