Add the feature to bypass the toolcache for kotlin and swift
This works by moving the logic to check for toolcache bypass out of creating the codeql instance. The logic now _may_ perform an API request in order to check what languages are in the repository. This check is redundant because the same call is being made later in the action when the actual list of languages is calculated.
This commit is contained in:
parent
5b7c9daecd
commit
f79028af27
27 changed files with 471 additions and 78 deletions
|
|
@ -15,7 +15,12 @@ import {
|
|||
} from "./codeql";
|
||||
import * as externalQueries from "./external-queries";
|
||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||
import { Language, parseLanguage } from "./languages";
|
||||
import {
|
||||
Language,
|
||||
LanguageOrAlias,
|
||||
LANGUAGE_ALIASES,
|
||||
parseLanguage,
|
||||
} from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import { downloadTrapCaches } from "./trap-caching";
|
||||
|
|
@ -857,7 +862,7 @@ export function getUnknownLanguagesError(languages: string[]): string {
|
|||
async function getLanguagesInRepo(
|
||||
repository: RepositoryNwo,
|
||||
logger: Logger
|
||||
): Promise<Language[]> {
|
||||
): Promise<LanguageOrAlias[]> {
|
||||
logger.debug(`GitHub repo ${repository.owner} ${repository.repo}`);
|
||||
const response = await api.getApiClient().repos.listLanguages({
|
||||
owner: repository.owner,
|
||||
|
|
@ -870,7 +875,7 @@ async function getLanguagesInRepo(
|
|||
// 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
|
||||
const languages: Set<Language> = new Set();
|
||||
const languages: Set<LanguageOrAlias> = new Set();
|
||||
for (const lang of Object.keys(response.data)) {
|
||||
const parsedLang = parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
|
|
@ -896,21 +901,21 @@ async function getLanguages(
|
|||
repository: RepositoryNwo,
|
||||
logger: Logger
|
||||
): Promise<Language[]> {
|
||||
// Obtain from action input 'languages' if set
|
||||
let languages = (languagesInput || "")
|
||||
.split(",")
|
||||
.map((x) => x.trim())
|
||||
.filter((x) => x.length > 0);
|
||||
logger.info(`Languages from configuration: ${JSON.stringify(languages)}`);
|
||||
// Obtain languages without filtering them.
|
||||
const { rawLanguages, autodetected } = await getRawLanguages(
|
||||
languagesInput,
|
||||
repository,
|
||||
logger
|
||||
);
|
||||
|
||||
if (languages.length === 0) {
|
||||
// Obtain languages as all languages in the repo that can be analysed
|
||||
languages = await getLanguagesInRepo(repository, logger);
|
||||
let languages: string[];
|
||||
if (autodetected) {
|
||||
const availableLanguages = await codeQL.resolveLanguages();
|
||||
languages = languages.filter((value) => value in availableLanguages);
|
||||
logger.info(
|
||||
`Automatically detected languages: ${JSON.stringify(languages)}`
|
||||
);
|
||||
languages = rawLanguages.filter((value) => value in availableLanguages);
|
||||
logger.info(`Automatically detected languages: ${languages.join(", ")}`);
|
||||
} else {
|
||||
languages = rawLanguages;
|
||||
logger.info(`Languages from configuration: ${languages.join(", ")}`);
|
||||
}
|
||||
|
||||
// If the languages parameter was not given and no languages were
|
||||
|
|
@ -924,10 +929,14 @@ async function getLanguages(
|
|||
const unknownLanguages: string[] = [];
|
||||
for (const language of languages) {
|
||||
const parsedLanguage = parseLanguage(language);
|
||||
const dealiasedLanguage =
|
||||
parsedLanguage && parsedLanguage in LANGUAGE_ALIASES
|
||||
? LANGUAGE_ALIASES[parsedLanguage]
|
||||
: (parsedLanguage as Language);
|
||||
if (parsedLanguage === undefined) {
|
||||
unknownLanguages.push(language);
|
||||
} else if (parsedLanguages.indexOf(parsedLanguage) === -1) {
|
||||
parsedLanguages.push(parsedLanguage);
|
||||
} else if (!parsedLanguages.includes(dealiasedLanguage)) {
|
||||
parsedLanguages.push(dealiasedLanguage);
|
||||
}
|
||||
}
|
||||
if (unknownLanguages.length > 0) {
|
||||
|
|
@ -937,6 +946,38 @@ async function getLanguages(
|
|||
return parsedLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set of languages in the current repository without checking to
|
||||
* see if these languages are actually supported by CodeQL.
|
||||
*
|
||||
* @param languagesInput The languages from the workflow input
|
||||
* @param repository the owner/name of the repository
|
||||
* @param logger a logger
|
||||
* @returns A tuple containing a list of languages in this repository that might be
|
||||
* analyzable and whether or not this list was determined automatically.
|
||||
*/
|
||||
export async function getRawLanguages(
|
||||
languagesInput: string | undefined,
|
||||
repository: RepositoryNwo,
|
||||
logger: Logger
|
||||
) {
|
||||
// Obtain from action input 'languages' if set
|
||||
let rawLanguages = (languagesInput || "")
|
||||
.split(",")
|
||||
.map((x) => x.trim().toLowerCase())
|
||||
.filter((x) => x.length > 0);
|
||||
let autodetected: boolean;
|
||||
if (rawLanguages.length) {
|
||||
autodetected = false;
|
||||
} else {
|
||||
autodetected = true;
|
||||
|
||||
// Obtain languages as all languages in the repo that can be analysed
|
||||
rawLanguages = (await getLanguagesInRepo(repository, logger)) as string[];
|
||||
}
|
||||
return { rawLanguages, autodetected };
|
||||
}
|
||||
|
||||
async function addQueriesAndPacksFromWorkflow(
|
||||
codeQL: CodeQL,
|
||||
queriesInput: string,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue