Fall back to gzip if zstd fails
This commit is contained in:
parent
662c71aa9e
commit
4d015b8cba
6 changed files with 82 additions and 33 deletions
27
lib/setup-codeql.js
generated
27
lib/setup-codeql.js
generated
|
|
@ -198,7 +198,7 @@ async function findOverridingToolsInCache(humanReadableVersion, logger) {
|
|||
}
|
||||
return undefined;
|
||||
}
|
||||
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, zstdAvailability, features, logger) {
|
||||
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, tarSupportsZstd, features, logger) {
|
||||
if (toolsInput &&
|
||||
!CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput) &&
|
||||
!toolsInput.startsWith("http")) {
|
||||
|
|
@ -341,7 +341,7 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
|
|||
}
|
||||
if (!url) {
|
||||
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, cliVersion !== undefined &&
|
||||
(await useZstdBundle(cliVersion, features, zstdAvailability)), logger);
|
||||
(await useZstdBundle(cliVersion, features, tarSupportsZstd)), logger);
|
||||
}
|
||||
if (cliVersion) {
|
||||
logger.info(`Using CodeQL CLI version ${cliVersion} sourced from ${url}.`);
|
||||
|
|
@ -479,7 +479,20 @@ function getCanonicalToolcacheVersion(cliVersion, bundleVersion, logger) {
|
|||
*/
|
||||
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger) {
|
||||
const zstdAvailability = await tar.isZstdAvailable(logger);
|
||||
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, zstdAvailability, features, logger);
|
||||
// If we think the installed version of tar supports zstd, try to use zstd,
|
||||
// but be prepared to fall back to gzip in case we were wrong.
|
||||
if (zstdAvailability.available) {
|
||||
try {
|
||||
return await setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, zstdAvailability, true);
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to set up CodeQL tools with zstd. Falling back to gzipped version. Error: ${util.getErrorMessage(e)}`);
|
||||
}
|
||||
}
|
||||
return await setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, zstdAvailability, false);
|
||||
}
|
||||
async function setupCodeQLBundleWithCompressionMethod(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, zstdAvailability, useTarIfAvailable) {
|
||||
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useTarIfAvailable, features, logger);
|
||||
let codeqlFolder;
|
||||
let toolsVersion = source.toolsVersion;
|
||||
let toolsDownloadStatusReport;
|
||||
|
|
@ -538,9 +551,9 @@ function sanitizeUrlForStatusReport(url) {
|
|||
? url
|
||||
: "sanitized-value";
|
||||
}
|
||||
async function useZstdBundle(cliVersion, features, zstdAvailability) {
|
||||
return (semver.gte(cliVersion, "2.19.0") &&
|
||||
!!(await features.getValue(feature_flags_1.Feature.ZstdBundle)) &&
|
||||
zstdAvailability.available);
|
||||
async function useZstdBundle(cliVersion, features, tarSupportsZstd) {
|
||||
return (tarSupportsZstd &&
|
||||
semver.gte(cliVersion, "2.19.0") &&
|
||||
!!(await features.getValue(feature_flags_1.Feature.ZstdBundle)));
|
||||
}
|
||||
//# sourceMappingURL=setup-codeql.js.map
|
||||
File diff suppressed because one or more lines are too long
11
lib/setup-codeql.test.js
generated
11
lib/setup-codeql.test.js
generated
|
|
@ -79,7 +79,7 @@ ava_1.default.beforeEach(() => {
|
|||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const tagName = "codeql-bundle-v1.2.3";
|
||||
(0, testing_utils_1.mockBundleDownloadApi)({ tagName });
|
||||
const source = await setupCodeql.getCodeQLSource(`https://github.com/github/codeql-action/releases/download/${tagName}/codeql-bundle-linux64.tar.gz`, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, getStubZstdAvailability(), (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||
const source = await setupCodeql.getCodeQLSource(`https://github.com/github/codeql-action/releases/download/${tagName}/codeql-bundle-linux64.tar.gz`, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, false, (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||
t.is(source.sourceType, "download");
|
||||
t.is(source["cliVersion"], "1.2.3");
|
||||
});
|
||||
|
|
@ -87,7 +87,7 @@ ava_1.default.beforeEach(() => {
|
|||
(0, ava_1.default)("getCodeQLSource correctly returns bundled CLI version when tools == linked", async (t) => {
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const source = await setupCodeql.getCodeQLSource("linked", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, getStubZstdAvailability(), (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||
const source = await setupCodeql.getCodeQLSource("linked", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, false, (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||
t.is(source.toolsVersion, testing_utils_1.LINKED_CLI_VERSION.cliVersion);
|
||||
t.is(source.sourceType, "download");
|
||||
});
|
||||
|
|
@ -97,7 +97,7 @@ ava_1.default.beforeEach(() => {
|
|||
const logger = (0, testing_utils_1.getRecordingLogger)(loggedMessages);
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const source = await setupCodeql.getCodeQLSource("latest", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, getStubZstdAvailability(), (0, testing_utils_1.createFeatures)([]), logger);
|
||||
const source = await setupCodeql.getCodeQLSource("latest", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, false, (0, testing_utils_1.createFeatures)([]), logger);
|
||||
// First, ensure that the CLI version is the linked version, so that backwards
|
||||
// compatibility is maintained.
|
||||
t.is(source.toolsVersion, testing_utils_1.LINKED_CLI_VERSION.cliVersion);
|
||||
|
|
@ -164,9 +164,4 @@ ava_1.default.beforeEach(() => {
|
|||
msg.message.includes(expected_message)));
|
||||
});
|
||||
});
|
||||
function getStubZstdAvailability() {
|
||||
return {
|
||||
available: false,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=setup-codeql.test.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -6,7 +6,6 @@ import * as sinon from "sinon";
|
|||
import * as actionsUtil from "./actions-util";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import * as setupCodeql from "./setup-codeql";
|
||||
import { ZstdAvailability } from "./tar";
|
||||
import {
|
||||
LINKED_CLI_VERSION,
|
||||
LoggedMessage,
|
||||
|
|
@ -91,7 +90,7 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
|
|||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
getStubZstdAvailability(),
|
||||
false,
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
|
@ -109,7 +108,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == linked
|
|||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
getStubZstdAvailability(),
|
||||
false,
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
|
@ -130,7 +129,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == latest
|
|||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
getStubZstdAvailability(),
|
||||
false,
|
||||
createFeatures([]),
|
||||
logger,
|
||||
);
|
||||
|
|
@ -246,9 +245,3 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to dow
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
function getStubZstdAvailability(): ZstdAvailability {
|
||||
return {
|
||||
available: false,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ export async function getCodeQLSource(
|
|||
defaultCliVersion: CodeQLDefaultVersionInfo,
|
||||
apiDetails: api.GitHubApiDetails,
|
||||
variant: util.GitHubVariant,
|
||||
zstdAvailability: tar.ZstdAvailability,
|
||||
tarSupportsZstd: boolean,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<CodeQLToolsSource> {
|
||||
|
|
@ -441,7 +441,7 @@ export async function getCodeQLSource(
|
|||
tagName!,
|
||||
apiDetails,
|
||||
cliVersion !== undefined &&
|
||||
(await useZstdBundle(cliVersion, features, zstdAvailability)),
|
||||
(await useZstdBundle(cliVersion, features, tarSupportsZstd)),
|
||||
logger,
|
||||
);
|
||||
}
|
||||
|
|
@ -673,12 +673,60 @@ export async function setupCodeQLBundle(
|
|||
): Promise<SetupCodeQLResult> {
|
||||
const zstdAvailability = await tar.isZstdAvailable(logger);
|
||||
|
||||
// If we think the installed version of tar supports zstd, try to use zstd,
|
||||
// but be prepared to fall back to gzip in case we were wrong.
|
||||
if (zstdAvailability.available) {
|
||||
try {
|
||||
return await setupCodeQLBundleWithCompressionMethod(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
tempDir,
|
||||
variant,
|
||||
defaultCliVersion,
|
||||
features,
|
||||
logger,
|
||||
zstdAvailability,
|
||||
true,
|
||||
);
|
||||
} catch (e) {
|
||||
logger.warning(
|
||||
`Failed to set up CodeQL tools with zstd. Falling back to gzipped version. Error: ${util.getErrorMessage(
|
||||
e,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return await setupCodeQLBundleWithCompressionMethod(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
tempDir,
|
||||
variant,
|
||||
defaultCliVersion,
|
||||
features,
|
||||
logger,
|
||||
zstdAvailability,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
async function setupCodeQLBundleWithCompressionMethod(
|
||||
toolsInput: string | undefined,
|
||||
apiDetails: api.GitHubApiDetails,
|
||||
tempDir: string,
|
||||
variant: util.GitHubVariant,
|
||||
defaultCliVersion: CodeQLDefaultVersionInfo,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
zstdAvailability: tar.ZstdAvailability,
|
||||
useTarIfAvailable: boolean,
|
||||
) {
|
||||
const source = await getCodeQLSource(
|
||||
toolsInput,
|
||||
defaultCliVersion,
|
||||
apiDetails,
|
||||
variant,
|
||||
zstdAvailability,
|
||||
useTarIfAvailable,
|
||||
features,
|
||||
logger,
|
||||
);
|
||||
|
|
@ -757,11 +805,11 @@ function sanitizeUrlForStatusReport(url: string): string {
|
|||
async function useZstdBundle(
|
||||
cliVersion: string,
|
||||
features: FeatureEnablement,
|
||||
zstdAvailability: tar.ZstdAvailability,
|
||||
tarSupportsZstd: boolean,
|
||||
): Promise<boolean> {
|
||||
return (
|
||||
tarSupportsZstd &&
|
||||
semver.gte(cliVersion, "2.19.0") &&
|
||||
!!(await features.getValue(Feature.ZstdBundle)) &&
|
||||
zstdAvailability.available
|
||||
!!(await features.getValue(Feature.ZstdBundle))
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue