diff --git a/lib/entry-points.js b/lib/entry-points.js index dd77444e0..582aa5a3e 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -145250,22 +145250,28 @@ function isPersistedVersionInfo(x) { const candidate = x; return typeof candidate === "object" && candidate !== null && typeof candidate.cmd === "string" && isVersionInfo(candidate.version); } -function cacheCodeQlVersion(cmd, version) { +function getPathToCodeQLVersionCacheFile(env) { + return path.join(getTemporaryDirectory(env), "version.json"); +} +function cacheCodeQlVersion(cmd, version, env = getEnv()) { if (cachedCodeQlVersion !== void 0) { throw new Error("cacheCodeQlVersion() should be called only once"); } cachedCodeQlVersion = version; - core2.exportVariable( - "CODEQL_ACTION_CLI_VERSION_INFO" /* CODEQL_VERSION_INFO */, - JSON.stringify({ cmd, version }) + fs.writeFileSync( + getPathToCodeQLVersionCacheFile(env), + JSON.stringify({ cmd, version }), + "utf8" ); } -function getCachedCodeQlVersion(cmd) { +function getCachedCodeQlVersion(cmd, env = getEnv()) { if (cachedCodeQlVersion !== void 0) { return cachedCodeQlVersion; } - const serialized = process.env["CODEQL_ACTION_CLI_VERSION_INFO" /* CODEQL_VERSION_INFO */]; - if (!serialized) { + let serialized; + try { + serialized = fs.readFileSync(getPathToCodeQLVersionCacheFile(env), "utf8"); + } catch { return void 0; } let persisted; diff --git a/src/util.ts b/src/util.ts index 315e9ae4e..c92671850 100644 --- a/src/util.ts +++ b/src/util.ts @@ -689,10 +689,12 @@ export function getCachedCodeQlVersion( // Fall back to the value persisted by an earlier Actions step, if any. This is // best-effort: any malformed or mismatched value is ignored so that the caller // invokes `codeql version` instead. - const serialized = fs.readFileSync( - getPathToCodeQLVersionCacheFile(env), - "utf8", - ); + let serialized: string; + try { + serialized = fs.readFileSync(getPathToCodeQLVersionCacheFile(env), "utf8"); + } catch { + return undefined; + } let persisted: unknown; try { persisted = JSON.parse(serialized);