From a336faa4976eb63d68381c8e5f24bae688fd5291 Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Mon, 21 Apr 2025 12:01:54 -0700 Subject: [PATCH] databaseInitCluster: use overlayDatabaseMode from config This commit changes databaseInitCluster() to use overlayDatabaseMode from AugmentationProperties instead of the overlayDatabaseMode parameter. There is no behavior change because both overlayDatabaseMode values are computed the same way. The commit then cleans up the overlayDatabaseMode parameter and the code paths that feed into it. --- src/codeql.test.ts | 5 ----- src/codeql.ts | 4 ++-- src/config-utils.ts | 1 + src/init-action.ts | 15 ++++---------- src/init.ts | 49 --------------------------------------------- 5 files changed, 7 insertions(+), 67 deletions(-) diff --git a/src/codeql.test.ts b/src/codeql.test.ts index 24d5fe49b..053c99a16 100644 --- a/src/codeql.test.ts +++ b/src/codeql.test.ts @@ -24,7 +24,6 @@ import { DocUrl } from "./doc-url"; import { FeatureEnablement } from "./feature-flags"; import { Language } from "./languages"; import { getRunnerLogger } from "./logging"; -import { OverlayDatabaseMode } from "./overlay-database-utils"; import { ToolsSource } from "./setup-codeql"; import { setupTests, @@ -515,7 +514,6 @@ const injectedConfigMacro = test.macro({ "", undefined, undefined, - OverlayDatabaseMode.None, getRunnerLogger(true), ); @@ -726,7 +724,6 @@ test("passes a code scanning config AND qlconfig to the CLI", async (t: Executio "", undefined, "/path/to/qlconfig.yml", - OverlayDatabaseMode.None, getRunnerLogger(true), ); @@ -756,7 +753,6 @@ test("does not pass a qlconfig to the CLI when it is undefined", async (t: Execu "", undefined, undefined, // undefined qlconfigFile - OverlayDatabaseMode.None, getRunnerLogger(true), ); @@ -1010,7 +1006,6 @@ test("Avoids duplicating --overwrite flag if specified in CODEQL_ACTION_EXTRA_OP "sourceRoot", undefined, undefined, - OverlayDatabaseMode.None, getRunnerLogger(false), ); diff --git a/src/codeql.ts b/src/codeql.ts index 07b763b59..0cc917c22 100644 --- a/src/codeql.ts +++ b/src/codeql.ts @@ -87,7 +87,6 @@ export interface CodeQL { sourceRoot: string, processName: string | undefined, qlconfigFile: string | undefined, - overlayDatabaseMode: OverlayDatabaseMode, logger: Logger, ): Promise; /** @@ -564,7 +563,6 @@ export async function getCodeQLForCmd( sourceRoot: string, processName: string | undefined, qlconfigFile: string | undefined, - overlayDatabaseMode: OverlayDatabaseMode, logger: Logger, ) { const extraArgs = config.languages.map( @@ -602,6 +600,8 @@ export async function getCodeQLForCmd( ? "--force-overwrite" : "--overwrite"; + const overlayDatabaseMode = + config.augmentationProperties.overlayDatabaseMode; if (overlayDatabaseMode === OverlayDatabaseMode.Overlay) { const overlayChangesFile = await writeOverlayChangesFile( config, diff --git a/src/config-utils.ts b/src/config-utils.ts index 9aea68904..7d05ec357 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -695,6 +695,7 @@ export async function calculateAugmentation( buildMode, logger, ); + logger.info(`Using overlay database mode: ${overlayDatabaseMode}`); const qualityQueriesInput = parseQueriesFromInput( rawQualityQueriesInput, diff --git a/src/init-action.ts b/src/init-action.ts index 74327d4f6..a3837cbd2 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -36,7 +36,6 @@ import { Feature, featureConfig, Features } from "./feature-flags"; import { checkInstallPython311, cleanupDatabaseClusterDirectory, - getOverlayDatabaseMode, initCodeQL, initConfig, runInit, @@ -399,15 +398,10 @@ async function run() { } try { - const overlayDatabaseMode = await getOverlayDatabaseMode( - (await codeql.getVersion()).version, - config, - sourceRoot, - logger, - ); - logger.info(`Using overlay database mode: ${overlayDatabaseMode}`); - - if (overlayDatabaseMode !== OverlayDatabaseMode.Overlay) { + if ( + config.augmentationProperties.overlayDatabaseMode !== + OverlayDatabaseMode.Overlay + ) { cleanupDatabaseClusterDirectory(config, logger); } @@ -679,7 +673,6 @@ async function run() { "Runner.Worker.exe", getOptionalInput("registries"), apiDetails, - overlayDatabaseMode, logger, ); if (tracerConfig !== undefined) { diff --git a/src/init.ts b/src/init.ts index bad26bb78..b49aac25f 100644 --- a/src/init.ts +++ b/src/init.ts @@ -3,20 +3,14 @@ import * as path from "path"; import * as toolrunner from "@actions/exec/lib/toolrunner"; import * as io from "@actions/io"; -import * as semver from "semver"; import { getOptionalInput, isSelfHostedRunner } from "./actions-util"; import { GitHubApiCombinedDetails, GitHubApiDetails } from "./api-client"; import { CodeQL, setupCodeQL } from "./codeql"; import * as configUtils from "./config-utils"; import { CodeQLDefaultVersionInfo, FeatureEnablement } from "./feature-flags"; -import { getGitRoot } from "./git-utils"; import { Language } from "./languages"; import { Logger, withGroupAsync } from "./logging"; -import { - CODEQL_OVERLAY_MINIMUM_VERSION, - OverlayDatabaseMode, -} from "./overlay-database-utils"; import { ToolsSource } from "./setup-codeql"; import { ZstdAvailability } from "./tar"; import { ToolsDownloadStatusReport } from "./tools-download"; @@ -74,47 +68,6 @@ export async function initConfig( }); } -export async function getOverlayDatabaseMode( - codeqlVersion: string, - config: configUtils.Config, - sourceRoot: string, - logger: Logger, -): Promise { - const overlayDatabaseMode = process.env.CODEQL_OVERLAY_DATABASE_MODE; - - if ( - overlayDatabaseMode === OverlayDatabaseMode.Overlay || - overlayDatabaseMode === OverlayDatabaseMode.OverlayBase - ) { - if (config.buildMode !== util.BuildMode.None) { - logger.warning( - `Cannot build an ${overlayDatabaseMode} database because ` + - `build-mode is set to "${config.buildMode}" instead of "none". ` + - "Falling back to creating a normal full database instead.", - ); - return OverlayDatabaseMode.None; - } - if (semver.lt(codeqlVersion, CODEQL_OVERLAY_MINIMUM_VERSION)) { - logger.warning( - `Cannot build an ${overlayDatabaseMode} database because ` + - `the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` + - "Falling back to creating a normal full database instead.", - ); - return OverlayDatabaseMode.None; - } - if ((await getGitRoot(sourceRoot)) === undefined) { - logger.warning( - `Cannot build an ${overlayDatabaseMode} database because ` + - `the source root "${sourceRoot}" is not inside a git repository. ` + - "Falling back to creating a normal full database instead.", - ); - return OverlayDatabaseMode.None; - } - return overlayDatabaseMode as OverlayDatabaseMode; - } - return OverlayDatabaseMode.None; -} - export async function runInit( codeql: CodeQL, config: configUtils.Config, @@ -122,7 +75,6 @@ export async function runInit( processName: string | undefined, registriesInput: string | undefined, apiDetails: GitHubApiCombinedDetails, - overlayDatabaseMode: OverlayDatabaseMode, logger: Logger, ): Promise { fs.mkdirSync(config.dbLocation, { recursive: true }); @@ -146,7 +98,6 @@ export async function runInit( sourceRoot, processName, qlconfigFile, - overlayDatabaseMode, logger, ), );