Fall back to gzipped bundles

This commit is contained in:
Henry Mercer
2024-08-13 13:55:19 +01:00
parent 8e444360fd
commit d277fb19ed
9 changed files with 108 additions and 46 deletions
+52 -1
View File
@@ -327,6 +327,56 @@ export const CODEQL_VERSION_SUBLANGUAGE_FILE_COVERAGE = "2.15.0";
*/
const CODEQL_VERSION_INCLUDE_QUERY_HELP = "2.15.2";
async function setupCodeQLBundlePreferringZstd(
toolsInput: string | undefined,
apiDetails: api.GitHubApiDetails,
tempDir: string,
variant: util.GitHubVariant,
defaultCliVersion: CodeQLDefaultVersionInfo,
features: FeatureEnablement,
logger: Logger,
): Promise<setupCodeql.SetupCodeQLResult> {
let zstdError: unknown = undefined;
if (await features.getValue(Feature.ZstdBundle)) {
try {
return await setupCodeql.setupCodeQLBundle(
toolsInput,
apiDetails,
tempDir,
variant,
defaultCliVersion,
true,
logger,
);
} catch (e) {
logger.info(
"Failed to set up bundle compressed using zstd, falling back to bundle compressed using gzip.",
);
zstdError = e;
}
}
const result = await setupCodeql.setupCodeQLBundle(
toolsInput,
apiDetails,
tempDir,
variant,
defaultCliVersion,
false,
logger,
);
if (zstdError) {
result.toolsDownloadStatusReport = Object.assign(
{},
result.toolsDownloadStatusReport,
{ zstdError: wrapError(zstdError).message },
);
}
return result;
}
/**
* Set up CodeQL CLI access.
*
@@ -361,7 +411,7 @@ export async function setupCodeQL(
toolsDownloadStatusReport,
toolsSource,
toolsVersion,
} = await setupCodeql.setupCodeQLBundle(
} = await setupCodeQLBundlePreferringZstd(
toolsInput,
apiDetails,
tempDir,
@@ -370,6 +420,7 @@ export async function setupCodeQL(
features,
logger,
);
let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
if (process.platform === "win32") {
codeqlCmd += ".exe";
+5 -6
View File
@@ -11,7 +11,6 @@ import {
LoggedMessage,
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
createFeatures,
getRecordingLogger,
mockBundleDownloadApi,
setupActionsVars,
@@ -90,7 +89,7 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
GitHubVariant.DOTCOM,
createFeatures([]),
false,
getRunnerLogger(true),
);
@@ -107,7 +106,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == linked
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
GitHubVariant.DOTCOM,
createFeatures([]),
false,
getRunnerLogger(true),
);
@@ -127,7 +126,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == latest
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
GitHubVariant.DOTCOM,
createFeatures([]),
false,
logger,
);
@@ -172,7 +171,7 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to use
"tmp/codeql_action_test/",
GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
false,
logger,
);
@@ -219,7 +218,7 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to dow
"tmp/codeql_action_test/",
GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
false,
logger,
);
+17 -21
View File
@@ -15,11 +15,7 @@ import * as api from "./api-client";
// creation scripts. Ensure that any changes to the format of this file are compatible with both of
// these dependents.
import * as defaults from "./defaults.json";
import {
CodeQLDefaultVersionInfo,
Feature,
FeatureEnablement,
} from "./feature-flags";
import { CodeQLDefaultVersionInfo } from "./feature-flags";
import { Logger } from "./logging";
import * as util from "./util";
import { isGoodVersion } from "./util";
@@ -49,10 +45,8 @@ function getCodeQLBundleBaseName(): string {
return `codeql-bundle-${platform}`;
}
async function getCodeQLBundleName(
features: FeatureEnablement,
): Promise<string> {
if (await features.getValue(Feature.ZstdBundle)) {
async function getCodeQLBundleName(useStdBundle: boolean): Promise<string> {
if (useStdBundle) {
return `${getCodeQLBundleBaseName()}.tar.zst`;
}
return `${getCodeQLBundleBaseName()}.tar.gz`;
@@ -75,7 +69,7 @@ export function getCodeQLActionRepository(logger: Logger): string {
async function getCodeQLBundleDownloadURL(
tagName: string,
apiDetails: api.GitHubApiDetails,
features: FeatureEnablement,
useStdBundle: boolean,
logger: Logger,
): Promise<string> {
const codeQLActionRepository = getCodeQLActionRepository(logger);
@@ -94,7 +88,7 @@ async function getCodeQLBundleDownloadURL(
return !self.slice(0, index).some((other) => deepEqual(source, other));
},
);
const codeQLBundleName = await getCodeQLBundleName(features);
const codeQLBundleName = await getCodeQLBundleName(useStdBundle);
for (const downloadSource of uniqueDownloadSources) {
const [apiURL, repository] = downloadSource;
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
@@ -244,7 +238,7 @@ export async function getCodeQLSource(
defaultCliVersion: CodeQLDefaultVersionInfo,
apiDetails: api.GitHubApiDetails,
variant: util.GitHubVariant,
features: FeatureEnablement,
useStdBundle: boolean,
logger: Logger,
): Promise<CodeQLToolsSource> {
if (
@@ -441,7 +435,7 @@ export async function getCodeQLSource(
url = await getCodeQLBundleDownloadURL(
tagName!,
apiDetails,
features,
useStdBundle,
logger,
);
}
@@ -639,6 +633,13 @@ function getCanonicalToolcacheVersion(
return cliVersion;
}
export interface SetupCodeQLResult {
codeqlFolder: string;
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
toolsSource: ToolsSource;
toolsVersion: string;
}
/**
* Obtains the CodeQL bundle, installs it in the toolcache if appropriate, and extracts it.
*
@@ -658,20 +659,15 @@ export async function setupCodeQLBundle(
tempDir: string,
variant: util.GitHubVariant,
defaultCliVersion: CodeQLDefaultVersionInfo,
features: FeatureEnablement,
useStdBundle: boolean,
logger: Logger,
): Promise<{
codeqlFolder: string;
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
toolsSource: ToolsSource;
toolsVersion: string;
}> {
): Promise<SetupCodeQLResult> {
const source = await getCodeQLSource(
toolsInput,
defaultCliVersion,
apiDetails,
variant,
features,
useStdBundle,
logger,
);