mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-07 16:56:12 +02:00
Treat configuration-cache as an extracted entry
Instead of using a fallback strategy to locate a configuration-cache entry based on the current job and git SHA, these entries are now keyed based on their file content with the keys persisted in the primary Gradle User Home entry. This removes the chance of having a configuration-cache entry restored that is incompatible with the restored Gradle User Home state, and makes the logic easier to understand. This change involved a fairly major refactor, with the CacheEntryExtractor being split out from the primary cache implementation, and adding a separate extractor implementation for configuration-cache.
This commit is contained in:
parent
12fc52a49a
commit
76ea8a76b2
9 changed files with 661 additions and 586 deletions
|
@ -46,6 +46,36 @@ export function hashStrings(values: string[]): string {
|
|||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
export async function restoreCache(
|
||||
cachePath: string[],
|
||||
cacheKey: string,
|
||||
cacheRestoreKeys: string[] = []
|
||||
): Promise<cache.CacheEntry | undefined> {
|
||||
try {
|
||||
return await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys)
|
||||
} catch (error) {
|
||||
handleCacheFailure(error, `Failed to restore ${cacheKey}`)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveCache(cachePath: string[], cacheKey: string): Promise<cache.CacheEntry | undefined> {
|
||||
try {
|
||||
return await cache.saveCache(cachePath, cacheKey)
|
||||
} catch (error) {
|
||||
handleCacheFailure(error, `Failed to save cache entry ${cacheKey}`)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
export function cacheDebug(message: string): void {
|
||||
if (isCacheDebuggingEnabled()) {
|
||||
core.info(message)
|
||||
} else {
|
||||
core.debug(message)
|
||||
}
|
||||
}
|
||||
|
||||
export function handleCacheFailure(error: unknown, message: string): void {
|
||||
if (error instanceof cache.ValidationError) {
|
||||
// Fail on cache validation errors
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue