Provide a better error message when language is not recognised
This commit is contained in:
parent
8608105240
commit
d5853409b4
3 changed files with 68 additions and 8 deletions
|
|
@ -17,6 +17,16 @@ const QUERIES_USES_PROPERTY = 'uses';
|
|||
const PATHS_IGNORE_PROPERTY = 'paths-ignore';
|
||||
const PATHS_PROPERTY = 'paths';
|
||||
|
||||
// All the languages supported by CodeQL
|
||||
const ALL_LANGUAGES = ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] as const;
|
||||
type Language = (typeof ALL_LANGUAGES)[number];
|
||||
|
||||
// Some alternate names for languages
|
||||
const LANGUAGE_ALIASES: {[name: string]: Language} = {
|
||||
'c': 'cpp',
|
||||
'typescript': 'javascript',
|
||||
};
|
||||
|
||||
/**
|
||||
* Format of the config file supplied by the user.
|
||||
*/
|
||||
|
|
@ -38,7 +48,7 @@ export interface Config {
|
|||
/**
|
||||
* Set of languages to run analysis for.
|
||||
*/
|
||||
languages: string[];
|
||||
languages: Language[];
|
||||
/**
|
||||
* Map from language to query files.
|
||||
* Will only contain .ql files and not other kinds of files,
|
||||
|
|
@ -405,9 +415,9 @@ function getConfigFilePropertyError(configFile: string, property: string, error:
|
|||
/**
|
||||
* Gets the set of languages in the current repository
|
||||
*/
|
||||
async function getLanguagesInRepo(): Promise<string[]> {
|
||||
async function getLanguagesInRepo(): Promise<Language[]> {
|
||||
// Translate between GitHub's API names for languages and ours
|
||||
const codeqlLanguages = {
|
||||
const codeqlLanguages: {[lang: string]: Language} = {
|
||||
'C': 'cpp',
|
||||
'C++': 'cpp',
|
||||
'C#': 'csharp',
|
||||
|
|
@ -434,7 +444,7 @@ async function getLanguagesInRepo(): Promise<string[]> {
|
|||
// When we pick a language to autobuild we want to pick the most popular traced language
|
||||
// Since sets in javascript maintain insertion order, using a set here and then splatting it
|
||||
// into an array gives us an array of languages ordered by popularity
|
||||
let languages: Set<string> = new Set();
|
||||
let languages: Set<Language> = new Set();
|
||||
for (let lang in response.data) {
|
||||
if (lang in codeqlLanguages) {
|
||||
languages.add(codeqlLanguages[lang]);
|
||||
|
|
@ -456,7 +466,7 @@ async function getLanguagesInRepo(): Promise<string[]> {
|
|||
* If no languages could be detected from either the workflow or the repository
|
||||
* then throw an error.
|
||||
*/
|
||||
async function getLanguages(): Promise<string[]> {
|
||||
async function getLanguages(): Promise<Language[]> {
|
||||
|
||||
// Obtain from action input 'languages' if set
|
||||
let languages = core.getInput('languages', { required: false })
|
||||
|
|
@ -478,7 +488,29 @@ async function getLanguages(): Promise<string[]> {
|
|||
"Please update input in workflow or check that GitHub detects the correct languages in your repository.");
|
||||
}
|
||||
|
||||
return languages;
|
||||
// Make sure they are supported
|
||||
const checkedLanguages: Language[] = [];
|
||||
const unknownLanguages: string[] = [];
|
||||
for (let language of languages) {
|
||||
// Normalise to lower case
|
||||
language = language.toLowerCase();
|
||||
// Resolve any known aliases
|
||||
if (language in LANGUAGE_ALIASES) {
|
||||
language = LANGUAGE_ALIASES[language];
|
||||
}
|
||||
|
||||
const checkedLanguage = ALL_LANGUAGES.find(l => l === language);
|
||||
if (checkedLanguage === undefined) {
|
||||
unknownLanguages.push(language);
|
||||
} else if (checkedLanguages.indexOf(checkedLanguage) === -1) {
|
||||
checkedLanguages.push(checkedLanguage);
|
||||
}
|
||||
}
|
||||
if (unknownLanguages.length > 0) {
|
||||
throw new Error("Did not recognise the following languages: " + unknownLanguages.join(', '));
|
||||
}
|
||||
|
||||
return checkedLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue