Skip to content

Commit 27dbb1a

Browse files
committed
Infer compression method from URL
Using the downloaded path is unreliable since we may have removed the file extension.
1 parent 379271d commit 27dbb1a

File tree

6 files changed

+48
-36
lines changed

6 files changed

+48
-36
lines changed

lib/setup-codeql.js

+4-3
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

+15-12
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.

src/setup-codeql.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ export const downloadCodeQL = async function (
507507
`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`,
508508
);
509509

510+
const compressionMethod = tar.inferCompressionMethod(codeqlURL);
510511
const dest = path.join(tempDir, uuidV4());
511512
const finalHeaders = Object.assign(
512513
{ "User-Agent": "CodeQL Action" },
@@ -528,8 +529,10 @@ export const downloadCodeQL = async function (
528529

529530
logger.debug("Extracting CodeQL bundle.");
530531
const extractionStart = performance.now();
531-
const { compressionMethod, outputPath: extractedBundlePath } =
532-
await tar.extract(archivedBundlePath);
532+
const extractedBundlePath = await tar.extract(
533+
archivedBundlePath,
534+
compressionMethod,
535+
);
533536
const extractionDurationMs = Math.round(performance.now() - extractionStart);
534537
logger.debug(
535538
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
@@ -658,8 +661,10 @@ export async function setupCodeQLBundle(
658661
let toolsSource: ToolsSource;
659662
switch (source.sourceType) {
660663
case "local": {
661-
const { outputPath } = await tar.extract(source.codeqlTarPath);
662-
codeqlFolder = outputPath;
664+
const compressionMethod = tar.inferCompressionMethod(
665+
source.codeqlTarPath,
666+
);
667+
codeqlFolder = await tar.extract(source.codeqlTarPath, compressionMethod);
663668
toolsSource = ToolsSource.Local;
664669
break;
665670
}

src/tar.ts

+18-15
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,26 @@ export async function isZstdAvailable(
7878

7979
export type CompressionMethod = "gzip" | "zstd";
8080

81-
export async function extract(path: string): Promise<{
82-
compressionMethod: CompressionMethod;
83-
outputPath: string;
84-
}> {
85-
if (path.endsWith(".tar.gz")) {
86-
return {
87-
compressionMethod: "gzip",
81+
export async function extract(
82+
path: string,
83+
compressionMethod: CompressionMethod,
84+
): Promise<string> {
85+
switch (compressionMethod) {
86+
case "gzip":
8887
// While we could also ask tar to autodetect the compression method,
8988
// we defensively keep the gzip call identical as requesting a gzipped
9089
// bundle will soon be a fallback option.
91-
outputPath: await toolcache.extractTar(path),
92-
};
90+
return await toolcache.extractTar(path);
91+
case "zstd":
92+
// By specifying only the "x" flag, we ask tar to autodetect the
93+
// compression method.
94+
return await toolcache.extractTar(path, undefined, "x");
95+
}
96+
}
97+
98+
export function inferCompressionMethod(path: string): CompressionMethod {
99+
if (path.endsWith(".tar.gz")) {
100+
return "gzip";
93101
}
94-
return {
95-
compressionMethod: "zstd",
96-
// By specifying only the "x" flag, we ask tar to autodetect the compression
97-
// method.
98-
outputPath: await toolcache.extractTar(path, undefined, "x"),
99-
};
102+
return "zstd";
100103
}

0 commit comments

Comments
 (0)