From ba2492c5082881bc2f523cf3f93a879946731961 Mon Sep 17 00:00:00 2001 From: Henning Makholm Date: Mon, 11 Dec 2023 18:29:36 +0100 Subject: [PATCH] pass CODEQL_FEATURE_RAM_2023 to the CLI This prepares for an upcoming change in how the `--ram` argument to the CLI is interpreted. The CLI will interpret _either_ this feature flag _or_ an Action version of 2.22.10 or earlier as a sign that it would fall back to the current interpretation of `--ram`. Later in the future, the Action can start using a less conservative calculation of `--ram` (when it detect the CLI is sufficiently new CLIs) and signal that to the CLI by _not_ passing `CODEQL_FEATURE_RAM_2023` anyway. That way we can avoid wrong RAM settings caused by mismatched CLI and Actions versions. --- src/environment.ts | 7 +++++++ src/util.ts | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/environment.ts b/src/environment.ts index 5f9d7b055..dd31fb3ac 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -29,6 +29,13 @@ export enum EnvVar { /** Whether the CodeQL Action will upload SARIF, not the CLI. */ FEATURE_WILL_UPLOAD = "CODEQL_ACTION_FEATURE_WILL_UPLOAD", + /** + * This flag tells `codeql database analyze` that the `--ram` option it gets is still + * computed by the 2023 algorithm that leaves space for overshooting. + * The CLI will _implicitly_ treat this flag as set if the Action version is 2.22.10 or earlier. + */ + FEATURE_RAM_2023 = "CODEQL_ACTION_FEATURE_RAM_2023", + /** Whether the CodeQL Action has already warned the user about low disk space. */ HAS_WARNED_ABOUT_DISK_SPACE = "CODEQL_ACTION_HAS_WARNED_ABOUT_DISK_SPACE", diff --git a/src/util.ts b/src/util.ts index 31846d458..5a1302f68 100644 --- a/src/util.ts +++ b/src/util.ts @@ -161,6 +161,16 @@ export async function withTmpDir( * when the user doesn't explicitly specify a memory setting. * This is a heuristic to avoid OOM errors (exit code 137 / SIGKILL) * from committing too much of the available memory to CodeQL. + * + * BEWARE: Eventually, with new enough CLIs, this computation can be made + * less conservative, because the CLI can now itself reserve space for memory + * overhead of the JVM. When this happens, stop passing FEATURE_RAM_2023 + * feature variable. + * + * Also this rewrite cannot happen until the Action version is strictly above + * 2.22.10, because the CLI will interpret a version of 2.22.10 or lower as + * "old action that does not yet know to pass FEATURE_RAM_2023". + * * @returns number */ function getSystemReservedMemoryMegaBytes( @@ -539,6 +549,7 @@ export function initializeEnvironment(version: string) { core.exportVariable(String(EnvVar.FEATURE_SANDWICH), "false"); core.exportVariable(String(EnvVar.FEATURE_SARIF_COMBINE), "true"); core.exportVariable(String(EnvVar.FEATURE_WILL_UPLOAD), "true"); + core.exportVariable(String(EnvVar.FEATURE_RAM_2023), "true"); core.exportVariable(String(EnvVar.VERSION), version); }