Use zstd bundle by default when feature flag enabled

This commit is contained in:
Henry Mercer
2024-09-23 19:00:30 +01:00
parent e7309d2b5c
commit ac3fca3e9f
24 changed files with 116 additions and 45 deletions

View File

@@ -68,6 +68,8 @@ async function installIntoToolcache({
cliVersion !== undefined
? { cliVersion, tagName }
: SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -127,6 +129,8 @@ test("downloads and caches explicitly requested bundles that aren't in the toolc
tmpDir,
util.GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -156,6 +160,8 @@ test("caches semantically versioned bundles using their semantic version number"
tmpDir,
util.GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -189,6 +195,8 @@ test("downloads an explicitly requested bundle even if a different version is ca
tmpDir,
util.GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -233,6 +241,8 @@ for (const {
tmpDir,
util.GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -271,6 +281,8 @@ for (const toolcacheVersion of [
tmpDir,
util.GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -301,6 +313,8 @@ test(`uses a cached bundle when no tools input is given on GHES`, async (t) => {
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
},
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -335,6 +349,8 @@ test(`downloads bundle if only an unpinned version is cached on GHES`, async (t)
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
},
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -368,6 +384,8 @@ test('downloads bundle if "latest" tools specified but not cached', async (t) =>
tmpDir,
util.GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);
@@ -404,6 +422,8 @@ test("bundle URL from another repo is cached as 0.0.0-bundleVersion", async (t)
tmpDir,
util.GitHubVariant.DOTCOM,
SAMPLE_DEFAULT_CLI_VERSION,
createFeatures([]),
getRunnerLogger(true),
false,
);

View File

@@ -351,6 +351,7 @@ export async function setupCodeQL(
tempDir: string,
variant: util.GitHubVariant,
defaultCliVersion: CodeQLDefaultVersionInfo,
features: FeatureEnablement,
logger: Logger,
checkVersion: boolean,
): Promise<{
@@ -371,6 +372,7 @@ export async function setupCodeQL(
tempDir,
variant,
defaultCliVersion,
features,
logger,
);

View File

@@ -499,3 +499,13 @@ class GitHubFeatureFlags {
}
}
}
export async function useZstdBundle(
cliVersion: string,
features: FeatureEnablement,
): Promise<boolean> {
return (
semver.gte(cliVersion, "2.19.0") &&
!!(await features.getValue(Feature.ZstdBundle))
);
}

View File

@@ -308,6 +308,7 @@ async function run() {
getTemporaryDirectory(),
gitHubVersion.type,
codeQLDefaultVersionInfo,
features,
logger,
);
codeql = initCodeQLResult.codeql;

View File

@@ -8,7 +8,7 @@ import { getOptionalInput, isSelfHostedRunner } from "./actions-util";
import { GitHubApiCombinedDetails, GitHubApiDetails } from "./api-client";
import { CodeQL, setupCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { CodeQLDefaultVersionInfo } from "./feature-flags";
import { CodeQLDefaultVersionInfo, FeatureEnablement } from "./feature-flags";
import { Language, isScannedLanguage } from "./languages";
import { Logger } from "./logging";
import { ToolsDownloadStatusReport, ToolsSource } from "./setup-codeql";
@@ -22,6 +22,7 @@ export async function initCodeQL(
tempDir: string,
variant: util.GitHubVariant,
defaultCliVersion: CodeQLDefaultVersionInfo,
features: FeatureEnablement,
logger: Logger,
): Promise<{
codeql: CodeQL;
@@ -37,6 +38,7 @@ export async function initCodeQL(
tempDir,
variant,
defaultCliVersion,
features,
logger,
true,
);

View File

@@ -11,6 +11,7 @@ import {
LoggedMessage,
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
createFeatures,
getRecordingLogger,
mockBundleDownloadApi,
setupActionsVars,
@@ -89,6 +90,7 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
GitHubVariant.DOTCOM,
createFeatures([]),
getRunnerLogger(true),
);
@@ -105,6 +107,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == linked
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
GitHubVariant.DOTCOM,
createFeatures([]),
getRunnerLogger(true),
);
@@ -124,6 +127,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == latest
SAMPLE_DEFAULT_CLI_VERSION,
SAMPLE_DOTCOM_API_DETAILS,
GitHubVariant.DOTCOM,
createFeatures([]),
logger,
);
@@ -170,6 +174,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([]),
logger,
);
@@ -218,6 +223,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([]),
logger,
);

View File

@@ -15,7 +15,11 @@ 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 } from "./feature-flags";
import {
CodeQLDefaultVersionInfo,
FeatureEnablement,
useZstdBundle,
} from "./feature-flags";
import { Logger } from "./logging";
import * as tar from "./tar";
import * as util from "./util";
@@ -32,7 +36,13 @@ export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
const CODEQL_BUNDLE_VERSION_ALIAS: string[] = ["linked", "latest"];
function getCodeQLBundleName(): string {
function getCodeQLBundleExtension(useZstd: boolean): string {
return useZstd ? ".tar.zst" : ".tar.gz";
}
function getCodeQLBundleName(useZstd: boolean): string {
const extension = getCodeQLBundleExtension(useZstd);
let platform: string;
if (process.platform === "win32") {
platform = "win64";
@@ -41,9 +51,9 @@ function getCodeQLBundleName(): string {
} else if (process.platform === "darwin") {
platform = "osx64";
} else {
return "codeql-bundle.tar.gz";
return `codeql-bundle${extension}`;
}
return `codeql-bundle-${platform}.tar.gz`;
return `codeql-bundle-${platform}${extension}`;
}
export function getCodeQLActionRepository(logger: Logger): string {
@@ -63,6 +73,7 @@ export function getCodeQLActionRepository(logger: Logger): string {
async function getCodeQLBundleDownloadURL(
tagName: string,
apiDetails: api.GitHubApiDetails,
useZstd: boolean,
logger: Logger,
): Promise<string> {
const codeQLActionRepository = getCodeQLActionRepository(logger);
@@ -81,7 +92,7 @@ async function getCodeQLBundleDownloadURL(
return !self.slice(0, index).some((other) => deepEqual(source, other));
},
);
const codeQLBundleName = getCodeQLBundleName();
const codeQLBundleName = getCodeQLBundleName(useZstd);
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.
@@ -231,6 +242,7 @@ export async function getCodeQLSource(
defaultCliVersion: CodeQLDefaultVersionInfo,
apiDetails: api.GitHubApiDetails,
variant: util.GitHubVariant,
features: FeatureEnablement,
logger: Logger,
): Promise<CodeQLToolsSource> {
if (
@@ -424,7 +436,12 @@ export async function getCodeQLSource(
}
if (!url) {
url = await getCodeQLBundleDownloadURL(tagName!, apiDetails, logger);
url = await getCodeQLBundleDownloadURL(
tagName!,
apiDetails,
cliVersion !== undefined && (await useZstdBundle(cliVersion, features)),
logger,
);
}
if (cliVersion) {
@@ -648,6 +665,7 @@ export async function setupCodeQLBundle(
tempDir: string,
variant: util.GitHubVariant,
defaultCliVersion: CodeQLDefaultVersionInfo,
features: FeatureEnablement,
logger: Logger,
): Promise<SetupCodeQLResult> {
const source = await getCodeQLSource(
@@ -655,6 +673,7 @@ export async function setupCodeQLBundle(
defaultCliVersion,
apiDetails,
variant,
features,
logger,
);

View File

@@ -221,6 +221,7 @@ async function combineSarifFilesUsingCLI(
tempDir,
gitHubVersion.type,
codeQLDefaultVersionInfo,
features,
logger,
);