mirror of
https://github.com/github/codeql-action.git
synced 2026-05-08 06:40:19 +00:00
Fall back to gzipped bundles
This commit is contained in:
Generated
+18
-1
@@ -105,6 +105,23 @@ exports.CODEQL_VERSION_SUBLANGUAGE_FILE_COVERAGE = "2.15.0";
|
||||
* Versions 2.15.2+ of the CodeQL CLI support the `--sarif-include-query-help` option.
|
||||
*/
|
||||
const CODEQL_VERSION_INCLUDE_QUERY_HELP = "2.15.2";
|
||||
async function setupCodeQLBundlePreferringZstd(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger) {
|
||||
let zstdError = undefined;
|
||||
if (await features.getValue(feature_flags_1.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: (0, util_1.wrapError)(zstdError).message });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Set up CodeQL CLI access.
|
||||
*
|
||||
@@ -120,7 +137,7 @@ const CODEQL_VERSION_INCLUDE_QUERY_HELP = "2.15.2";
|
||||
*/
|
||||
async function setupCodeQL(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger, checkVersion) {
|
||||
try {
|
||||
const { codeqlFolder, toolsDownloadStatusReport, toolsSource, toolsVersion, } = await setupCodeql.setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger);
|
||||
const { codeqlFolder, toolsDownloadStatusReport, toolsSource, toolsVersion, } = await setupCodeQLBundlePreferringZstd(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger);
|
||||
let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
|
||||
if (process.platform === "win32") {
|
||||
codeqlCmd += ".exe";
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Generated
+8
-9
@@ -48,7 +48,6 @@ const api = __importStar(require("./api-client"));
|
||||
// creation scripts. Ensure that any changes to the format of this file are compatible with both of
|
||||
// these dependents.
|
||||
const defaults = __importStar(require("./defaults.json"));
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
const util = __importStar(require("./util"));
|
||||
const util_1 = require("./util");
|
||||
var ToolsSource;
|
||||
@@ -76,8 +75,8 @@ function getCodeQLBundleBaseName() {
|
||||
}
|
||||
return `codeql-bundle-${platform}`;
|
||||
}
|
||||
async function getCodeQLBundleName(features) {
|
||||
if (await features.getValue(feature_flags_1.Feature.ZstdBundle)) {
|
||||
async function getCodeQLBundleName(useStdBundle) {
|
||||
if (useStdBundle) {
|
||||
return `${getCodeQLBundleBaseName()}.tar.zst`;
|
||||
}
|
||||
return `${getCodeQLBundleBaseName()}.tar.gz`;
|
||||
@@ -92,7 +91,7 @@ function getCodeQLActionRepository(logger) {
|
||||
}
|
||||
return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY");
|
||||
}
|
||||
async function getCodeQLBundleDownloadURL(tagName, apiDetails, features, logger) {
|
||||
async function getCodeQLBundleDownloadURL(tagName, apiDetails, useStdBundle, logger) {
|
||||
const codeQLActionRepository = getCodeQLActionRepository(logger);
|
||||
const potentialDownloadSources = [
|
||||
// This GitHub instance, and this Action.
|
||||
@@ -107,7 +106,7 @@ async function getCodeQLBundleDownloadURL(tagName, apiDetails, features, logger)
|
||||
const uniqueDownloadSources = potentialDownloadSources.filter((source, index, self) => {
|
||||
return !self.slice(0, index).some((other) => (0, fast_deep_equal_1.default)(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.
|
||||
@@ -199,7 +198,7 @@ async function findOverridingToolsInCache(humanReadableVersion, logger) {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, features, logger) {
|
||||
async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useStdBundle, logger) {
|
||||
if (toolsInput &&
|
||||
!CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput) &&
|
||||
!toolsInput.startsWith("http")) {
|
||||
@@ -341,7 +340,7 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, varian
|
||||
}
|
||||
}
|
||||
if (!url) {
|
||||
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, features, logger);
|
||||
url = await getCodeQLBundleDownloadURL(tagName, apiDetails, useStdBundle, logger);
|
||||
}
|
||||
if (cliVersion) {
|
||||
logger.info(`Using CodeQL CLI version ${cliVersion} sourced from ${url}.`);
|
||||
@@ -480,8 +479,8 @@ function getCanonicalToolcacheVersion(cliVersion, bundleVersion, logger) {
|
||||
* version requirement. Must be set to true outside tests.
|
||||
* @returns the path to the extracted bundle, and the version of the tools
|
||||
*/
|
||||
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, features, logger) {
|
||||
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, features, logger);
|
||||
async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, useStdBundle, logger) {
|
||||
const source = await getCodeQLSource(toolsInput, defaultCliVersion, apiDetails, variant, useStdBundle, logger);
|
||||
let codeqlFolder;
|
||||
let toolsVersion = source.toolsVersion;
|
||||
let toolsDownloadStatusReport;
|
||||
|
||||
File diff suppressed because one or more lines are too long
Generated
+5
-5
@@ -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, (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, 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, (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, 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, (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, 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);
|
||||
@@ -123,7 +123,7 @@ ava_1.default.beforeEach(() => {
|
||||
});
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const result = await setupCodeql.setupCodeQLBundle("linked", testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, "tmp/codeql_action_test/", util_1.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, testing_utils_1.createFeatures)([]), logger);
|
||||
const result = await setupCodeql.setupCodeQLBundle("linked", testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, "tmp/codeql_action_test/", util_1.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, false, logger);
|
||||
// Basic sanity check that the version we got back is indeed
|
||||
// the linked (default) CLI version.
|
||||
t.is(result.toolsVersion, testing_utils_1.LINKED_CLI_VERSION.cliVersion);
|
||||
@@ -150,7 +150,7 @@ ava_1.default.beforeEach(() => {
|
||||
});
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const result = await setupCodeql.setupCodeQLBundle(bundleUrl, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, "tmp/codeql_action_test/", util_1.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, testing_utils_1.createFeatures)([]), logger);
|
||||
const result = await setupCodeql.setupCodeQLBundle(bundleUrl, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, "tmp/codeql_action_test/", util_1.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, false, logger);
|
||||
// Basic sanity check that the version we got back is indeed the version that the
|
||||
// bundle contains..
|
||||
t.is(result.toolsVersion, expectedVersion);
|
||||
|
||||
File diff suppressed because one or more lines are too long
+52
-1
@@ -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";
|
||||
|
||||
@@ -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
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user