Skip to content

Commit 05310c6

Browse files
committed
Ignore repository property query config if CQ-only analysis
1 parent 889d482 commit 05310c6

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

lib/init-action.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
getRecordingLogger,
3030
LoggedMessage,
3131
mockCodeQLVersion,
32+
createTestConfig,
3233
} from "./testing-utils";
3334
import {
3435
GitHubVariant,
@@ -230,6 +231,63 @@ test("load code quality config", async (t) => {
230231
});
231232
});
232233

234+
test("initActionState doesn't throw if there are queries configured in the repository properties", async (t) => {
235+
return await withTmpDir(async (tempDir) => {
236+
const logger = getRunnerLogger(true);
237+
const languages = "javascript";
238+
239+
const codeql = createStubCodeQL({
240+
async betterResolveLanguages() {
241+
return {
242+
extractors: {
243+
javascript: [{ extractor_root: "" }],
244+
},
245+
};
246+
},
247+
});
248+
249+
// This should be ignored and no error should be thrown.
250+
const repositoryProperties = {
251+
"github-codeql-extra-queries": "+foo",
252+
};
253+
254+
// Expected configuration for a CQ-only analysis.
255+
const computedConfig: configUtils.UserConfig = {
256+
"disable-default-queries": true,
257+
queries: [{ uses: "code-quality" }],
258+
"query-filters": [],
259+
};
260+
261+
const expectedConfig = createTestConfig({
262+
analysisKinds: [AnalysisKind.CodeQuality],
263+
languages: [KnownLanguage.javascript],
264+
codeQLCmd: codeql.getPath(),
265+
computedConfig,
266+
dbLocation: path.resolve(tempDir, "codeql_databases"),
267+
debugArtifactName: "",
268+
debugDatabaseName: "",
269+
tempDir,
270+
repositoryProperties,
271+
});
272+
273+
await t.notThrowsAsync(async () => {
274+
const config = await configUtils.initConfig(
275+
createTestInitConfigInputs({
276+
analysisKindsInput: "code-quality",
277+
languagesInput: languages,
278+
repository: { owner: "github", repo: "example" },
279+
tempDir,
280+
codeql,
281+
repositoryProperties,
282+
logger,
283+
}),
284+
);
285+
286+
t.deepEqual(config, expectedConfig);
287+
});
288+
});
289+
});
290+
233291
test("loading a saved config produces the same config", async (t) => {
234292
return await withTmpDir(async (tempDir) => {
235293
const logger = getRunnerLogger(true);

src/config-utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,24 @@ export async function initActionState(
463463
languages,
464464
);
465465

466+
// If `code-quality` is the only enabled analysis kind, we don't support query customisation.
467+
// It would be a problem if queries that are configured in repository properties cause `code-quality`-only
468+
// analyses to break. We therefore ignore query customisations that are configured in repository properties
469+
// if `code-quality` is the only enabled analysis kind.
470+
if (
471+
analysisKinds.length === 1 &&
472+
analysisKinds.includes(AnalysisKind.CodeQuality) &&
473+
augmentationProperties.repoPropertyQueries.input
474+
) {
475+
logger.info(
476+
`Ignoring queries configured in the repository properties, because query customisations are not supported for Code Quality analyses.`,
477+
);
478+
augmentationProperties.repoPropertyQueries = {
479+
combines: false,
480+
input: undefined,
481+
};
482+
}
483+
466484
const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime(
467485
trapCachingEnabled,
468486
codeql,

0 commit comments

Comments
 (0)