mirror of
https://github.com/github/codeql-action.git
synced 2026-10-30 01:27:22 +00:00
Determine zstd availability earlier on to simplify log
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
import { Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import * as setupCodeql from "./setup-codeql";
|
||||
import { ZstdAvailability } from "./tar";
|
||||
import { ToolsFeature, isSupportedToolsFeature } from "./tools-features";
|
||||
import { shouldEnableIndirectTracing } from "./tracer-config";
|
||||
import * as util from "./util";
|
||||
@@ -359,6 +360,7 @@ export async function setupCodeQL(
|
||||
toolsDownloadStatusReport?: setupCodeql.ToolsDownloadStatusReport;
|
||||
toolsSource: setupCodeql.ToolsSource;
|
||||
toolsVersion: string;
|
||||
zstdAvailability: ZstdAvailability;
|
||||
}> {
|
||||
try {
|
||||
const {
|
||||
@@ -366,6 +368,7 @@ export async function setupCodeQL(
|
||||
toolsDownloadStatusReport,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
zstdAvailability,
|
||||
} = await setupCodeql.setupCodeQLBundle(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
@@ -397,6 +400,7 @@ export async function setupCodeQL(
|
||||
toolsDownloadStatusReport,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
zstdAvailability,
|
||||
};
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
getActionsStatus,
|
||||
sendStatusReport,
|
||||
} from "./status-report";
|
||||
import { isZstdAvailable } from "./tar";
|
||||
import { ZstdAvailability } from "./tar";
|
||||
import { ToolsFeature } from "./tools-features";
|
||||
import { getTotalCacheSize } from "./trap-caching";
|
||||
import {
|
||||
@@ -255,6 +255,7 @@ async function run() {
|
||||
let toolsFeatureFlagsValid: boolean | undefined;
|
||||
let toolsSource: ToolsSource;
|
||||
let toolsVersion: string;
|
||||
let zstdAvailability: ZstdAvailability | undefined;
|
||||
|
||||
const apiDetails = {
|
||||
auth: getRequiredInput("token"),
|
||||
@@ -315,6 +316,7 @@ async function run() {
|
||||
toolsDownloadStatusReport = initCodeQLResult.toolsDownloadStatusReport;
|
||||
toolsVersion = initCodeQLResult.toolsVersion;
|
||||
toolsSource = initCodeQLResult.toolsSource;
|
||||
zstdAvailability = initCodeQLResult.zstdAvailability;
|
||||
|
||||
core.startGroup("Validating workflow");
|
||||
if ((await validateWorkflow(codeql, logger)) === undefined) {
|
||||
@@ -378,7 +380,9 @@ async function run() {
|
||||
try {
|
||||
cleanupDatabaseClusterDirectory(config, logger);
|
||||
|
||||
await logZstdAvailability(config, logger);
|
||||
if (zstdAvailability) {
|
||||
await recordZstdAvailability(config, zstdAvailability);
|
||||
}
|
||||
|
||||
// Log CodeQL download telemetry, if appropriate
|
||||
if (toolsDownloadStatusReport) {
|
||||
@@ -675,9 +679,10 @@ function getTrapCachingEnabled(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
async function logZstdAvailability(config: configUtils.Config, logger: Logger) {
|
||||
// Log zstd availability
|
||||
const zstdAvailableResult = await isZstdAvailable(logger);
|
||||
async function recordZstdAvailability(
|
||||
config: configUtils.Config,
|
||||
zstdAvailability: ZstdAvailability,
|
||||
) {
|
||||
addDiagnostic(
|
||||
config,
|
||||
// Arbitrarily choose the first language. We could also choose all languages, but that
|
||||
@@ -687,7 +692,7 @@ async function logZstdAvailability(config: configUtils.Config, logger: Logger) {
|
||||
"codeql-action/zstd-availability",
|
||||
"Zstandard availability",
|
||||
{
|
||||
attributes: zstdAvailableResult,
|
||||
attributes: zstdAvailability,
|
||||
visibility: {
|
||||
cliSummaryTable: false,
|
||||
statusPage: false,
|
||||
|
||||
37
src/init.ts
37
src/init.ts
@@ -12,6 +12,7 @@ import { CodeQLDefaultVersionInfo, FeatureEnablement } from "./feature-flags";
|
||||
import { Language, isScannedLanguage } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { ToolsDownloadStatusReport, ToolsSource } from "./setup-codeql";
|
||||
import { ZstdAvailability } from "./tar";
|
||||
import { ToolsFeature } from "./tools-features";
|
||||
import { TracerConfig, getCombinedTracerConfig } from "./tracer-config";
|
||||
import * as util from "./util";
|
||||
@@ -29,22 +30,34 @@ export async function initCodeQL(
|
||||
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
|
||||
toolsSource: ToolsSource;
|
||||
toolsVersion: string;
|
||||
zstdAvailability: ZstdAvailability;
|
||||
}> {
|
||||
logger.startGroup("Setup CodeQL tools");
|
||||
const { codeql, toolsDownloadStatusReport, toolsSource, toolsVersion } =
|
||||
await setupCodeQL(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
tempDir,
|
||||
variant,
|
||||
defaultCliVersion,
|
||||
features,
|
||||
logger,
|
||||
true,
|
||||
);
|
||||
const {
|
||||
codeql,
|
||||
toolsDownloadStatusReport,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
zstdAvailability,
|
||||
} = await setupCodeQL(
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
tempDir,
|
||||
variant,
|
||||
defaultCliVersion,
|
||||
features,
|
||||
logger,
|
||||
true,
|
||||
);
|
||||
await codeql.printVersion();
|
||||
logger.endGroup();
|
||||
return { codeql, toolsDownloadStatusReport, toolsSource, toolsVersion };
|
||||
return {
|
||||
codeql,
|
||||
toolsDownloadStatusReport,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
zstdAvailability,
|
||||
};
|
||||
}
|
||||
|
||||
export async function initConfig(
|
||||
|
||||
@@ -6,6 +6,7 @@ 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,
|
||||
@@ -90,6 +91,7 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
getStubZstdAvailability(),
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
@@ -107,6 +109,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == linked
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
getStubZstdAvailability(),
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
@@ -127,6 +130,7 @@ test("getCodeQLSource correctly returns bundled CLI version when tools == latest
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
getStubZstdAvailability(),
|
||||
createFeatures([]),
|
||||
logger,
|
||||
);
|
||||
@@ -242,3 +246,9 @@ test("setupCodeQLBundle logs the CodeQL CLI version being used when asked to dow
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function getStubZstdAvailability(): ZstdAvailability {
|
||||
return {
|
||||
available: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -242,6 +242,7 @@ export async function getCodeQLSource(
|
||||
defaultCliVersion: CodeQLDefaultVersionInfo,
|
||||
apiDetails: api.GitHubApiDetails,
|
||||
variant: util.GitHubVariant,
|
||||
zstdAvailability: tar.ZstdAvailability,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<CodeQLToolsSource> {
|
||||
@@ -440,7 +441,7 @@ export async function getCodeQLSource(
|
||||
tagName!,
|
||||
apiDetails,
|
||||
cliVersion !== undefined &&
|
||||
(await useZstdBundle(cliVersion, features, logger)),
|
||||
(await useZstdBundle(cliVersion, features, zstdAvailability)),
|
||||
logger,
|
||||
);
|
||||
}
|
||||
@@ -653,6 +654,7 @@ export interface SetupCodeQLResult {
|
||||
toolsDownloadStatusReport?: ToolsDownloadStatusReport;
|
||||
toolsSource: ToolsSource;
|
||||
toolsVersion: string;
|
||||
zstdAvailability: tar.ZstdAvailability;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -669,11 +671,14 @@ export async function setupCodeQLBundle(
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<SetupCodeQLResult> {
|
||||
const zstdAvailability = await tar.isZstdAvailable(logger);
|
||||
|
||||
const source = await getCodeQLSource(
|
||||
toolsInput,
|
||||
defaultCliVersion,
|
||||
apiDetails,
|
||||
variant,
|
||||
zstdAvailability,
|
||||
features,
|
||||
logger,
|
||||
);
|
||||
@@ -714,7 +719,13 @@ export async function setupCodeQLBundle(
|
||||
default:
|
||||
util.assertNever(source);
|
||||
}
|
||||
return { codeqlFolder, toolsDownloadStatusReport, toolsSource, toolsVersion };
|
||||
return {
|
||||
codeqlFolder,
|
||||
toolsDownloadStatusReport,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
zstdAvailability,
|
||||
};
|
||||
}
|
||||
|
||||
async function cleanUpGlob(glob: string, name: string, logger: Logger) {
|
||||
@@ -746,11 +757,11 @@ function sanitizeUrlForStatusReport(url: string): string {
|
||||
async function useZstdBundle(
|
||||
cliVersion: string,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
zstdAvailability: tar.ZstdAvailability,
|
||||
): Promise<boolean> {
|
||||
return (
|
||||
semver.gte(cliVersion, "2.19.0") &&
|
||||
!!(await features.getValue(Feature.ZstdBundle)) &&
|
||||
(await tar.isZstdAvailable(logger)).available
|
||||
zstdAvailability.available
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,9 +46,14 @@ async function getTarVersion(): Promise<TarVersion> {
|
||||
}
|
||||
}
|
||||
|
||||
export interface ZstdAvailability {
|
||||
available: boolean;
|
||||
version?: TarVersion;
|
||||
}
|
||||
|
||||
export async function isZstdAvailable(
|
||||
logger: Logger,
|
||||
): Promise<{ available: boolean; version?: TarVersion }> {
|
||||
): Promise<ZstdAvailability> {
|
||||
try {
|
||||
const tarVersion = await getTarVersion();
|
||||
const { type, version } = tarVersion;
|
||||
|
||||
Reference in New Issue
Block a user