mirror of
https://github.com/github/codeql-action.git
synced 2026-10-28 16:47:16 +00:00
Refactor resolveLanguages() to cache output according to CLI feature support
The output of `resolveLanguages()` can vary based on whether the flag `--filter-to-languages-with-queries` is included, but not all versions of the CLI support that. This makes caching a single execution problematic, so I opted to cache it based on whether it's supported. If it's supported, it's used; otherwise, it's not.
This commit is contained in:
@@ -126,9 +126,7 @@ export interface CodeQL {
|
||||
/**
|
||||
* Run 'codeql resolve languages' with '--format=betterjson'.
|
||||
*/
|
||||
resolveLanguages(options?: {
|
||||
filterToLanguagesWithQueries: boolean;
|
||||
}): Promise<ResolveLanguagesOutput>;
|
||||
resolveLanguages(): Promise<ResolveLanguagesOutput>;
|
||||
/**
|
||||
* Run 'codeql resolve build-environment'
|
||||
*/
|
||||
@@ -784,28 +782,30 @@ async function getCodeQLForCmd(
|
||||
];
|
||||
await runCli(cmd, args);
|
||||
},
|
||||
async resolveLanguages(
|
||||
{
|
||||
filterToLanguagesWithQueries,
|
||||
}: {
|
||||
filterToLanguagesWithQueries: boolean;
|
||||
} = { filterToLanguagesWithQueries: false },
|
||||
) {
|
||||
async resolveLanguages() {
|
||||
return getCachedOrRun(
|
||||
CommandCacheKey.ResolveLanguages,
|
||||
cmd,
|
||||
() =>
|
||||
runCliJson<ResolveLanguagesOutput>(cmd, [
|
||||
async () => {
|
||||
const isFilterToLanguagesWithQueriesSupported =
|
||||
await this.supportsFeature(
|
||||
ToolsFeature.BuiltinExtractorsSpecifyDefaultQueries,
|
||||
);
|
||||
return runCliJson<ResolveLanguagesOutput>(cmd, [
|
||||
"resolve",
|
||||
"languages",
|
||||
"--format=betterjson",
|
||||
"--extractor-options-verbosity=4",
|
||||
"--extractor-include-aliases",
|
||||
...(filterToLanguagesWithQueries
|
||||
// TODO: Unconditionally include `--filter-to-languages-with-queries`
|
||||
// once CODEQL_MINIMUM_VERSION is at least v2.23.0
|
||||
// — the first version to support this flag.
|
||||
...(isFilterToLanguagesWithQueriesSupported
|
||||
? ["--filter-to-languages-with-queries"]
|
||||
: []),
|
||||
...getExtraOptionsFromEnv(["resolve", "languages"]),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
isResolveLanguagesOutput,
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user