Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
angelapwen committed Jan 23, 2023
1 parent cc99631 commit 8ca90f9
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 75 deletions.
33 changes: 22 additions & 11 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,23 @@ export async function setupCodeQL(
defaultCliVersion: CodeQLDefaultVersionInfo,
logger: Logger,
checkVersion: boolean
): Promise<{ codeql: CodeQL; toolsDownloadDurationMs?: number; toolsSource: ToolsSource; toolsVersion: string }> {
): Promise<{
codeql: CodeQL;
toolsDownloadDurationMs?: number;
toolsSource: ToolsSource;
toolsVersion: string;
}> {
try {
const { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion } = await setupCodeql.setupCodeQLBundle(
toolsInput,
apiDetails,
tempDir,
variant,
bypassToolcache,
defaultCliVersion,
logger
);
const { codeqlFolder, toolsDownloadDurationMs, toolsSource, toolsVersion } =
await setupCodeql.setupCodeQLBundle(
toolsInput,
apiDetails,
tempDir,
variant,
bypassToolcache,
defaultCliVersion,
logger
);
let codeqlCmd = path.join(codeqlFolder, "codeql", "codeql");
if (process.platform === "win32") {
codeqlCmd += ".exe";
Expand All @@ -320,7 +326,12 @@ export async function setupCodeQL(
}

cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
return { codeql: cachedCodeQL, toolsDownloadDurationMs, toolsSource, toolsVersion };
return {
codeql: cachedCodeQL,
toolsDownloadDurationMs,
toolsSource,
toolsVersion,
};
} catch (e) {
logger.error(e instanceof Error ? e : new Error(String(e)));
throw new Error("Unable to download and extract CodeQL CLI");
Expand Down
54 changes: 26 additions & 28 deletions src/feature-flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,11 @@ for (const variant of [GitHubVariant.GHAE, GitHubVariant.GHES]) {
const features = setUpFeatureFlagTests(tmpDir);

const defaultCliVersion = await features.getDefaultCliVersion(variant);
t.deepEqual(
defaultCliVersion.codeQLDefaultVersionInfo,
{
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
variant,
});
t.deepEqual(defaultCliVersion.codeQLDefaultVersionInfo, {
cliVersion: defaults.cliVersion,
tagName: defaults.bundleVersion,
variant,
});

t.is(defaultCliVersion.toolsFeatureFlagsValid, undefined);
});
Expand All @@ -403,13 +401,13 @@ test("selects CLI v2.12.1 on Dotcom when feature flags enable v2.12.0 and v2.12.
expectedFeatureEnablement["default_codeql_version_2_12_5_enabled"] = false;
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);

const defaultCliVersion = await featureEnablement.getDefaultCliVersion(GitHubVariant.DOTCOM);
t.deepEqual(
defaultCliVersion.codeQLDefaultVersionInfo,
{
cliVersion: "2.12.1",
variant: GitHubVariant.DOTCOM,
});
const defaultCliVersion = await featureEnablement.getDefaultCliVersion(
GitHubVariant.DOTCOM
);
t.deepEqual(defaultCliVersion.codeQLDefaultVersionInfo, {
cliVersion: "2.12.1",
variant: GitHubVariant.DOTCOM,
});

t.is(defaultCliVersion.toolsFeatureFlagsValid, true);
});
Expand All @@ -421,13 +419,13 @@ test(`selects CLI v2.11.6 on Dotcom when no default version feature flags are en
const expectedFeatureEnablement = initializeFeatures(true);
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);

const defaultCliVersion = await featureEnablement.getDefaultCliVersion(GitHubVariant.DOTCOM);
t.deepEqual(
defaultCliVersion.codeQLDefaultVersionInfo,
{
cliVersion: "2.11.6",
variant: GitHubVariant.DOTCOM,
});
const defaultCliVersion = await featureEnablement.getDefaultCliVersion(
GitHubVariant.DOTCOM
);
t.deepEqual(defaultCliVersion.codeQLDefaultVersionInfo, {
cliVersion: "2.11.6",
variant: GitHubVariant.DOTCOM,
});

t.is(defaultCliVersion.toolsFeatureFlagsValid, false);
});
Expand All @@ -447,13 +445,13 @@ test("ignores invalid version numbers in default version feature flags", async (
true;
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);

const defaultCliVersion = await featureEnablement.getDefaultCliVersion(GitHubVariant.DOTCOM);
t.deepEqual(
defaultCliVersion.codeQLDefaultVersionInfo,
{
cliVersion: "2.12.1",
variant: GitHubVariant.DOTCOM,
});
const defaultCliVersion = await featureEnablement.getDefaultCliVersion(
GitHubVariant.DOTCOM
);
t.deepEqual(defaultCliVersion.codeQLDefaultVersionInfo, {
cliVersion: "2.12.1",
variant: GitHubVariant.DOTCOM,
});

t.is(defaultCliVersion.toolsFeatureFlagsValid, true);

Expand Down
33 changes: 21 additions & 12 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export type CodeQLDefaultVersionInfo =

export interface FeatureEnablement {
/** Gets the default version of the CodeQL tools. */
getDefaultCliVersion(
variant: util.GitHubVariant
): Promise<{ codeQLDefaultVersionInfo: CodeQLDefaultVersionInfo; toolsFeatureFlagsValid?: boolean }>;
getDefaultCliVersion(variant: util.GitHubVariant): Promise<{
codeQLDefaultVersionInfo: CodeQLDefaultVersionInfo;
toolsFeatureFlagsValid?: boolean;
}>;
getValue(feature: Feature, codeql?: CodeQL): Promise<boolean>;
}

Expand Down Expand Up @@ -113,9 +114,10 @@ export class Features implements FeatureEnablement {
);
}

async getDefaultCliVersion(
variant: util.GitHubVariant
): Promise<{ codeQLDefaultVersionInfo: CodeQLDefaultVersionInfo; toolsFeatureFlagsValid?: boolean }> {
async getDefaultCliVersion(variant: util.GitHubVariant): Promise<{
codeQLDefaultVersionInfo: CodeQLDefaultVersionInfo;
toolsFeatureFlagsValid?: boolean;
}> {
return await this.gitHubFeatureFlags.getDefaultCliVersion(variant);
}

Expand Down Expand Up @@ -204,17 +206,18 @@ class GitHubFeatureFlags implements FeatureEnablement {
return version;
}

async getDefaultCliVersion(
variant: util.GitHubVariant
): Promise<{ codeQLDefaultVersionInfo: CodeQLDefaultVersionInfo; toolsFeatureFlagsValid?: boolean }> {
async getDefaultCliVersion(variant: util.GitHubVariant): Promise<{
codeQLDefaultVersionInfo: CodeQLDefaultVersionInfo;
toolsFeatureFlagsValid?: boolean;
}> {
if (variant === util.GitHubVariant.DOTCOM) {
const defaultDotComCliVersion = await this.getDefaultDotcomCliVersion();
return {
codeQLDefaultVersionInfo: {
cliVersion: defaultDotComCliVersion.version,
variant,
},
toolsFeatureFlagsValid: defaultDotComCliVersion.toolsFeatureFlagsValid
toolsFeatureFlagsValid: defaultDotComCliVersion.toolsFeatureFlagsValid,
};
}
return {
Expand All @@ -226,7 +229,10 @@ class GitHubFeatureFlags implements FeatureEnablement {
};
}

async getDefaultDotcomCliVersion(): Promise<{ version: string; toolsFeatureFlagsValid: boolean }> {
async getDefaultDotcomCliVersion(): Promise<{
version: string;
toolsFeatureFlagsValid: boolean;
}> {
const response = await this.getAllFeatures();

const enabledFeatureFlagCliVersions = Object.entries(response)
Expand All @@ -241,7 +247,10 @@ class GitHubFeatureFlags implements FeatureEnablement {
"Feature flags do not specify a default CLI version. Falling back to CLI version " +
`${MINIMUM_ENABLED_CODEQL_VERSION}.`
);
return { version: MINIMUM_ENABLED_CODEQL_VERSION, toolsFeatureFlagsValid: false };
return {
version: MINIMUM_ENABLED_CODEQL_VERSION,
toolsFeatureFlagsValid: false,
};
}

const maxCliVersion = enabledFeatureFlagCliVersions.reduce(
Expand Down
31 changes: 22 additions & 9 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
injectWindowsTracer,
installPythonDeps,
runInit,
ToolsSource
ToolsSource,
} from "./init";
import { Language } from "./languages";
import { getActionsLogger, Logger } from "./logging";
Expand Down Expand Up @@ -139,12 +139,12 @@ async function sendInitStatusReport(
tools_resolved_version: toolsVersion || "",
workflow_languages: workflowLanguages || "",
// TODO(angelapwen): I think the following will crash if config.trapCaches is undefined because we might
// be sending a failure report before we initialize config.
// be sending a failure report before we initialize config.
trap_cache_languages: Object.keys(config.trapCaches).join(",") || "",
trap_cache_download_size_bytes: Math.round(
await getTotalCacheSize(config.trapCaches, logger)
) || -1, // Placeholder value if cache size is not determined yet.
trap_cache_download_duration_ms: Math.round(config.trapCacheDownloadTime) || -1, // Placeholder value if cache size is not determined yet.,
trap_cache_download_size_bytes:
Math.round(await getTotalCacheSize(config.trapCaches, logger)) || -1, // Placeholder value if cache size is not determined yet.
trap_cache_download_duration_ms:
Math.round(config.trapCacheDownloadTime) || -1, // Placeholder value if cache size is not determined yet.,
tools_source: toolsSource || ToolsSource.Unknown,
};

Expand All @@ -155,8 +155,12 @@ async function sendInitStatusReport(
// Otherwise, we should append the extra two download-related telemetry fields.
const downloadStatusReport: InitDownloadStatusReport = {
...statusReport,
tools_download_duration_ms: toolsDownloadDurationMs ? toolsDownloadDurationMs : -1, // Placeholder value in case field is undefined.
tools_feature_flags_valid: toolsFeatureFlagsValid ? toolsFeatureFlagsValid : false, // Report invalid in case field is undefined.
tools_download_duration_ms: toolsDownloadDurationMs
? toolsDownloadDurationMs
: -1, // Placeholder value in case field is undefined.
tools_feature_flags_valid: toolsFeatureFlagsValid
? toolsFeatureFlagsValid
: false, // Report invalid in case field is undefined.
};

await sendStatusReport(downloadStatusReport);
Expand Down Expand Up @@ -363,7 +367,16 @@ async function run() {
);
return;
}
await sendInitStatusReport("success", startedAt, config, toolsDownloadDurationMs, toolsFeatureFlagsValid, toolsSource, toolsVersion, logger);
await sendInitStatusReport(
"success",
startedAt,
config,
toolsDownloadDurationMs,
toolsFeatureFlagsValid,
toolsSource,
toolsVersion,
logger
);
}

async function getTrapCachingEnabled(
Expand Down
30 changes: 18 additions & 12 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export enum ToolsSource {
Unknown = "UNKNOWN",
Local = "LOCAL",
Toolcache = "TOOLCACHE",
Download = "DOWNLOAD"
Download = "DOWNLOAD",
}

export async function initCodeQL(
Expand All @@ -30,18 +30,24 @@ export async function initCodeQL(
bypassToolcache: boolean,
defaultCliVersion: CodeQLDefaultVersionInfo,
logger: Logger
): Promise<{ codeql: CodeQL; toolsDownloadDurationMs?: number; toolsSource: ToolsSource; toolsVersion: string }> {
): Promise<{
codeql: CodeQL;
toolsDownloadDurationMs?: number;
toolsSource: ToolsSource;
toolsVersion: string;
}> {
logger.startGroup("Setup CodeQL tools");
const { codeql, toolsDownloadDurationMs, toolsSource, toolsVersion } = await setupCodeQL(
toolsInput,
apiDetails,
tempDir,
variant,
bypassToolcache,
defaultCliVersion,
logger,
true
);
const { codeql, toolsDownloadDurationMs, toolsSource, toolsVersion } =
await setupCodeQL(
toolsInput,
apiDetails,
tempDir,
variant,
bypassToolcache,
defaultCliVersion,
logger,
true
);
await codeql.printVersion();
logger.endGroup();
return { codeql, toolsDownloadDurationMs, toolsSource, toolsVersion };
Expand Down
15 changes: 12 additions & 3 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,11 @@ export async function downloadCodeQL(
variant: util.GitHubVariant,
tempDir: string,
logger: Logger
): Promise<{ toolsVersion: string; codeqlFolder: string; toolsDownloadDurationMs: number }> {
): Promise<{
toolsVersion: string;
codeqlFolder: string;
toolsDownloadDurationMs: number;
}> {
const parsedCodeQLURL = new URL(codeqlURL);
const searchParams = new URLSearchParams(parsedCodeQLURL.search);
const headers: OutgoingHttpHeaders = {
Expand Down Expand Up @@ -587,7 +591,7 @@ export async function downloadCodeQL(
"CodeQL",
toolcacheVersion
),
toolsDownloadDurationMs
toolsDownloadDurationMs,
};
}

Expand Down Expand Up @@ -623,7 +627,12 @@ export async function setupCodeQLBundle(
bypassToolcache: boolean,
defaultCliVersion: CodeQLDefaultVersionInfo,
logger: Logger
): Promise<{ codeqlFolder: string; toolsDownloadDurationMs?: number; toolsSource: ToolsSource; toolsVersion: string }> {
): Promise<{
codeqlFolder: string;
toolsDownloadDurationMs?: number;
toolsSource: ToolsSource;
toolsVersion: string;
}> {
const source = await getCodeQLSource(
toolsInput,
bypassToolcache,
Expand Down

0 comments on commit 8ca90f9

Please sign in to comment.