Log disk info throughout for debugging

This commit is contained in:
Henry Mercer
2023-08-01 18:30:17 +01:00
parent 5edc73a9a0
commit 14567d9b12
12 changed files with 741 additions and 57 deletions
+39 -26
View File
@@ -31,6 +31,7 @@ const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const perf_hooks_1 = require("perf_hooks");
const toolcache = __importStar(require("@actions/tool-cache"));
const check_disk_space_1 = __importDefault(require("check-disk-space"));
const del_1 = __importDefault(require("del"));
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
const semver = __importStar(require("semver"));
@@ -88,14 +89,14 @@ function tryGetCodeQLCliVersionForRelease(release, logger) {
return undefined;
}
else if (cliVersionsFromMarkerFiles.length === 0) {
logger.debug(`Failed to find the CodeQL CLI version for release ${release.tag_name}.`);
logger.info(`Failed to find the CodeQL CLI version for release ${release.tag_name}.`);
return undefined;
}
return cliVersionsFromMarkerFiles[0];
}
async function tryFindCliVersionDotcomOnly(tagName, logger) {
try {
logger.debug(`Fetching the GitHub Release for the CodeQL bundle tagged ${tagName}.`);
logger.info(`Fetching the GitHub Release for the CodeQL bundle tagged ${tagName}.`);
const apiClient = api.getApiClient();
const codeQLActionRepository = getCodeQLActionRepository(logger);
const release = await apiClient.rest.repos.getReleaseByTag({
@@ -106,7 +107,7 @@ async function tryFindCliVersionDotcomOnly(tagName, logger) {
return tryGetCodeQLCliVersionForRelease(release.data, logger);
}
catch (e) {
logger.debug(`Failed to find the CLI version for the CodeQL bundle tagged ${tagName}. ${(0, util_1.wrapError)(e).message}`);
logger.info(`Failed to find the CLI version for the CodeQL bundle tagged ${tagName}. ${(0, util_1.wrapError)(e).message}`);
return undefined;
}
}
@@ -181,7 +182,7 @@ async function getCodeQLBundleDownloadURL(tagName, apiDetails, variant, logger)
function tryGetBundleVersionFromTagName(tagName, logger) {
const match = tagName.match(/^codeql-bundle-(.*)$/);
if (match === null || match.length < 2) {
logger.debug(`Could not determine bundle version from tag ${tagName}.`);
logger.info(`Could not determine bundle version from tag ${tagName}.`);
return undefined;
}
return match[1];
@@ -189,7 +190,7 @@ function tryGetBundleVersionFromTagName(tagName, logger) {
function tryGetTagNameFromUrl(url, logger) {
const match = url.match(/\/(codeql-bundle-.*)\//);
if (match === null || match.length < 2) {
logger.debug(`Could not determine tag name for URL ${url}.`);
logger.info(`Could not determine tag name for URL ${url}.`);
return undefined;
}
return match[1];
@@ -204,7 +205,7 @@ function tryGetBundleVersionFromUrl(url, logger) {
exports.tryGetBundleVersionFromUrl = tryGetBundleVersionFromUrl;
function convertToSemVer(version, logger) {
if (!semver.valid(version)) {
logger.debug(`Bundle version ${version} is not in SemVer format. Will treat it as pre-release 0.0.0-${version}.`);
logger.info(`Bundle version ${version} is not in SemVer format. Will treat it as pre-release 0.0.0-${version}.`);
version = `0.0.0-${version}`;
}
const s = semver.clean(version);
@@ -228,7 +229,7 @@ async function findOverridingToolsInCache(humanReadableVersion, logger) {
.filter(({ folder }) => fs.existsSync(path.join(folder, "pinned-version")));
if (candidates.length === 1) {
const candidate = candidates[0];
logger.debug(`CodeQL tools version ${candidate.version} in toolcache overriding version ${humanReadableVersion}.`);
logger.info(`CodeQL tools version ${candidate.version} in toolcache overriding version ${humanReadableVersion}.`);
return {
codeqlFolder: candidate.folder,
sourceType: "toolcache",
@@ -236,10 +237,10 @@ async function findOverridingToolsInCache(humanReadableVersion, logger) {
};
}
else if (candidates.length === 0) {
logger.debug("Did not find any candidate pinned versions of the CodeQL tools in the toolcache.");
logger.info("Did not find any candidate pinned versions of the CodeQL tools in the toolcache.");
}
else {
logger.debug("Could not use CodeQL tools from the toolcache since more than one candidate pinned " +
logger.info("Could not use CodeQL tools from the toolcache since more than one candidate pinned " +
"version was found in the toolcache.");
}
return undefined;
@@ -301,7 +302,7 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
tagName ??
url ??
"unknown";
logger.debug("Attempting to obtain CodeQL tools. " +
logger.info("Attempting to obtain CodeQL tools. " +
`CLI version: ${cliVersion ?? "unknown"}, ` +
`bundle tag name: ${tagName ?? "unknown"}, ` +
`URL: ${url ?? "unspecified"}.`);
@@ -311,26 +312,26 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
codeqlFolder = toolcache.find("CodeQL", cliVersion);
// Fall back to matching `x.y.z-<tagName>`.
if (!codeqlFolder) {
logger.debug("Didn't find a version of the CodeQL tools in the toolcache with a version number " +
logger.info("Didn't find a version of the CodeQL tools in the toolcache with a version number " +
`exactly matching ${cliVersion}.`);
const allVersions = toolcache.findAllVersions("CodeQL");
logger.debug(`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(allVersions)}.`);
logger.info(`Found the following versions of the CodeQL tools in the toolcache: ${JSON.stringify(allVersions)}.`);
// If there is exactly one version of the CodeQL tools in the toolcache, and that version is
// the form `x.y.z-<tagName>`, then use it.
const candidateVersions = allVersions.filter((version) => version.startsWith(`${cliVersion}-`));
if (candidateVersions.length === 1) {
logger.debug(`Exactly one version of the CodeQL tools starting with ${cliVersion} found in the ` +
logger.info(`Exactly one version of the CodeQL tools starting with ${cliVersion} found in the ` +
"toolcache, using that.");
codeqlFolder = toolcache.find("CodeQL", candidateVersions[0]);
}
else if (candidateVersions.length === 0) {
logger.debug(`Didn't find any versions of the CodeQL tools starting with ${cliVersion} ` +
logger.info(`Didn't find any versions of the CodeQL tools starting with ${cliVersion} ` +
`in the toolcache. Trying next fallback method.`);
}
else {
logger.warning(`Found ${candidateVersions.length} versions of the CodeQL tools starting with ` +
`${cliVersion} in the toolcache, but at most one was expected.`);
logger.debug("Trying next fallback method.");
logger.info("Trying next fallback method.");
}
}
}
@@ -341,7 +342,7 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
codeqlFolder = toolcache.find("CodeQL", fallbackVersion);
}
else {
logger.debug("Could not determine a fallback toolcache version number for CodeQL tools version " +
logger.info("Could not determine a fallback toolcache version number for CodeQL tools version " +
`${humanReadableVersion}.`);
}
}
@@ -391,7 +392,7 @@ async function tryGetFallbackToolcacheVersion(cliVersion, tagName, logger) {
return undefined;
}
const fallbackVersion = convertToSemVer(bundleVersion, logger);
logger.debug(`Computed a fallback toolcache version number of ${fallbackVersion} for CodeQL version ` +
logger.info(`Computed a fallback toolcache version number of ${fallbackVersion} for CodeQL version ` +
`${cliVersion ?? tagName}.`);
return fallbackVersion;
}
@@ -408,34 +409,38 @@ async function downloadCodeQL(codeqlURL, maybeBundleVersion, maybeCliVersion, ap
// We also don't want to send an authorization header if there's already a token provided in the URL.
let authorization = undefined;
if (searchParams.has("token")) {
logger.debug("CodeQL tools URL contains an authorization token.");
logger.info("CodeQL tools URL contains an authorization token.");
}
else if (codeqlURL.startsWith(`${apiDetails.url}/`)) {
logger.debug("Providing an authorization token to download CodeQL tools.");
logger.info("Providing an authorization token to download CodeQL tools.");
authorization = `token ${apiDetails.auth}`;
}
else {
logger.debug("Downloading CodeQL tools without an authorization token.");
logger.info("Downloading CodeQL tools without an authorization token.");
}
await printDiskSpace(logger);
logger.info(`Downloading CodeQL tools from ${codeqlURL}. This may take a while.`);
const dest = path.join(tempDir, (0, uuid_1.v4)());
const finalHeaders = Object.assign({ "User-Agent": "CodeQL Action" }, headers);
const toolsDownloadStart = perf_hooks_1.performance.now();
const codeqlPath = await toolcache.downloadTool(codeqlURL, dest, authorization, finalHeaders);
const toolsDownloadDurationMs = Math.round(perf_hooks_1.performance.now() - toolsDownloadStart);
logger.debug(`Finished downloading CodeQL bundle to ${codeqlPath} (${toolsDownloadDurationMs} ms).`);
logger.info(`Finished downloading CodeQL bundle to ${codeqlPath} (${toolsDownloadDurationMs} ms).`);
await printDiskSpace(logger);
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
logger.debug(`Finished extracting CodeQL bundle to ${codeqlExtracted}.`);
logger.info(`Finished extracting CodeQL bundle to ${codeqlExtracted}.`);
await printDiskSpace(logger);
try {
await (0, del_1.default)(codeqlPath, { force: true });
logger.debug("Deleted CodeQL bundle archive.");
logger.info("Deleted CodeQL bundle archive.");
}
catch (e) {
logger.warning("Failed to delete CodeQL bundle archive.");
}
await printDiskSpace(logger);
const bundleVersion = maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
if (bundleVersion === undefined) {
logger.debug("Could not cache CodeQL tools because we could not determine the bundle version from the " +
logger.info("Could not cache CodeQL tools because we could not determine the bundle version from the " +
`URL ${codeqlURL}.`);
return {
toolsVersion: maybeCliVersion ?? "unknown",
@@ -461,9 +466,13 @@ async function downloadCodeQL(codeqlURL, maybeBundleVersion, maybeCliVersion, ap
const toolcacheVersion = maybeCliVersion?.match(/^[0-9]+\.[0-9]+\.[0-9]+$/)
? `${maybeCliVersion}-${bundleVersion}`
: convertToSemVer(bundleVersion, logger);
const codeqlFolder = await toolcache.cacheDir(codeqlExtracted, "CodeQL", toolcacheVersion);
await printDiskSpace(logger);
await (0, del_1.default)(codeqlExtracted, { force: true });
await printDiskSpace(logger);
return {
toolsVersion: maybeCliVersion ?? toolcacheVersion,
codeqlFolder: await toolcache.cacheDir(codeqlExtracted, "CodeQL", toolcacheVersion),
codeqlFolder,
toolsDownloadDurationMs,
};
}
@@ -502,7 +511,7 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defau
break;
case "toolcache":
codeqlFolder = source.codeqlFolder;
logger.debug(`CodeQL found in cache ${codeqlFolder}`);
logger.info(`CodeQL found in cache ${codeqlFolder}`);
toolsSource = ToolsSource.Toolcache;
break;
case "download": {
@@ -519,4 +528,8 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defau
return { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion };
}
exports.setupCodeQLBundle = setupCodeQLBundle;
async function printDiskSpace(logger) {
const diskSpaceInfo = await (0, check_disk_space_1.default)(process.platform === "win32" ? path.parse(process.cwd()).root : "/");
logger.info(`Disk space info: ${diskSpaceInfo.free / (1024 * 1024 * 1024)} GB free of ${diskSpaceInfo.size / (1024 * 1024 * 1024)} GB`);
}
//# sourceMappingURL=setup-codeql.js.map