Fix dependency cycle between trap-caching and init
This commit is contained in:
parent
2637069a45
commit
5658fd1df2
21 changed files with 104 additions and 113 deletions
|
|
@ -16,9 +16,9 @@ import * as codeql from "./codeql";
|
|||
import { AugmentationProperties, Config } from "./config-utils";
|
||||
import * as defaults from "./defaults.json";
|
||||
import { Feature, featureConfig } from "./feature-flags";
|
||||
import { ToolsSource } from "./init";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
import {
|
||||
setupTests,
|
||||
createFeatures,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import * as core from "@actions/core";
|
|||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as yaml from "js-yaml";
|
||||
|
||||
import { getOptionalInput } from "./actions-util";
|
||||
import { getOptionalInput, isAnalyzingDefaultBranch } from "./actions-util";
|
||||
import * as api from "./api-client";
|
||||
import {
|
||||
Config,
|
||||
|
|
@ -21,15 +21,10 @@ import {
|
|||
FeatureEnablement,
|
||||
useCodeScanningConfigInCli,
|
||||
} from "./feature-flags";
|
||||
import { ToolsSource } from "./init";
|
||||
import { isTracedLanguage, Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import * as setupCodeql from "./setup-codeql";
|
||||
import { toolrunnerErrorCatcher } from "./toolrunner-error-catcher";
|
||||
import {
|
||||
getTrapCachingExtractorConfigArgs,
|
||||
getTrapCachingExtractorConfigArgsForLang,
|
||||
} from "./trap-caching";
|
||||
import * as util from "./util";
|
||||
import { wrapError } from "./util";
|
||||
|
||||
|
|
@ -345,7 +340,7 @@ export async function setupCodeQL(
|
|||
): Promise<{
|
||||
codeql: CodeQL;
|
||||
toolsDownloadDurationMs?: number;
|
||||
toolsSource: ToolsSource;
|
||||
toolsSource: setupCodeql.ToolsSource;
|
||||
toolsVersion: string;
|
||||
}> {
|
||||
try {
|
||||
|
|
@ -1264,3 +1259,31 @@ async function getCodeScanningConfigExportArguments(
|
|||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
// This constant sets the size of each TRAP cache in megabytes.
|
||||
const TRAP_CACHE_SIZE_MB = 1024;
|
||||
|
||||
export async function getTrapCachingExtractorConfigArgs(
|
||||
config: Config
|
||||
): Promise<string[]> {
|
||||
const result: string[][] = [];
|
||||
for (const language of config.languages)
|
||||
result.push(
|
||||
await getTrapCachingExtractorConfigArgsForLang(config, language)
|
||||
);
|
||||
return result.flat();
|
||||
}
|
||||
|
||||
export async function getTrapCachingExtractorConfigArgsForLang(
|
||||
config: Config,
|
||||
language: Language
|
||||
): Promise<string[]> {
|
||||
const cacheDir = config.trapCaches[language];
|
||||
if (cacheDir === undefined) return [];
|
||||
const write = await isAnalyzingDefaultBranch();
|
||||
return [
|
||||
`-O=${language}.trap.cache.dir=${cacheDir}`,
|
||||
`-O=${language}.trap.cache.bound=${TRAP_CACHE_SIZE_MB}`,
|
||||
`-O=${language}.trap.cache.write=${write}`,
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,16 +21,11 @@ import * as configUtils from "./config-utils";
|
|||
import { getMlPoweredJsQueriesStatus } from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Feature, Features } from "./feature-flags";
|
||||
import {
|
||||
initCodeQL,
|
||||
initConfig,
|
||||
installPythonDeps,
|
||||
runInit,
|
||||
ToolsSource,
|
||||
} from "./init";
|
||||
import { initCodeQL, initConfig, installPythonDeps, runInit } from "./init";
|
||||
import { Language } from "./languages";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
import { getTotalCacheSize } from "./trap-caching";
|
||||
import {
|
||||
checkForTimeout,
|
||||
|
|
|
|||
|
|
@ -15,16 +15,10 @@ import {
|
|||
} from "./feature-flags";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
import { TracerConfig, getCombinedTracerConfig } from "./tracer-config";
|
||||
import * as util from "./util";
|
||||
|
||||
export enum ToolsSource {
|
||||
Unknown = "UNKNOWN",
|
||||
Local = "LOCAL",
|
||||
Toolcache = "TOOLCACHE",
|
||||
Download = "DOWNLOAD",
|
||||
}
|
||||
|
||||
export async function initCodeQL(
|
||||
toolsInput: string | undefined,
|
||||
apiDetails: GitHubApiDetails,
|
||||
|
|
|
|||
|
|
@ -15,11 +15,17 @@ import * as api from "./api-client";
|
|||
// these dependents.
|
||||
import * as defaults from "./defaults.json";
|
||||
import { CodeQLDefaultVersionInfo } from "./feature-flags";
|
||||
import { ToolsSource } from "./init";
|
||||
import { Logger } from "./logging";
|
||||
import * as util from "./util";
|
||||
import { isGoodVersion, wrapError } from "./util";
|
||||
|
||||
export enum ToolsSource {
|
||||
Unknown = "UNKNOWN",
|
||||
Local = "LOCAL",
|
||||
Toolcache = "TOOLCACHE",
|
||||
Download = "DOWNLOAD",
|
||||
}
|
||||
|
||||
export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
|
||||
function getCodeQLBundleName(): string {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ import test from "ava";
|
|||
import * as sinon from "sinon";
|
||||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
import { setCodeQL } from "./codeql";
|
||||
import {
|
||||
setCodeQL,
|
||||
getTrapCachingExtractorConfigArgs,
|
||||
getTrapCachingExtractorConfigArgsForLang,
|
||||
} from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { Config } from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
|
|
@ -14,8 +18,6 @@ import { getRecordingLogger, setupTests } from "./testing-utils";
|
|||
import {
|
||||
downloadTrapCaches,
|
||||
getLanguagesSupportingCaching,
|
||||
getTrapCachingExtractorConfigArgs,
|
||||
getTrapCachingExtractorConfigArgsForLang,
|
||||
uploadTrapCaches,
|
||||
} from "./trap-caching";
|
||||
import * as util from "./util";
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@ import { codeQlVersionAbove, tryGetFolderBytes, withTimeout } from "./util";
|
|||
// goes into the cache key.
|
||||
const CACHE_VERSION = 1;
|
||||
|
||||
// This constant sets the size of each TRAP cache in megabytes.
|
||||
const CACHE_SIZE_MB = 1024;
|
||||
|
||||
// This constant sets the minimum size in megabytes of a TRAP
|
||||
// cache for us to consider it worth uploading.
|
||||
const MINIMUM_CACHE_MB_TO_UPLOAD = 10;
|
||||
|
|
@ -30,31 +27,6 @@ const MINIMUM_CACHE_MB_TO_UPLOAD = 10;
|
|||
// times as there are languages with TRAP caching enabled.
|
||||
const MAX_CACHE_OPERATION_MS = 120_000; // Two minutes
|
||||
|
||||
export async function getTrapCachingExtractorConfigArgs(
|
||||
config: Config
|
||||
): Promise<string[]> {
|
||||
const result: string[][] = [];
|
||||
for (const language of config.languages)
|
||||
result.push(
|
||||
await getTrapCachingExtractorConfigArgsForLang(config, language)
|
||||
);
|
||||
return result.flat();
|
||||
}
|
||||
|
||||
export async function getTrapCachingExtractorConfigArgsForLang(
|
||||
config: Config,
|
||||
language: Language
|
||||
): Promise<string[]> {
|
||||
const cacheDir = config.trapCaches[language];
|
||||
if (cacheDir === undefined) return [];
|
||||
const write = await actionsUtil.isAnalyzingDefaultBranch();
|
||||
return [
|
||||
`-O=${language}.trap.cache.dir=${cacheDir}`,
|
||||
`-O=${language}.trap.cache.bound=${CACHE_SIZE_MB}`,
|
||||
`-O=${language}.trap.cache.write=${write}`,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Download TRAP caches from the Actions cache.
|
||||
* @param codeql The CodeQL instance to use.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue