Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc9841c

Browse files
committed
Add environment variable for custom dependency cache prefix
1 parent 4663b2b commit dc9841c

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

lib/dependency-caching.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dependency-caching.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/environment.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/environment.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dependency-caching.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Config } from "./config-utils";
99
import { Language } from "./languages";
1010
import { Logger } from "./logging";
1111
import { getRequiredEnvParam } from "./util";
12+
import { EnvVar } from "./environment";
1213

1314
/**
1415
* Caching configuration for a particular language.
@@ -199,5 +200,12 @@ async function cacheKey(
199200
*/
200201
async function cachePrefix(language: Language): Promise<string> {
201202
const runnerOs = getRequiredEnvParam("RUNNER_OS");
202-
return `${CODEQL_DEPENDENCY_CACHE_PREFIX}-${CODEQL_DEPENDENCY_CACHE_VERSION}-${runnerOs}-${language}-`;
203+
const customPrefix = process.env[EnvVar.DEPENDENCY_CACHING_PREFIX];
204+
let prefix = CODEQL_DEPENDENCY_CACHE_PREFIX;
205+
206+
if (customPrefix !== undefined && customPrefix.length > 0) {
207+
prefix = `${prefix}-${customPrefix}`;
208+
}
209+
210+
return `${prefix}-${CODEQL_DEPENDENCY_CACHE_VERSION}-${runnerOs}-${language}-`;
203211
}

src/environment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,10 @@ export enum EnvVar {
105105
* change the inputs to the Action.
106106
*/
107107
DEPENDENCY_CACHING = "CODEQL_ACTION_DEPENDENCY_CACHING",
108+
109+
/**
110+
* An optional string to add into the cache key used by dependency caching.
111+
* Useful for testing purposes where multiple caches may be stored in the same repository.
112+
*/
113+
DEPENDENCY_CACHING_PREFIX = "CODEQL_ACTION_DEPENDENCY_CACHE_PREFIX",
108114
}

0 commit comments

Comments
 (0)