FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix additive packs for the selected language by theinfosecguy · Pull Request #4314 · github/codeql-action · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) .md  (1) .ts  (4) .yml  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 5 additions & 4 deletions lib/entry-points.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions src/codeql.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ const injectedConfigMacro = makeMacro({
new RecordingLogger(),
thisStubConfig.originalUserInput,
augmentationProperties,
thisStubConfig.languages,
);

await codeqlObject.databaseInitCluster(
Expand Down Expand Up @@ -737,6 +738,54 @@ injectedConfigMacro.serial(
},
);

const additivePackConfigurations: Array<Record<string, string[]>> = [
{
javascript: ["acme/javascript-queries"],
python: ["acme/python-queries"],
},
{
python: ["acme/python-queries"],
javascript: ["acme/javascript-queries"],
},
{ javascript: ["acme/javascript-queries"] },
{ javascript: ["acme/javascript-queries"], python: [] },
{},
];
for (const packs of additivePackConfigurations) {
injectedConfigMacro.serial(
`additive packs target the analyzed language in ${JSON.stringify(packs)}`,
{
...defaultAugmentationProperties,
packsInputCombines: true,
packsInput: ["acme/python-extra"],
},
{
languages: [BuiltInLanguage.python],
originalUserInput: { packs },
},
{
packs: {
...packs,
python: [...(packs.python || []), "acme/python-extra"],
},
},
);
}

injectedConfigMacro.serial(
"additive packs preserve an existing array",
{
...defaultAugmentationProperties,
packsInputCombines: true,
packsInput: ["acme/python-extra"],
},
{
languages: [BuiltInLanguage.python],
originalUserInput: { packs: ["acme/python-queries"] },
},
{ packs: ["acme/python-queries", "acme/python-extra"] },
);

injectedConfigMacro.serial(
"injected packs from input with existing packs overrides",
{
Expand Down
41 changes: 41 additions & 0 deletions src/config-utils.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,47 @@ test.serial(
},
);

test.serial(
"additive packs use the job language with a shared config file",
async (t) => {
await withTmpDir(async (tempDir) => {
setupActionsVars(tempDir, tempDir);
const userConfig: UserConfig = {
packs: {
javascript: ["acme/javascript-queries"],
python: ["acme/python-queries"],
},
};
const codeql = createStubCodeQL({
async resolveLanguages() {
return {
extractors: { python: [{ extractor_root: "" }] },
};
},
});
const config = await configUtils.initConfig(
initAllState(),
createTestInitConfigInputs({
languagesInput: "python",
packsInput: "+acme/python-extra",
configFile: createConfigFile(yaml.dump(userConfig), tempDir),
tempDir,
codeql,
workspacePath: tempDir,
}),
);

t.deepEqual(config.computedConfig, {
packs: {
javascript: ["acme/javascript-queries"],
python: ["acme/python-queries", "acme/python-extra"],
},
});
t.deepEqual(config.originalUserInput, userConfig);
});
},
);

test.serial("API client used when reading remote config", async (t) => {
return await withTmpDir(async (tempDir) => {
const codeql = createStubCodeQL({
Expand Down
1 change: 1 addition & 0 deletions src/config-utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ export async function initActionState(
logger,
userConfig,
augmentationProperties,
languages,
);

return {
Expand Down
11 changes: 5 additions & 6 deletions src/config/db-config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ export function generateCodeScanningConfig(
logger: Logger,
originalUserInput: UserConfig,
augmentationProperties: AugmentationProperties,
languages: Language[],
): UserConfig {
// make a copy so we can modify it
const augmentedConfig = cloneObject(originalUserInput);
Expand Down Expand Up @@ -616,12 +617,10 @@ export function generateCodeScanningConfig(
} else if (!augmentedConfig.packs) {
augmentedConfig.packs = augmentationProperties.packsInput;
} else {
// At this point, we know there is only one language.
// If there were more than one language, an error would already have been thrown.
const language = Object.keys(augmentedConfig.packs)[0];
augmentedConfig.packs[language] = augmentedConfig.packs[
language
].concat(augmentationProperties.packsInput);
const language = languages[0];
augmentedConfig.packs[language] = (
augmentedConfig.packs[language] ?? []
).concat(augmentationProperties.packsInput);
}
} else {
augmentedConfig.packs = augmentationProperties.packsInput;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Pack testing in the CodeQL Action

disable-default-queries: true
packs:
ruby:
- codeql/ruby-queries
javascript:
- codeql-testing/codeql-pack2
- codeql-testing/codeql-pack3:other-query.ql
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed additive `packs` inputs being applied to the wrong language when a shared configuration file lists packs for multiple languages.

Back | FazBrowse Home | New Git URL