Use cache protocol version for bundle keys too

This commit is contained in:
Daz DeBoer 2021-10-16 09:44:35 -06:00
parent 263f84178a
commit aa2ed2e033
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
2 changed files with 13 additions and 4 deletions

View file

@ -5,7 +5,12 @@ import * as core from '@actions/core'
import * as glob from '@actions/glob' import * as glob from '@actions/glob'
import * as exec from '@actions/exec' import * as exec from '@actions/exec'
import {AbstractCache, hashFileNames, tryDelete} from './cache-utils' import {
AbstractCache,
getCacheKeyPrefix,
hashFileNames,
tryDelete
} from './cache-utils'
// Which paths under Gradle User Home should be cached // Which paths under Gradle User Home should be cached
const CACHE_PATH = ['caches', 'notifications'] const CACHE_PATH = ['caches', 'notifications']
@ -131,7 +136,7 @@ export class GradleUserHomeCache extends AbstractCache {
} }
protected createCacheKey(bundle: string, files: string[]): string { protected createCacheKey(bundle: string, files: string[]): string {
const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || '' const cacheKeyPrefix = getCacheKeyPrefix()
const relativeFiles = files.map(x => const relativeFiles = files.map(x =>
path.relative(this.gradleUserHome, x) path.relative(this.gradleUserHome, x)
) )

View file

@ -17,9 +17,13 @@ export function isCacheDebuggingEnabled(): boolean {
return process.env['CACHE_DEBUG_ENABLED'] ? true : false return process.env['CACHE_DEBUG_ENABLED'] ? true : false
} }
function generateCacheKey(cacheName: string): CacheKey { export function getCacheKeyPrefix(): string {
// Prefix can be used to force change all cache keys (defaults to cache protocol version) // Prefix can be used to force change all cache keys (defaults to cache protocol version)
const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || 'v2-' return process.env['CACHE_KEY_PREFIX'] || 'v2-'
}
function generateCacheKey(cacheName: string): CacheKey {
const cacheKeyPrefix = getCacheKeyPrefix()
// At the most general level, share caches for all executions on the same OS // At the most general level, share caches for all executions on the same OS
const runnerOs = process.env['RUNNER_OS'] || '' const runnerOs = process.env['RUNNER_OS'] || ''