Skip to content

Commit 47bcabd

Browse files
authored
Merge pull request #1116 from github/aeisenberg/multi-lang-packs
Allow scans with packs for languages not being scanned
2 parents 7c4d0e0 + b9deefb commit 47bcabd

File tree

8 files changed

+93
-37
lines changed

8 files changed

+93
-37
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [UNRELEASED]
44

5+
- CodeQL query packs listed in the `packs` configuration field will be skipped if their target language is not being analyzed in the current Actions job. Previously, this would throw an error. [#1116](https://github.com/github/codeql-action/pull/1116)
56
- The combination of python2 and poetry is no longer supported. See https://github.com/actions/setup-python/issues/374 for more details. [#1124](https://github.com/github/codeql-action/pull/1124)
67

78
## 2.1.14 - 22 Jun 2022

lib/config-utils.js

+15-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js

+15-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

+37-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getCachedCodeQL, setCodeQL } from "./codeql";
1010
import * as configUtils from "./config-utils";
1111
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
1212
import { Language } from "./languages";
13-
import { getRunnerLogger } from "./logging";
13+
import { getRunnerLogger, Logger } from "./logging";
1414
import { setupTests } from "./testing-utils";
1515
import * as util from "./util";
1616

@@ -1424,7 +1424,12 @@ const parsePacksMacro = test.macro({
14241424
expected: Partial<Record<Language, string[]>>
14251425
) =>
14261426
t.deepEqual(
1427-
configUtils.parsePacksFromConfig(packsByLanguage, languages, "/a/b"),
1427+
configUtils.parsePacksFromConfig(
1428+
packsByLanguage,
1429+
languages,
1430+
"/a/b",
1431+
mockLogger
1432+
),
14281433
expected
14291434
),
14301435

@@ -1446,7 +1451,8 @@ const parsePacksErrorMacro = test.macro({
14461451
configUtils.parsePacksFromConfig(
14471452
packsByLanguage as string[] | Record<string, string[]>,
14481453
languages,
1449-
"/a/b"
1454+
"/a/b",
1455+
{} as Logger
14501456
),
14511457
{
14521458
message: expected,
@@ -1499,6 +1505,19 @@ test(
14991505
}
15001506
);
15011507

1508+
test(
1509+
"two packs with unused language in config",
1510+
parsePacksMacro,
1511+
{
1512+
[Language.cpp]: ["a/b", "c/[email protected]"],
1513+
[Language.java]: ["d/e", "f/[email protected]"],
1514+
},
1515+
[Language.cpp, Language.csharp],
1516+
{
1517+
[Language.cpp]: ["a/b", "c/[email protected]"],
1518+
}
1519+
);
1520+
15021521
test(
15031522
"packs with other valid names",
15041523
parsePacksMacro,
@@ -1544,13 +1563,6 @@ test(
15441563
[Language.java, Language.python],
15451564
/The configuration file "\/a\/b" is invalid: property "packs" must split packages by language/
15461565
);
1547-
test(
1548-
"invalid language",
1549-
parsePacksErrorMacro,
1550-
{ [Language.java]: ["c/d"] },
1551-
[Language.cpp],
1552-
/The configuration file "\/a\/b" is invalid: property "packs" has "java", but it is not one of the languages to analyze/
1553-
);
15541566
test(
15551567
"not an array",
15561568
parsePacksErrorMacro,
@@ -1583,13 +1595,25 @@ function parseInputAndConfigMacro(
15831595
expected
15841596
) {
15851597
t.deepEqual(
1586-
configUtils.parsePacks(packsFromConfig, packsFromInput, languages, "/a/b"),
1598+
configUtils.parsePacks(
1599+
packsFromConfig,
1600+
packsFromInput,
1601+
languages,
1602+
"/a/b",
1603+
mockLogger
1604+
),
15871605
expected
15881606
);
15891607
}
15901608
parseInputAndConfigMacro.title = (providedTitle: string) =>
15911609
`Parse Packs input and config: ${providedTitle}`;
15921610

1611+
const mockLogger = {
1612+
info: (message: string) => {
1613+
console.log(message);
1614+
},
1615+
} as Logger;
1616+
15931617
function parseInputAndConfigErrorMacro(
15941618
t: ExecutionContext<unknown>,
15951619
packsFromConfig: string[] | Record<string, string[]>,
@@ -1603,7 +1627,8 @@ function parseInputAndConfigErrorMacro(
16031627
packsFromConfig,
16041628
packsFromInput,
16051629
languages,
1606-
"/a/b"
1630+
"/a/b",
1631+
mockLogger
16071632
);
16081633
},
16091634
{

src/config-utils.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,11 @@ export function getPathsInvalid(configFile: string): string {
629629
);
630630
}
631631

632-
export function getPacksRequireLanguage(
633-
lang: string,
634-
configFile: string
635-
): string {
632+
function getPacksRequireLanguage(lang: string, configFile: string): string {
636633
return getConfigFilePropertyError(
637634
configFile,
638635
PACKS_PROPERTY,
639-
`has "${lang}", but it is not one of the languages to analyze`
636+
`has "${lang}", but it is not a valid language.`
640637
);
641638
}
642639

@@ -1026,7 +1023,8 @@ async function loadConfig(
10261023
parsedYAML[PACKS_PROPERTY] ?? {},
10271024
packsInput,
10281025
languages,
1029-
configFile
1026+
configFile,
1027+
logger
10301028
);
10311029

10321030
// If queries were provided using `with` in the action configuration,
@@ -1146,7 +1144,8 @@ const PACK_IDENTIFIER_PATTERN = (function () {
11461144
export function parsePacksFromConfig(
11471145
packsByLanguage: string[] | Record<string, string[]>,
11481146
languages: Language[],
1149-
configFile: string
1147+
configFile: string,
1148+
logger: Logger
11501149
): Packs {
11511150
const packs = {};
11521151

@@ -1168,7 +1167,16 @@ export function parsePacksFromConfig(
11681167
throw new Error(getPacksInvalid(configFile));
11691168
}
11701169
if (!languages.includes(lang as Language)) {
1171-
throw new Error(getPacksRequireLanguage(lang, configFile));
1170+
// This particular language is not being analyzed in this run.
1171+
if (Language[lang as Language]) {
1172+
logger.info(
1173+
`Ignoring packs for ${lang} since this language is not being analyzed in this run.`
1174+
);
1175+
continue;
1176+
} else {
1177+
// This language is invalid, probably a misspelling
1178+
throw new Error(getPacksRequireLanguage(configFile, lang));
1179+
}
11721180
}
11731181
packs[lang] = [];
11741182
for (const packStr of packsArr) {
@@ -1296,13 +1304,15 @@ export function parsePacks(
12961304
rawPacksFromConfig: string[] | Record<string, string[]>,
12971305
rawPacksInput: string | undefined,
12981306
languages: Language[],
1299-
configFile: string
1307+
configFile: string,
1308+
logger: Logger
13001309
) {
13011310
const packsFromInput = parsePacksFromInput(rawPacksInput, languages);
13021311
const packsFomConfig = parsePacksFromConfig(
13031312
rawPacksFromConfig,
13041313
languages,
1305-
configFile
1314+
configFile,
1315+
logger
13061316
);
13071317

13081318
if (!packsFromInput) {

tests/multi-language-repo/.github/codeql/codeql-config-packaging.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ packs:
66
- dsp-testing/[email protected]
77
- dsp-testing/codeql-pack2
88
- dsp-testing/codeql-pack3:other-query.ql
9+
ruby:
10+
- dsp-testing/hucairz
11+
- dsp-testing/[email protected]
912

1013
paths-ignore:
1114
- tests

0 commit comments

Comments
 (0)