Skip to content

Commit 4b5b9e6

Browse files
committed
Infer compression method from URL
Using the downloaded path is unreliable since we may have removed the file extension.
1 parent d0e358e commit 4b5b9e6

File tree

6 files changed

+48
-36
lines changed

6 files changed

+48
-36
lines changed

lib/setup-codeql.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-codeql.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ export const downloadCodeQL = async function (
519519
`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`,
520520
);
521521

522+
const compressionMethod = tar.inferCompressionMethod(codeqlURL);
522523
const dest = path.join(tempDir, uuidV4());
523524
const finalHeaders = Object.assign(
524525
{ "User-Agent": "CodeQL Action" },
@@ -540,8 +541,10 @@ export const downloadCodeQL = async function (
540541

541542
logger.debug("Extracting CodeQL bundle.");
542543
const extractionStart = performance.now();
543-
const { compressionMethod, outputPath: extractedBundlePath } =
544-
await tar.extract(archivedBundlePath);
544+
const extractedBundlePath = await tar.extract(
545+
archivedBundlePath,
546+
compressionMethod,
547+
);
545548
const extractionDurationMs = Math.round(performance.now() - extractionStart);
546549
logger.debug(
547550
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${extractionDurationMs} ms).`,
@@ -673,8 +676,10 @@ async function setupCodeQLBundleWithZstdOption(
673676
let toolsSource: ToolsSource;
674677
switch (source.sourceType) {
675678
case "local": {
676-
const { outputPath } = await tar.extract(source.codeqlTarPath);
677-
codeqlFolder = outputPath;
679+
const compressionMethod = tar.inferCompressionMethod(
680+
source.codeqlTarPath,
681+
);
682+
codeqlFolder = await tar.extract(source.codeqlTarPath, compressionMethod);
678683
toolsSource = ToolsSource.Local;
679684
break;
680685
}

src/tar.ts

Lines changed: 18 additions & 15 deletions
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)