mirror of
https://github.com/github/codeql-action.git
synced 2026-04-26 08:48:46 +00:00
Update start-proxy Action to use known language aliases
This commit is contained in:
+12
-24
@@ -18,6 +18,7 @@ import {
|
||||
FeatureEnablement,
|
||||
} from "./feature-flags";
|
||||
import * as json from "./json";
|
||||
import * as knownLanguageAliases from "./known-language-aliases.json";
|
||||
import { KnownLanguage } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import {
|
||||
@@ -188,43 +189,30 @@ export const UPDATEJOB_PROXY_VERSION = "v2.0.20250624110901";
|
||||
const UPDATEJOB_PROXY_URL_PREFIX =
|
||||
"https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.22.0/";
|
||||
|
||||
/*
|
||||
* Language aliases supported by the start-proxy Action.
|
||||
*
|
||||
* In general, the CodeQL CLI is the source of truth for language aliases, and to
|
||||
* allow us to more easily support new languages, we want to avoid hardcoding these
|
||||
* aliases in the Action itself. However this is difficult to do in the start-proxy
|
||||
* Action since this Action does not use CodeQL, so we're accepting some hardcoding
|
||||
* for this Action.
|
||||
*/
|
||||
const LANGUAGE_ALIASES: { [lang: string]: KnownLanguage } = {
|
||||
c: KnownLanguage.cpp,
|
||||
"c++": KnownLanguage.cpp,
|
||||
"c#": KnownLanguage.csharp,
|
||||
kotlin: KnownLanguage.java,
|
||||
typescript: KnownLanguage.javascript,
|
||||
"javascript-typescript": KnownLanguage.javascript,
|
||||
"java-kotlin": KnownLanguage.java,
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the start-proxy language input into its canonical CodeQL language name.
|
||||
*
|
||||
* Exported for testing. Do not use this outside of the start-proxy Action
|
||||
* to avoid complicating the process of adding new CodeQL languages.
|
||||
* This uses the language aliases shipped with the Action and will not be able to resolve aliases
|
||||
* added by versions of the CodeQL CLI newer than the one mentioned in `defaults.json`. However,
|
||||
* this is sufficient for the start-proxy Action since we are already specifying proxy
|
||||
* configurations on a per-language basis.
|
||||
*/
|
||||
export function parseLanguage(language: string): KnownLanguage | undefined {
|
||||
// Normalize to lower case
|
||||
language = language.trim().toLowerCase();
|
||||
|
||||
// See if it's an exact match
|
||||
if (language in KnownLanguage) {
|
||||
if (Object.hasOwn(KnownLanguage, language)) {
|
||||
return language as KnownLanguage;
|
||||
}
|
||||
|
||||
// Check language aliases
|
||||
if (language in LANGUAGE_ALIASES) {
|
||||
return LANGUAGE_ALIASES[language];
|
||||
if (Object.hasOwn(knownLanguageAliases, language)) {
|
||||
language =
|
||||
knownLanguageAliases[language as keyof typeof knownLanguageAliases];
|
||||
if (Object.hasOwn(KnownLanguage, language)) {
|
||||
return language as KnownLanguage;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user