From 71ab101d3833e084bf1cb655ed058dcf864eff0b Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Thu, 27 Mar 2025 14:06:40 -0700 Subject: [PATCH] Set default query filter for diff-informed analysis --- src/config-utils.test.ts | 6 ++++++ src/config-utils.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/config-utils.test.ts b/src/config-utils.test.ts index 642c833c2..fcd3a8bb9 100644 --- a/src/config-utils.test.ts +++ b/src/config-utils.test.ts @@ -811,9 +811,12 @@ const calculateAugmentationMacro = test.macro({ ) => { const actualAugmentationProperties = await configUtils.calculateAugmentation( + getCachedCodeQL(), + createFeatures([]), rawPacksInput, rawQueriesInput, languages, + mockLogger, ); t.deepEqual(actualAugmentationProperties, expectedAugmentationProperties); }, @@ -907,9 +910,12 @@ const calculateAugmentationErrorMacro = test.macro({ await t.throwsAsync( () => configUtils.calculateAugmentation( + getCachedCodeQL(), + createFeatures([]), rawPacksInput, rawQueriesInput, languages, + mockLogger, ), { message: expectedError }, ); diff --git a/src/config-utils.ts b/src/config-utils.ts index 008a027c0..e71826fb0 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -8,6 +8,7 @@ import * as semver from "semver"; import * as api from "./api-client"; import { CachingKind, getCachingKind } from "./caching-utils"; import { CodeQL } from "./codeql"; +import { shouldPerformDiffInformedAnalysis } from "./diff-informed-analysis-utils"; import { Feature, FeatureEnablement } from "./feature-flags"; import { Language, parseLanguage } from "./languages"; import { Logger } from "./logging"; @@ -469,9 +470,12 @@ export async function getDefaultConfig({ ); const augmentationProperties = await calculateAugmentation( + codeql, + features, packsInput, queriesInput, languages, + logger, ); const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime( @@ -575,9 +579,12 @@ async function loadConfig({ ); const augmentationProperties = await calculateAugmentation( + codeql, + features, packsInput, queriesInput, languages, + logger, ); const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime( @@ -612,11 +619,14 @@ async function loadConfig({ * and the CLI does not know about these inputs so we need to inject them into * the config file sent to the CLI. * + * @param codeql The CodeQL object. + * @param features The feature enablement object. * @param rawPacksInput The packs input from the action configuration. * @param rawQueriesInput The queries input from the action configuration. * @param languages The languages that the config file is for. If the packs input * is non-empty, then there must be exactly one language. Otherwise, an * error is thrown. + * @param logger The logger to use for logging. * * @returns The properties that need to be augmented in the config file. * @@ -625,9 +635,12 @@ async function loadConfig({ */ // exported for testing. export async function calculateAugmentation( + codeql: CodeQL, + features: FeatureEnablement, rawPacksInput: string | undefined, rawQueriesInput: string | undefined, languages: Language[], + logger: Logger, ): Promise { const packsInputCombines = shouldCombine(rawPacksInput); const packsInput = parsePacksFromInput( @@ -642,6 +655,9 @@ export async function calculateAugmentation( ); const defaultQueryFilters: QueryFilter[] = []; + if (await shouldPerformDiffInformedAnalysis(codeql, features, logger)) { + defaultQueryFilters.push({ exclude: { tags: "exclude-from-incremental" } }); + } return { packsInputCombines,