From aa2ed2e033f58e6e511a9f4480874e15aa3b2cf6 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sat, 16 Oct 2021 09:44:35 -0600 Subject: [PATCH] Use cache protocol version for bundle keys too --- src/cache-gradle-user-home.ts | 9 +++++++-- src/cache-utils.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index f4605d1..6cdc8b3 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -5,7 +5,12 @@ import * as core from '@actions/core' import * as glob from '@actions/glob' 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 const CACHE_PATH = ['caches', 'notifications'] @@ -131,7 +136,7 @@ export class GradleUserHomeCache extends AbstractCache { } protected createCacheKey(bundle: string, files: string[]): string { - const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || '' + const cacheKeyPrefix = getCacheKeyPrefix() const relativeFiles = files.map(x => path.relative(this.gradleUserHome, x) ) diff --git a/src/cache-utils.ts b/src/cache-utils.ts index a94c3fa..fdf4b24 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -17,9 +17,13 @@ export function isCacheDebuggingEnabled(): boolean { 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) - 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 const runnerOs = process.env['RUNNER_OS'] || ''