Fail if configuration-cache is enabled without dependencies cache

Fixes #61
This commit is contained in:
Daz DeBoer 2021-08-07 15:33:18 -07:00
parent 01bfa29846
commit 88af98fab4
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 14 additions and 2 deletions

View file

@ -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. 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. 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 ### Configuring the dependencies and configuration caches
Both the dependencies and configuration caches use the same default configuration: Both the dependencies and configuration caches use the same default configuration:

View file

@ -6,7 +6,11 @@ import * as cache from '@actions/cache'
import * as crypto from './crypto-utils' 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_PATH = 'CONFIGURATION_CACHE_PATH'
const CONFIGURATION_CACHE_KEY = 'CONFIGURATION_CACHE_KEY' const CONFIGURATION_CACHE_KEY = 'CONFIGURATION_CACHE_KEY'
@ -17,6 +21,12 @@ export async function restoreCachedConfiguration(
): Promise<void> { ): Promise<void> {
if (isConfigurationCacheDisabled()) return 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') const cachePath = path.resolve(rootDir, '.gradle/configuration-cache')
if (fs.existsSync(cachePath)) return if (fs.existsSync(cachePath)) return
core.saveState(CONFIGURATION_CACHE_PATH, cachePath) core.saveState(CONFIGURATION_CACHE_PATH, cachePath)

View file

@ -102,7 +102,7 @@ export function tryDeleteFiles(filePaths: string[]): boolean {
return !failure return !failure
} }
function isDependenciesCacheDisabled(): boolean { export function isDependenciesCacheDisabled(): boolean {
return !core.getBooleanInput('dependencies-cache-enabled') return !core.getBooleanInput('dependencies-cache-enabled')
} }