Factor out common code for cleaning up bundle artifacts
This commit is contained in:
parent
92c848eb82
commit
61cdd2503b
3 changed files with 45 additions and 34 deletions
36
lib/setup-codeql.js
generated
36
lib/setup-codeql.js
generated
|
|
@ -429,14 +429,7 @@ async function downloadCodeQL(codeqlURL, maybeBundleVersion, maybeCliVersion, ap
|
|||
const extractedBundlePath = await toolcache.extractTar(archivedBundlePath);
|
||||
const extractionMs = Math.round(perf_hooks_1.performance.now() - extractionStart);
|
||||
logger.debug(`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionMs} ms).`);
|
||||
logger.debug("Cleaning up CodeQL bundle archive.");
|
||||
try {
|
||||
await (0, del_1.default)(archivedBundlePath, { force: true });
|
||||
logger.debug("Deleted CodeQL bundle archive.");
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning("Failed to delete CodeQL bundle archive.");
|
||||
}
|
||||
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", 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 " +
|
||||
|
|
@ -469,14 +462,7 @@ async function downloadCodeQL(codeqlURL, maybeBundleVersion, maybeCliVersion, ap
|
|||
const toolcachedBundlePath = await toolcache.cacheDir(extractedBundlePath, "CodeQL", toolcacheVersion);
|
||||
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
||||
if (toolcachedBundlePath !== extractedBundlePath) {
|
||||
logger.debug("Cleaning up downloaded CodeQL bundle.");
|
||||
try {
|
||||
await (0, del_1.default)(archivedBundlePath, { force: true });
|
||||
logger.debug("Deleted CodeQL bundle from temporary directory.");
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning("Failed to delete CodeQL bundle from temporary directory.");
|
||||
}
|
||||
await cleanUpGlob(extractedBundlePath, "CodeQL bundle from temporary directory", logger);
|
||||
}
|
||||
return {
|
||||
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
||||
|
|
@ -536,4 +522,22 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defau
|
|||
return { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion };
|
||||
}
|
||||
exports.setupCodeQLBundle = setupCodeQLBundle;
|
||||
async function cleanUpGlob(glob, name, logger) {
|
||||
logger.debug(`Cleaning up ${name}.`);
|
||||
try {
|
||||
const deletedPaths = await (0, del_1.default)(glob, { force: true });
|
||||
if (deletedPaths.length === 0) {
|
||||
logger.warning(`Failed to clean up ${name}: no files found matching ${glob}.`);
|
||||
}
|
||||
else if (deletedPaths.length === 1) {
|
||||
logger.debug(`Cleaned up ${name}.`);
|
||||
}
|
||||
else {
|
||||
logger.debug(`Cleaned up ${name} (${deletedPaths.length} files).`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to clean up ${name}: ${e}.`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=setup-codeql.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -581,14 +581,7 @@ export async function downloadCodeQL(
|
|||
logger.debug(
|
||||
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionMs} ms).`,
|
||||
);
|
||||
|
||||
logger.debug("Cleaning up CodeQL bundle archive.");
|
||||
try {
|
||||
await del(archivedBundlePath, { force: true });
|
||||
logger.debug("Deleted CodeQL bundle archive.");
|
||||
} catch (e) {
|
||||
logger.warning("Failed to delete CodeQL bundle archive.");
|
||||
}
|
||||
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
|
||||
|
||||
const bundleVersion =
|
||||
maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
||||
|
|
@ -639,15 +632,11 @@ export async function downloadCodeQL(
|
|||
|
||||
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
||||
if (toolcachedBundlePath !== extractedBundlePath) {
|
||||
logger.debug("Cleaning up downloaded CodeQL bundle.");
|
||||
try {
|
||||
await del(archivedBundlePath, { force: true });
|
||||
logger.debug("Deleted CodeQL bundle from temporary directory.");
|
||||
} catch (e) {
|
||||
logger.warning(
|
||||
"Failed to delete CodeQL bundle from temporary directory.",
|
||||
);
|
||||
}
|
||||
await cleanUpGlob(
|
||||
extractedBundlePath,
|
||||
"CodeQL bundle from temporary directory",
|
||||
logger,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -736,3 +725,21 @@ export async function setupCodeQLBundle(
|
|||
}
|
||||
return { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion };
|
||||
}
|
||||
|
||||
async function cleanUpGlob(glob: string, name: string, logger: Logger) {
|
||||
logger.debug(`Cleaning up ${name}.`);
|
||||
try {
|
||||
const deletedPaths = await del(glob, { force: true });
|
||||
if (deletedPaths.length === 0) {
|
||||
logger.warning(
|
||||
`Failed to clean up ${name}: no files found matching ${glob}.`,
|
||||
);
|
||||
} else if (deletedPaths.length === 1) {
|
||||
logger.debug(`Cleaned up ${name}.`);
|
||||
} else {
|
||||
logger.debug(`Cleaned up ${name} (${deletedPaths.length} files).`);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warning(`Failed to clean up ${name}: ${e}.`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue