diff --git a/lib/init-action.js b/lib/init-action.js index a5fcd7687..bf8138277 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -87616,6 +87616,15 @@ async function initActionState({ repositoryProperties, languages ); + if (analysisKinds.length === 1 && analysisKinds.includes("code-quality" /* CodeQuality */) && augmentationProperties.repoPropertyQueries.input) { + logger.info( + `Ignoring queries configured in the repository properties, because query customisations are not supported for Code Quality analyses.` + ); + augmentationProperties.repoPropertyQueries = { + combines: false, + input: void 0 + }; + } const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime( trapCachingEnabled, codeql, diff --git a/src/config-utils.test.ts b/src/config-utils.test.ts index 1df142f11..566a719ca 100644 --- a/src/config-utils.test.ts +++ b/src/config-utils.test.ts @@ -29,6 +29,7 @@ import { getRecordingLogger, LoggedMessage, mockCodeQLVersion, + createTestConfig, } from "./testing-utils"; import { GitHubVariant, @@ -230,6 +231,63 @@ test("load code quality config", async (t) => { }); }); +test("initActionState doesn't throw if there are queries configured in the repository properties", async (t) => { + return await withTmpDir(async (tempDir) => { + const logger = getRunnerLogger(true); + const languages = "javascript"; + + const codeql = createStubCodeQL({ + async betterResolveLanguages() { + return { + extractors: { + javascript: [{ extractor_root: "" }], + }, + }; + }, + }); + + // This should be ignored and no error should be thrown. + const repositoryProperties = { + "github-codeql-extra-queries": "+foo", + }; + + // Expected configuration for a CQ-only analysis. + const computedConfig: configUtils.UserConfig = { + "disable-default-queries": true, + queries: [{ uses: "code-quality" }], + "query-filters": [], + }; + + const expectedConfig = createTestConfig({ + analysisKinds: [AnalysisKind.CodeQuality], + languages: [KnownLanguage.javascript], + codeQLCmd: codeql.getPath(), + computedConfig, + dbLocation: path.resolve(tempDir, "codeql_databases"), + debugArtifactName: "", + debugDatabaseName: "", + tempDir, + repositoryProperties, + }); + + await t.notThrowsAsync(async () => { + const config = await configUtils.initConfig( + createTestInitConfigInputs({ + analysisKindsInput: "code-quality", + languagesInput: languages, + repository: { owner: "github", repo: "example" }, + tempDir, + codeql, + repositoryProperties, + logger, + }), + ); + + t.deepEqual(config, expectedConfig); + }); + }); +}); + test("loading a saved config produces the same config", async (t) => { return await withTmpDir(async (tempDir) => { const logger = getRunnerLogger(true); diff --git a/src/config-utils.ts b/src/config-utils.ts index e6e99be3b..fe4b392ab 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -463,6 +463,24 @@ export async function initActionState( languages, ); + // If `code-quality` is the only enabled analysis kind, we don't support query customisation. + // It would be a problem if queries that are configured in repository properties cause `code-quality`-only + // analyses to break. We therefore ignore query customisations that are configured in repository properties + // if `code-quality` is the only enabled analysis kind. + if ( + analysisKinds.length === 1 && + analysisKinds.includes(AnalysisKind.CodeQuality) && + augmentationProperties.repoPropertyQueries.input + ) { + logger.info( + `Ignoring queries configured in the repository properties, because query customisations are not supported for Code Quality analyses.`, + ); + augmentationProperties.repoPropertyQueries = { + combines: false, + input: undefined, + }; + } + const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime( trapCachingEnabled, codeql,