Skip to content

Commit bc1ea4d

Browse files
committed
Fix +packs language selection
1 parent 3ea37a4 commit bc1ea4d

7 files changed

Lines changed: 104 additions & 10 deletions

File tree

‎lib/entry-points.js‎

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

‎src/codeql.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ const injectedConfigMacro = makeMacro({
668668
new RecordingLogger(),
669669
thisStubConfig.originalUserInput,
670670
augmentationProperties,
671+
thisStubConfig.languages,
671672
);
672673

673674
await codeqlObject.databaseInitCluster(
@@ -737,6 +738,54 @@ injectedConfigMacro.serial(
737738
},
738739
);
739740

741+
const additivePackConfigurations: Array<Record<string, string[]>> = [
742+
{
743+
javascript: ["acme/javascript-queries"],
744+
python: ["acme/python-queries"],
745+
},
746+
{
747+
python: ["acme/python-queries"],
748+
javascript: ["acme/javascript-queries"],
749+
},
750+
{ javascript: ["acme/javascript-queries"] },
751+
{ javascript: ["acme/javascript-queries"], python: [] },
752+
{},
753+
];
754+
for (const packs of additivePackConfigurations) {
755+
injectedConfigMacro.serial(
756+
`additive packs target the analyzed language in ${JSON.stringify(packs)}`,
757+
{
758+
...defaultAugmentationProperties,
759+
packsInputCombines: true,
760+
packsInput: ["acme/python-extra"],
761+
},
762+
{
763+
languages: [BuiltInLanguage.python],
764+
originalUserInput: { packs },
765+
},
766+
{
767+
packs: {
768+
...packs,
769+
python: [...(packs.python || []), "acme/python-extra"],
770+
},
771+
},
772+
);
773+
}
774+
775+
injectedConfigMacro.serial(
776+
"additive packs preserve an existing array",
777+
{
778+
...defaultAugmentationProperties,
779+
packsInputCombines: true,
780+
packsInput: ["acme/python-extra"],
781+
},
782+
{
783+
languages: [BuiltInLanguage.python],
784+
originalUserInput: { packs: ["acme/python-queries"] },
785+
},
786+
{ packs: ["acme/python-queries", "acme/python-extra"] },
787+
);
788+
740789
injectedConfigMacro.serial(
741790
"injected packs from input with existing packs overrides",
742791
{

‎src/config-utils.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,47 @@ test.serial(
622622
},
623623
);
624624

625+
test.serial(
626+
"additive packs use the job language with a shared config file",
627+
async (t) => {
628+
await withTmpDir(async (tempDir) => {
629+
setupActionsVars(tempDir, tempDir);
630+
const userConfig: UserConfig = {
631+
packs: {
632+
javascript: ["acme/javascript-queries"],
633+
python: ["acme/python-queries"],
634+
},
635+
};
636+
const codeql = createStubCodeQL({
637+
async resolveLanguages() {
638+
return {
639+
extractors: { python: [{ extractor_root: "" }] },
640+
};
641+
},
642+
});
643+
const config = await configUtils.initConfig(
644+
initAllState(),
645+
createTestInitConfigInputs({
646+
languagesInput: "python",
647+
packsInput: "+acme/python-extra",
648+
configFile: createConfigFile(yaml.dump(userConfig), tempDir),
649+
tempDir,
650+
codeql,
651+
workspacePath: tempDir,
652+
}),
653+
);
654+
655+
t.deepEqual(config.computedConfig, {
656+
packs: {
657+
javascript: ["acme/javascript-queries"],
658+
python: ["acme/python-queries", "acme/python-extra"],
659+
},
660+
});
661+
t.deepEqual(config.originalUserInput, userConfig);
662+
});
663+
},
664+
);
665+
625666
test.serial("API client used when reading remote config", async (t) => {
626667
return await withTmpDir(async (tempDir) => {
627668
const codeql = createStubCodeQL({

‎src/config-utils.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ export async function initActionState(
437437
logger,
438438
userConfig,
439439
augmentationProperties,
440+
languages,
440441
);
441442

442443
return {

‎src/config/db-config.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ export function generateCodeScanningConfig(
588588
logger: Logger,
589589
originalUserInput: UserConfig,
590590
augmentationProperties: AugmentationProperties,
591+
languages: Language[],
591592
): UserConfig {
592593
// make a copy so we can modify it
593594
const augmentedConfig = cloneObject(originalUserInput);
@@ -616,12 +617,10 @@ export function generateCodeScanningConfig(
616617
} else if (!augmentedConfig.packs) {
617618
augmentedConfig.packs = augmentationProperties.packsInput;
618619
} else {
619-
// At this point, we know there is only one language.
620-
// If there were more than one language, an error would already have been thrown.
621-
const language = Object.keys(augmentedConfig.packs)[0];
622-
augmentedConfig.packs[language] = augmentedConfig.packs[
623-
language
624-
].concat(augmentationProperties.packsInput);
620+
const language = languages[0];
621+
augmentedConfig.packs[language] = (
622+
augmentedConfig.packs[language] ?? []
623+
).concat(augmentationProperties.packsInput);
625624
}
626625
} else {
627626
augmentedConfig.packs = augmentationProperties.packsInput;

‎tests/multi-language-repo/.github/codeql/codeql-config-packaging3.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Pack testing in the CodeQL Action
22

33
disable-default-queries: true
44
packs:
5+
ruby:
6+
- codeql/ruby-queries
57
javascript:
68
- codeql-testing/codeql-pack2
79
- codeql-testing/codeql-pack3:other-query.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed additive `packs` inputs being applied to the wrong language when a shared configuration file lists packs for multiple languages.

0 commit comments

Comments
 (0)