Move logging messages to downstream function and add deprecation notice

This commit is contained in:
Fotis Koutoulakis (@NlightNFotis) 2024-05-10 16:41:19 +01:00 committed by Fotis Koutoulakis
parent 1796f5474f
commit bcc13653e8
7 changed files with 142 additions and 33 deletions

20
lib/setup-codeql.js generated
View file

@ -226,6 +226,7 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
if (toolsInput &&
!CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput) &&
!toolsInput.startsWith("http")) {
logger.info("Using CodeQL CLI from local path $path");
return {
codeqlTarPath: toolsInput,
sourceType: "local",
@ -245,9 +246,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
*/
const forceShippedTools = toolsInput && CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput);
if (forceShippedTools) {
logger.info("Overriding the version of the CodeQL tools by the version shipped with the Action since " +
`"tools: linked" or "tools: latest" was requested. The version shipped with the Action is ` +
`${defaultCliVersion.cliVersion}.`);
logger.info(`Overriding the version of the CodeQL tools by ${defaultCliVersion.cliVersion}, the version shipped with the Action since ` +
`tools: ${toolsInput} was requested.`);
if (toolsInput === "latest") {
logger.warning("The 'latest' alias for the CodeQL tools has been deprecated. Please use 'linked' instead.");
}
}
/** CLI version number, for example 2.12.6. */
let cliVersion;
@ -337,10 +340,12 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
logger.info(`Did not find CodeQL tools version ${humanReadableVersion} in the toolcache.`);
}
if (codeqlFolder) {
const version = cliVersion ?? humanReadableVersion;
logger.info(`Using CodeQL CLI version ${version} from toolcache at ${codeqlFolder}`);
return {
codeqlFolder,
sourceType: "toolcache",
toolsVersion: cliVersion ?? humanReadableVersion,
toolsVersion: version,
};
}
// If we don't find the requested version on Enterprise, we may allow a
@ -357,12 +362,14 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
if (!url) {
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, logger);
}
const toolsVersion = cliVersion ?? humanReadableVersion;
logger.info(`Using CodeQL CLI version ${toolsVersion} downloaded from ${url}.`);
return {
bundleVersion: tagName && tryGetBundleVersionFromTagName(tagName, logger),
cliVersion,
codeqlURL: url,
sourceType: "download",
toolsVersion: cliVersion ?? humanReadableVersion,
toolsVersion,
};
}
exports.getCodeQLSource = getCodeQLSource;
@ -381,6 +388,8 @@ async function tryGetFallbackToolcacheVersion(cliVersion, tagName, logger) {
return fallbackVersion;
}
exports.tryGetFallbackToolcacheVersion = tryGetFallbackToolcacheVersion;
// Exported using `export const` for testing purposes. Specifically, we want to
// be able to stub this function and have other functions in this file use that stub.
const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVersion, apiDetails, variant, tempDir, logger) {
const parsedCodeQLURL = new URL(codeqlURL);
const searchParams = new URLSearchParams(parsedCodeQLURL.search);
@ -496,7 +505,6 @@ function getCanonicalToolcacheVersion(cliVersion, bundleVersion, logger) {
*/
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger) {
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, logger);
logger.info(`Using CodeQL CLI version ${source.toolsVersion} from ${source.sourceType}.`);
let codeqlFolder;
let toolsVersion = source.toolsVersion;
let toolsDownloadDurationMs;