mirror of
https://github.com/github/codeql-action.git
synced 2026-10-29 17:17:15 +00:00
Rename CacheEntry to CommandCacheEntry for consistency
This commit is contained in:
12
src/cache.ts
12
src/cache.ts
@@ -21,7 +21,7 @@ export type CommandCacheKey =
|
||||
(typeof CommandCacheKey)[keyof typeof CommandCacheKey];
|
||||
|
||||
/** A single cached command output together with the CLI path it came from. */
|
||||
interface CacheEntry {
|
||||
interface CommandCacheEntry {
|
||||
/**
|
||||
* The path to the CodeQL CLI that produced `output`. Persisted so that a
|
||||
* different step using a different CodeQL bundle doesn't pick up a stale
|
||||
@@ -36,7 +36,7 @@ interface CacheEntry {
|
||||
* whenever a value is read from the file (tier 2) or computed via the CLI
|
||||
* (tier 3).
|
||||
*/
|
||||
const inMemoryCache = new Map<CommandCacheKey, CacheEntry>();
|
||||
const inMemoryCache = new Map<CommandCacheKey, CommandCacheEntry>();
|
||||
|
||||
function getCommandCacheFilePath(): string {
|
||||
return path.join(getTemporaryDirectory(), COMMAND_CACHE_FILENAME);
|
||||
@@ -46,7 +46,7 @@ function getCommandCacheFilePath(): string {
|
||||
* Reads and parses the temporary cache file. Best-effort: a missing, malformed,
|
||||
* or otherwise unreadable file is treated as an empty cache.
|
||||
*/
|
||||
function readCommandCacheFile(): Record<string, CacheEntry> {
|
||||
function readCommandCacheFile(): Record<string, CommandCacheEntry> {
|
||||
let contents: string;
|
||||
try {
|
||||
contents = fs.readFileSync(getCommandCacheFilePath(), "utf8");
|
||||
@@ -68,7 +68,7 @@ function readCommandCacheFile(): Record<string, CacheEntry> {
|
||||
* Persists the cache to the temporary file. Best-effort: a failure to write
|
||||
* just means a later step re-runs the CLI.
|
||||
*/
|
||||
function writeCommandCacheFile(data: Record<string, CacheEntry>): void {
|
||||
function writeCommandCacheFile(data: Record<string, CommandCacheEntry>): void {
|
||||
try {
|
||||
fs.writeFileSync(getCommandCacheFilePath(), JSON.stringify(data));
|
||||
} catch {
|
||||
@@ -94,7 +94,7 @@ export function cacheCommandOutput(
|
||||
`cacheCommandOutput() should be called only once per key, but was called more than once for '${key}'.`,
|
||||
);
|
||||
}
|
||||
const entry: CacheEntry = { cmd, output };
|
||||
const entry: CommandCacheEntry = { cmd, output };
|
||||
inMemoryCache.set(key, entry);
|
||||
|
||||
const data = readCommandCacheFile();
|
||||
@@ -127,7 +127,7 @@ export function getCachedCommandOutput<T>(
|
||||
// Tier 2: the temporary file persisted by an earlier step, if any.
|
||||
const entry = readCommandCacheFile()[key] as unknown;
|
||||
if (
|
||||
!json.isObject<CacheEntry>(entry) ||
|
||||
!json.isObject<CommandCacheEntry>(entry) ||
|
||||
!json.isString(entry.cmd) ||
|
||||
(cmd !== undefined && entry.cmd !== cmd) ||
|
||||
(validate !== undefined && !validate(entry.output))
|
||||
|
||||
Reference in New Issue
Block a user