Skip to content

Commit 28db28f

Browse files
committed
Improve clean up if extraction fails
1 parent 3da852e commit 28db28f

File tree

9 files changed

+128
-102
lines changed

9 files changed

+128
-102
lines changed

lib/setup-codeql.js

+14-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js

+25-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-codeql.ts

+21-32
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as path from "path";
44
import { performance } from "perf_hooks";
55

66
import * as toolcache from "@actions/tool-cache";
7-
import del from "del";
87
import { default as deepEqual } from "fast-deep-equal";
98
import * as semver from "semver";
109
import { v4 as uuidV4 } from "uuid";
@@ -24,7 +23,7 @@ import {
2423
import { Logger } from "./logging";
2524
import * as tar from "./tar";
2625
import * as util from "./util";
27-
import { isGoodVersion } from "./util";
26+
import { cleanUpGlob, isGoodVersion } from "./util";
2827

2928
export enum ToolsSource {
3029
Unknown = "UNKNOWN",
@@ -550,18 +549,25 @@ export const downloadCodeQL = async function (
550549
`Finished downloading CodeQL bundle to ${archivedBundlePath} (${downloadDurationMs} ms).`,
551550
);
552551

553-
logger.debug("Extracting CodeQL bundle.");
554-
const extractionStart = performance.now();
555-
const extractedBundlePath = await tar.extract(
556-
archivedBundlePath,
557-
compressionMethod,
558-
tarVersion,
559-
);
560-
const extractionDurationMs = Math.round(performance.now() - extractionStart);
561-
logger.debug(
562-
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
563-
);
564-
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
552+
let extractedBundlePath: string;
553+
let extractionDurationMs: number;
554+
555+
try {
556+
logger.debug("Extracting CodeQL bundle.");
557+
const extractionStart = performance.now();
558+
extractedBundlePath = await tar.extract(
559+
archivedBundlePath,
560+
compressionMethod,
561+
tarVersion,
562+
logger,
563+
);
564+
extractionDurationMs = Math.round(performance.now() - extractionStart);
565+
logger.debug(
566+
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
567+
);
568+
} finally {
569+
await cleanUpGlob(archivedBundlePath, "CodeQL bundle archive", logger);
570+
}
565571

566572
const bundleVersion =
567573
maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
@@ -765,6 +771,7 @@ async function setupCodeQLBundleWithCompressionMethod(
765771
source.codeqlTarPath,
766772
compressionMethod,
767773
zstdAvailability.version,
774+
logger,
768775
);
769776
toolsSource = ToolsSource.Local;
770777
break;
@@ -802,24 +809,6 @@ async function setupCodeQLBundleWithCompressionMethod(
802809
};
803810
}
804811

805-
async function cleanUpGlob(glob: string, name: string, logger: Logger) {
806-
logger.debug(`Cleaning up ${name}.`);
807-
try {
808-
const deletedPaths = await del(glob, { force: true });
809-
if (deletedPaths.length === 0) {
810-
logger.warning(
811-
`Failed to clean up ${name}: no files found matching ${glob}.`,
812-
);
813-
} else if (deletedPaths.length === 1) {
814-
logger.debug(`Cleaned up ${name}.`);
815-
} else {
816-
logger.debug(`Cleaned up ${name} (${deletedPaths.length} files).`);
817-
}
818-
} catch (e) {
819-
logger.warning(`Failed to clean up ${name}: ${e}.`);
820-
}
821-
}
822-
823812
function sanitizeUrlForStatusReport(url: string): string {
824813
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some(
825814
(repo) => url.startsWith(`https://github.com/${repo}/releases/download/`),

0 commit comments

Comments
 (0)