Skip to content

Commit 76be57f

Browse files
committed
Add getStoredSupportedLanguageMap()
1 parent 796b998 commit 76be57f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

.github/workflows/validate-resolved-languages.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ jobs:
6161
echo "::error file=src/resolved-languages.json::The resolved-languages.json file is missing."
6262
exit 1
6363
fi
64+
#
65+
# Please update getStoredSupportedLanguageMap() when you update the
66+
# following call to use --filter-to-languages-with-queries.
67+
#
6468
"${CODEQL}" resolve languages --format=betterjson --extractor-include-aliases > resolved-languages.json
6569
if ! diff -u resolved-languages.json "${RESOLVED_LANGUAGES_FILE}"; then
6670
echo "::error file=src/resolved-languages.json::The saved resolved-languages.json file is out of date."

src/config-utils.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "./analyses";
1717
import * as api from "./api-client";
1818
import { CachingKind, getCachingKind } from "./caching-utils";
19-
import { type CodeQL } from "./codeql";
19+
import { type BetterResolveLanguagesOutput, type CodeQL } from "./codeql";
2020
import { shouldPerformDiffInformedAnalysis } from "./diff-informed-analysis-utils";
2121
import { Feature, FeatureEnablement } from "./feature-flags";
2222
import { getGitRoot, isAnalyzingDefaultBranch } from "./git-utils";
@@ -27,6 +27,7 @@ import {
2727
OverlayDatabaseMode,
2828
} from "./overlay-database-utils";
2929
import { RepositoryNwo } from "./repository";
30+
import * as resolvedLanguages from "./resolved-languages.json";
3031
import { downloadTrapCaches } from "./trap-caching";
3132
import {
3233
GitHubVersion,
@@ -331,6 +332,30 @@ export async function getSupportedLanguageMap(
331332
`The CodeQL CLI supports the following languages: ${Object.keys(resolveResult.extractors).join(", ")}`,
332333
);
333334
}
335+
return buildSupportedLanguageMap(
336+
resolveResult,
337+
resolveSupportedLanguagesUsingCli,
338+
);
339+
}
340+
341+
// This function serves the same purpose as getSupportedLanguageMap(), but it
342+
// uses the stored resolved-languages.json file instead of calling out to the
343+
// CodeQL CLI.
344+
export function getStoredSupportedLanguageMap(): Record<string, string> {
345+
return buildSupportedLanguageMap(
346+
resolvedLanguages,
347+
// resolveSupportedLanguagesUsingCli is false because we currently generate
348+
// resolved-languages.json without the --filter-to-languages-with-queries
349+
// flag (see .github/workflows/validate-resolved-languages.yml). Once that
350+
// changes, we should set this to true.
351+
false,
352+
);
353+
}
354+
355+
function buildSupportedLanguageMap(
356+
resolveResult: BetterResolveLanguagesOutput,
357+
resolveSupportedLanguagesUsingCli: boolean,
358+
): Record<string, string> {
334359
const supportedLanguages: Record<string, string> = {};
335360
// Populate canonical language names
336361
for (const extractor of Object.keys(resolveResult.extractors)) {

0 commit comments

Comments
 (0)