Skip to content

Commit f289f40

Browse files
committed
feat: nest streaming download inside try/catch to allow for retry if it fails
1 parent 6f90ed0 commit f289f40

File tree

4 files changed

+59
-47
lines changed

4 files changed

+59
-47
lines changed

lib/tools-download.js

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

lib/tools-download.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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as api from "./api-client";
1212
import * as defaults from "./defaults.json";
1313
import {
1414
CODEQL_VERSION_ZSTD_BUNDLE,
15-
CodeQLDefaultVersionInfo
15+
CodeQLDefaultVersionInfo,
1616
} from "./feature-flags";
1717
import { formatDuration, Logger } from "./logging";
1818
import * as tar from "./tar";

src/tools-download.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http";
22
import * as path from "path";
33
import { performance } from "perf_hooks";
44

5+
import * as core from "@actions/core";
56
import { getProxyUrl } from "@actions/http-client/lib/proxy";
67
import * as toolcache from "@actions/tool-cache";
78
import { https } from "follow-redirects";
89
import { v4 as uuidV4 } from "uuid";
910

1011
import { formatDuration, Logger } from "./logging";
1112
import * as tar from "./tar";
12-
import { cleanUpGlob } from "./util";
13+
import { cleanUpGlob, getErrorMessage } from "./util";
1314

1415
/**
1516
* High watermark to use when streaming the download and extraction of the CodeQL tools.
@@ -88,37 +89,42 @@ export async function downloadAndExtract(
8889

8990
const compressionMethod = tar.inferCompressionMethod(codeqlURL);
9091

91-
// TODO: Re-enable streaming when we have a more reliable way to respect proxy settings.
92-
93-
if (compressionMethod === "zstd" && process.platform === "linux") {
94-
logger.info(`Streaming the extraction of the CodeQL bundle.`);
95-
96-
const toolsInstallStart = performance.now();
97-
const extractedBundlePath = await downloadAndExtractZstdWithStreaming(
98-
codeqlURL,
99-
authorization,
100-
headers,
101-
tarVersion!,
102-
logger,
103-
);
92+
try {
93+
if (compressionMethod === "zstd" && process.platform === "linux") {
94+
logger.info(`Streaming the extraction of the CodeQL bundle.`);
10495

105-
const combinedDurationMs = Math.round(
106-
performance.now() - toolsInstallStart,
107-
);
108-
logger.info(
109-
`Finished downloading and extracting CodeQL bundle to ${extractedBundlePath} (${formatDuration(
110-
combinedDurationMs,
111-
)}).`,
96+
const toolsInstallStart = performance.now();
97+
const extractedBundlePath = await downloadAndExtractZstdWithStreaming(
98+
codeqlURL,
99+
authorization,
100+
headers,
101+
tarVersion!,
102+
logger,
103+
);
104+
105+
const combinedDurationMs = Math.round(
106+
performance.now() - toolsInstallStart,
107+
);
108+
logger.info(
109+
`Finished downloading and extracting CodeQL bundle to ${extractedBundlePath} (${formatDuration(
110+
combinedDurationMs,
111+
)}).`,
112+
);
113+
114+
return {
115+
extractedBundlePath,
116+
statusReport: {
117+
compressionMethod,
118+
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
119+
...makeStreamedToolsDownloadDurations(combinedDurationMs),
120+
},
121+
};
122+
}
123+
} catch (e) {
124+
core.warning(
125+
`Failed to download and extract CodeQL bundle using streaming. Falling back to downloading the bundle before extracting.`,
112126
);
113-
114-
return {
115-
extractedBundlePath,
116-
statusReport: {
117-
compressionMethod,
118-
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
119-
...makeStreamedToolsDownloadDurations(combinedDurationMs),
120-
},
121-
};
127+
core.warning(getErrorMessage(e));
122128
}
123129

124130
const dest = path.join(tempDir, uuidV4());

0 commit comments

Comments
 (0)