From 88af98fab4f433aa8e4226a244ad26b08f5d0186 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sat, 7 Aug 2021 15:33:18 -0700 Subject: [PATCH] Fail if configuration-cache is enabled without dependencies cache Fixes #61 --- README.md | 2 ++ src/cache-configuration.ts | 12 +++++++++++- src/cache-dependencies.ts | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a7fe51..2a4b1f2 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,8 @@ The distributions cache is simple and can't be configured further. The dependencies and configuration cache will compute a cache key in a best effort manner. Keep reading to learn how to better control how they work. +Note that enabling configuration cache without thee dependencies cache is not permitted, since a hit in the configuration cache assumes that dependencies are already present in the local dependencies cache. + ### Configuring the dependencies and configuration caches Both the dependencies and configuration caches use the same default configuration: diff --git a/src/cache-configuration.ts b/src/cache-configuration.ts index dbaac52..05e1ff0 100644 --- a/src/cache-configuration.ts +++ b/src/cache-configuration.ts @@ -6,7 +6,11 @@ import * as cache from '@actions/cache' import * as crypto from './crypto-utils' -import {inputCacheKeyGlobs, tryDeleteFiles} from './cache-dependencies' +import { + inputCacheKeyGlobs, + tryDeleteFiles, + isDependenciesCacheDisabled +} from './cache-dependencies' const CONFIGURATION_CACHE_PATH = 'CONFIGURATION_CACHE_PATH' const CONFIGURATION_CACHE_KEY = 'CONFIGURATION_CACHE_KEY' @@ -17,6 +21,12 @@ export async function restoreCachedConfiguration( ): Promise { if (isConfigurationCacheDisabled()) return + if (isDependenciesCacheDisabled()) { + throw new Error( + `Must enable dependencies-cache when configuration-cache is enabled` + ) + } + const cachePath = path.resolve(rootDir, '.gradle/configuration-cache') if (fs.existsSync(cachePath)) return core.saveState(CONFIGURATION_CACHE_PATH, cachePath) diff --git a/src/cache-dependencies.ts b/src/cache-dependencies.ts index 04f3f64..69e2e3f 100644 --- a/src/cache-dependencies.ts +++ b/src/cache-dependencies.ts @@ -102,7 +102,7 @@ export function tryDeleteFiles(filePaths: string[]): boolean { return !failure } -function isDependenciesCacheDisabled(): boolean { +export function isDependenciesCacheDisabled(): boolean { return !core.getBooleanInput('dependencies-cache-enabled') }