Add environment variable for custom dependency cache prefix

This commit is contained in:
Michael B. Gale 2024-10-07 10:59:35 +01:00
parent 1338dbce25
commit 8f657e857d
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
6 changed files with 29 additions and 4 deletions

View file

@ -9,6 +9,7 @@ import { Config } from "./config-utils";
import { Language } from "./languages";
import { Logger } from "./logging";
import { getRequiredEnvParam } from "./util";
import { EnvVar } from "./environment";
/**
* Caching configuration for a particular language.
@ -197,5 +198,12 @@ async function cacheKey(
*/
async function cachePrefix(language: Language): Promise<string> {
const runnerOs = getRequiredEnvParam("RUNNER_OS");
return `${CODEQL_DEPENDENCY_CACHE_PREFIX}-${CODEQL_DEPENDENCY_CACHE_VERSION}-${runnerOs}-${language}-`;
const customPrefix = process.env[EnvVar.DEPENDENCY_CACHING_PREFIX];
let prefix = CODEQL_DEPENDENCY_CACHE_PREFIX;
if (customPrefix !== undefined && customPrefix.length > 0) {
prefix = `${prefix}-${customPrefix}`;
}
return `${prefix}-${CODEQL_DEPENDENCY_CACHE_VERSION}-${runnerOs}-${language}-`;
}

View file

@ -105,4 +105,10 @@ export enum EnvVar {
* change the inputs to the Action.
*/
DEPENDENCY_CACHING = "CODEQL_ACTION_DEPENDENCY_CACHING",
/**
* An optional string to add into the cache key used by dependency caching.
* Useful for testing purposes where multiple caches may be stored in the same repository.
*/
DEPENDENCY_CACHING_PREFIX = "CODEQL_ACTION_DEPENDENCY_CACHE_PREFIX",
}