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 extractedBundlePath = await toolcache.extractTar(archivedBundlePath);
|
||||||
const extractionMs = Math.round(perf_hooks_1.performance.now() - extractionStart);
|
const extractionMs = Math.round(perf_hooks_1.performance.now() - extractionStart);
|
||||||
logger.debug(`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionMs} ms).`);
|
logger.debug(`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionMs} ms).`);
|
||||||
logger.debug("Cleaning up CodeQL bundle archive.");
|
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
const bundleVersion = maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
const bundleVersion = maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
||||||
if (bundleVersion === undefined) {
|
if (bundleVersion === undefined) {
|
||||||
logger.debug("Could not cache CodeQL tools because we could not determine the bundle version from the " +
|
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);
|
const toolcachedBundlePath = await toolcache.cacheDir(extractedBundlePath, "CodeQL", toolcacheVersion);
|
||||||
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
||||||
if (toolcachedBundlePath !== extractedBundlePath) {
|
if (toolcachedBundlePath !== extractedBundlePath) {
|
||||||
logger.debug("Cleaning up downloaded CodeQL bundle.");
|
await cleanUpGlob(extractedBundlePath, "CodeQL bundle from temporary directory", logger);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
||||||
|
|
@ -536,4 +522,22 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defau
|
||||||
return { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion };
|
return { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion };
|
||||||
}
|
}
|
||||||
exports.setupCodeQLBundle = setupCodeQLBundle;
|
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
|
//# 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(
|
logger.debug(
|
||||||
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionMs} ms).`,
|
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionMs} ms).`,
|
||||||
);
|
);
|
||||||
|
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const bundleVersion =
|
const bundleVersion =
|
||||||
maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
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.
|
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
||||||
if (toolcachedBundlePath !== extractedBundlePath) {
|
if (toolcachedBundlePath !== extractedBundlePath) {
|
||||||
logger.debug("Cleaning up downloaded CodeQL bundle.");
|
await cleanUpGlob(
|
||||||
try {
|
extractedBundlePath,
|
||||||
await del(archivedBundlePath, { force: true });
|
"CodeQL bundle from temporary directory",
|
||||||
logger.debug("Deleted CodeQL bundle from temporary directory.");
|
logger,
|
||||||
} catch (e) {
|
);
|
||||||
logger.warning(
|
|
||||||
"Failed to delete CodeQL bundle from temporary directory.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -736,3 +725,21 @@ export async function setupCodeQLBundle(
|
||||||
}
|
}
|
||||||
return { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion };
|
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