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
30
lib/config-utils.js
generated
30
lib/config-utils.js
generated
|
|
@ -23,6 +23,13 @@ const QUERIES_PROPERTY = 'queries';
|
||||||
const QUERIES_USES_PROPERTY = 'uses';
|
const QUERIES_USES_PROPERTY = 'uses';
|
||||||
const PATHS_IGNORE_PROPERTY = 'paths-ignore';
|
const PATHS_IGNORE_PROPERTY = 'paths-ignore';
|
||||||
const PATHS_PROPERTY = 'paths';
|
const PATHS_PROPERTY = 'paths';
|
||||||
|
// All the languages supported by CodeQL
|
||||||
|
const ALL_LANGUAGES = ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'];
|
||||||
|
// Some alternate names for languages
|
||||||
|
const LANGUAGE_ALIASES = {
|
||||||
|
'c': 'cpp',
|
||||||
|
'typescript': 'javascript',
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* A list of queries from https://github.com/github/codeql that
|
* A list of queries from https://github.com/github/codeql that
|
||||||
* we don't want to run. Disabling them here is a quicker alternative to
|
* we don't want to run. Disabling them here is a quicker alternative to
|
||||||
|
|
@ -350,7 +357,28 @@ async function getLanguages() {
|
||||||
throw new Error("Did not detect any languages to analyze. " +
|
throw new Error("Did not detect any languages to analyze. " +
|
||||||
"Please update input in workflow or check that GitHub detects the correct languages in your repository.");
|
"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 = [];
|
||||||
|
const unknownLanguages = [];
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the default config for when the user has not supplied one.
|
* Get the default config for when the user has not supplied one.
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -17,6 +17,16 @@ const QUERIES_USES_PROPERTY = 'uses';
|
||||||
const PATHS_IGNORE_PROPERTY = 'paths-ignore';
|
const PATHS_IGNORE_PROPERTY = 'paths-ignore';
|
||||||
const PATHS_PROPERTY = 'paths';
|
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.
|
* Format of the config file supplied by the user.
|
||||||
*/
|
*/
|
||||||
|
|
@ -38,7 +48,7 @@ export interface Config {
|
||||||
/**
|
/**
|
||||||
* Set of languages to run analysis for.
|
* Set of languages to run analysis for.
|
||||||
*/
|
*/
|
||||||
languages: string[];
|
languages: Language[];
|
||||||
/**
|
/**
|
||||||
* Map from language to query files.
|
* Map from language to query files.
|
||||||
* Will only contain .ql files and not other kinds of 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
|
* 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
|
// Translate between GitHub's API names for languages and ours
|
||||||
const codeqlLanguages = {
|
const codeqlLanguages: {[lang: string]: Language} = {
|
||||||
'C': 'cpp',
|
'C': 'cpp',
|
||||||
'C++': 'cpp',
|
'C++': 'cpp',
|
||||||
'C#': 'csharp',
|
'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
|
// 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
|
// 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
|
// 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) {
|
for (let lang in response.data) {
|
||||||
if (lang in codeqlLanguages) {
|
if (lang in codeqlLanguages) {
|
||||||
languages.add(codeqlLanguages[lang]);
|
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
|
* If no languages could be detected from either the workflow or the repository
|
||||||
* then throw an error.
|
* then throw an error.
|
||||||
*/
|
*/
|
||||||
async function getLanguages(): Promise<string[]> {
|
async function getLanguages(): Promise<Language[]> {
|
||||||
|
|
||||||
// Obtain from action input 'languages' if set
|
// Obtain from action input 'languages' if set
|
||||||
let languages = core.getInput('languages', { required: false })
|
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.");
|
"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