Tidy-up caching code

- Extracted common code for Gradle User Home and Project .gradle caches
  into abstract supertype.
- Improve error handling by checking error types
This commit is contained in:
Daz DeBoer 2021-09-06 11:16:08 -06:00
parent c44ebadf6f
commit 6d1455a33e
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
6 changed files with 138 additions and 166 deletions

View file

@ -142,13 +142,14 @@ async function downloadAndCacheGradleDistribution(
try {
await cache.saveCache([downloadPath], cacheKey)
} catch (error) {
if (error.name === cache.ValidationError.name) {
// Fail on validation errors or non-errors (the latter to keep Typescript happy)
if (
error instanceof cache.ValidationError ||
!(error instanceof Error)
) {
throw error
} else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message)
} else {
core.info(`[warning] ${error.message}`)
}
core.warning(error.message)
}
}
return downloadPath