diff --git a/sources/src/caching/cache-key.ts b/sources/src/caching/cache-key.ts index 12d10e8..b9402b1 100644 --- a/sources/src/caching/cache-key.ts +++ b/sources/src/caching/cache-key.ts @@ -3,7 +3,7 @@ import * as github from '@actions/github' import {CacheConfig, getJobMatrix} from '../input-params' import {hashStrings} from './cache-utils' -const CACHE_PROTOCOL_VERSION = 'v9-' +const CACHE_PROTOCOL_VERSION = 'v1' const CACHE_KEY_PREFIX_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX' const CACHE_KEY_OS_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_ENVIRONMENT' @@ -29,8 +29,8 @@ export class CacheKey { /** * Generates a cache key specific to the current job execution. * The key is constructed from the following inputs (with some user overrides): + * - The cache key prefix: defaults to 'gradle-' but can be overridden by the user * - The cache protocol version - * - The name of the cache * - The runner operating system * - The name of the workflow and Job being executed * - The matrix values for the Job being executed (job context) @@ -43,7 +43,9 @@ export class CacheKey { * - Any previous key for this cache on the current OS */ export function generateCacheKey(cacheName: string, config: CacheConfig): CacheKey { - const cacheKeyBase = `${getCacheKeyPrefix()}${CACHE_PROTOCOL_VERSION}${cacheName}` + const prefix = process.env[CACHE_KEY_PREFIX_VAR] || '' + + const cacheKeyBase = `${prefix}${getCacheKeyBase(cacheName, CACHE_PROTOCOL_VERSION)}` // At the most general level, share caches for all executions on the same OS const cacheKeyForEnvironment = `${cacheKeyBase}|${getCacheKeyEnvironment()}` @@ -64,9 +66,9 @@ export function generateCacheKey(cacheName: string, config: CacheConfig): CacheK return new CacheKey(cacheKey, [cacheKeyForJobContext, cacheKeyForJob, cacheKeyForEnvironment]) } -export function getCacheKeyPrefix(): string { +export function getCacheKeyBase(cacheName: string, cacheProtocolVersion: string): string { // Prefix can be used to force change all cache keys (defaults to cache protocol version) - return process.env[CACHE_KEY_PREFIX_VAR] || '' + return `gradle-${cacheName}-${cacheProtocolVersion}` } function getCacheKeyEnvironment(): string { diff --git a/sources/src/caching/gradle-home-extry-extractor.ts b/sources/src/caching/gradle-home-extry-extractor.ts index 97edab5..e71cc32 100644 --- a/sources/src/caching/gradle-home-extry-extractor.ts +++ b/sources/src/caching/gradle-home-extry-extractor.ts @@ -10,9 +10,10 @@ import {cacheDebug, hashFileNames, isCacheDebuggingEnabled, restoreCache, saveCa import {BuildResult, loadBuildResults} from '../build-results' import {CacheConfig} from '../input-params' -import {getCacheKeyPrefix} from './cache-key' +import {getCacheKeyBase} from './cache-key' const SKIP_RESTORE_VAR = 'GRADLE_BUILD_ACTION_SKIP_RESTORE' +const CACHE_PROTOCOL_VERSION = 'v1' /** * Represents the result of attempting to load or store an extracted cache entry. @@ -244,22 +245,20 @@ abstract class AbstractEntryExtractor { } protected createCacheKeyFromFileNames(artifactType: string, files: string[]): string { - const cacheKeyPrefix = getCacheKeyPrefix() const relativeFiles = files.map(x => path.relative(this.gradleUserHome, x)) const key = hashFileNames(relativeFiles) cacheDebug(`Generating cache key for ${artifactType} from file names: ${relativeFiles}`) - return `${cacheKeyPrefix}${artifactType}-${key}` + return `${getCacheKeyBase(artifactType, CACHE_PROTOCOL_VERSION)}-${key}` } protected async createCacheKeyFromFileContents(artifactType: string, pattern: string): Promise { - const cacheKeyPrefix = getCacheKeyPrefix() const key = await glob.hashFiles(pattern) cacheDebug(`Generating cache key for ${artifactType} from files matching: ${pattern}`) - return `${cacheKeyPrefix}${artifactType}-${key}` + return `${getCacheKeyBase(artifactType, CACHE_PROTOCOL_VERSION)}-${key}` } // Run actions sequentially if debugging is enabled diff --git a/sources/src/caching/gradle-user-home-cache.ts b/sources/src/caching/gradle-user-home-cache.ts index d435347..180e19b 100644 --- a/sources/src/caching/gradle-user-home-cache.ts +++ b/sources/src/caching/gradle-user-home-cache.ts @@ -15,7 +15,7 @@ const RESTORED_CACHE_KEY_KEY = 'restored-cache-key' export const META_FILE_DIR = '.setup-gradle' export class GradleUserHomeCache { - private readonly cacheName = 'gradle' + private readonly cacheName = 'home' private readonly cacheDescription = 'Gradle User Home' private readonly userHome: string