From 65392d2e25cd027cef43d50d194f5487a61f622b Mon Sep 17 00:00:00 2001 From: Mario Campos Date: Thu, 13 Aug 2026 23:30:51 -0500 Subject: [PATCH] Delete CLI output-cache file during `init` --- lib/entry-points.js | 9 +++++++++ src/cli/output-cache.ts | 2 +- src/init-action.ts | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 56914e8848..a0432668d2 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -161696,6 +161696,15 @@ async function run3(actionState) { `The 'init' action should not be run in the same workflow as 'setup-codeql'.` ); } + try { + fs29.unlinkSync(getCommandCacheFilePath(actionState.env)); + } catch (e) { + if (e?.code !== "ENOENT") { + logger.warning( + `Cannot delete CLI-cache file ${getCommandCacheFilePath(actionState.env)}: ${e}` + ); + } + } toolsInput = await getToolsInput( actionStateWithFeatures, repositoryProperties diff --git a/src/cli/output-cache.ts b/src/cli/output-cache.ts index 8bf8c27abe..2c15f4580d 100644 --- a/src/cli/output-cache.ts +++ b/src/cli/output-cache.ts @@ -43,7 +43,7 @@ export function resetCachedCodeQlVersion(): void { * Returns the path to the temporary file that backs the * on-disk cache of CLI responses between workflow steps. */ -function getCommandCacheFilePath(env: Env): string { +export function getCommandCacheFilePath(env: Env): string { return path.join(getTemporaryDirectory(env), COMMAND_CACHE_FILENAME); } diff --git a/src/init-action.ts b/src/init-action.ts index 6b5ed392ef..10ac425c59 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -22,6 +22,7 @@ import { getTotalCacheSize, shouldRestoreCache, } from "./caching-utils"; +import { getCommandCacheFilePath } from "./cli/output-cache"; import { CodeQL } from "./codeql"; import { getConfigFileInput } from "./config/file"; import { ComputedInput, getToolsInput } from "./config/inputs"; @@ -296,6 +297,18 @@ async function run( ); } + // Delete the CLI output-cache file if it exists, to avoid + // accidentally reusing a stale version from a previous run. + try { + fs.unlinkSync(getCommandCacheFilePath(actionState.env)); + } catch (e: any) { + if (e?.code !== "ENOENT") { + logger.warning( + `Cannot delete CLI-cache file ${getCommandCacheFilePath(actionState.env)}: ${e}`, + ); + } + } + // Get the computed `tools` input. toolsInput = await getToolsInput( actionStateWithFeatures,