mirror of
https://github.com/github/codeql-action.git
synced 2026-10-30 17:39:50 +00:00
Enable direct tracing the autobuild build mode by default
This commit is contained in:
@@ -20,7 +20,7 @@ import { getCodeQL } from "./codeql";
|
||||
import { Config, getConfig } from "./config-utils";
|
||||
import { uploadDatabases } from "./database-upload";
|
||||
import { EnvVar } from "./environment";
|
||||
import { FeatureEnablement, Features } from "./feature-flags";
|
||||
import { Features } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
@@ -147,11 +147,7 @@ function doesGoExtractionOutputExist(config: Config): boolean {
|
||||
* - We approximate whether manual build steps are present by looking at
|
||||
* whether any extraction output already exists for Go.
|
||||
*/
|
||||
async function runAutobuildIfLegacyGoWorkflow(
|
||||
config: Config,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
) {
|
||||
async function runAutobuildIfLegacyGoWorkflow(config: Config, logger: Logger) {
|
||||
if (!config.languages.includes(Language.go)) {
|
||||
return;
|
||||
}
|
||||
@@ -188,7 +184,7 @@ async function runAutobuildIfLegacyGoWorkflow(
|
||||
logger.debug(
|
||||
"Running Go autobuild because extraction output (TRAP files) for Go code has not been found.",
|
||||
);
|
||||
await runAutobuild(config, Language.go, features, logger);
|
||||
await runAutobuild(config, Language.go, logger);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
@@ -260,7 +256,7 @@ async function run() {
|
||||
);
|
||||
|
||||
await warnIfGoInstalledAfterInit(config, logger);
|
||||
await runAutobuildIfLegacyGoWorkflow(config, features, logger);
|
||||
await runAutobuildIfLegacyGoWorkflow(config, logger);
|
||||
|
||||
dbCreationTimings = await runFinalize(
|
||||
outputDir,
|
||||
@@ -268,7 +264,6 @@ async function run() {
|
||||
memory,
|
||||
codeql,
|
||||
config,
|
||||
features,
|
||||
logger,
|
||||
);
|
||||
|
||||
|
||||
@@ -382,7 +382,6 @@ export async function runFinalize(
|
||||
memoryFlag: string,
|
||||
codeql: CodeQL,
|
||||
config: configUtils.Config,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<DatabaseCreationTimings> {
|
||||
try {
|
||||
@@ -404,7 +403,7 @@ export async function runFinalize(
|
||||
|
||||
// If we didn't already end tracing in the autobuild Action, end it now.
|
||||
if (process.env[EnvVar.AUTOBUILD_DID_COMPLETE_SUCCESSFULLY] !== "true") {
|
||||
await endTracingForCluster(codeql, config, logger, features);
|
||||
await endTracingForCluster(codeql, config, logger);
|
||||
}
|
||||
return timings;
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ import { determineAutobuildLanguages, runAutobuild } from "./autobuild";
|
||||
import { getCodeQL } from "./codeql";
|
||||
import { Config, getConfig } from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Features } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { Logger, getActionsLogger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import {
|
||||
StatusReportBase,
|
||||
getActionsStatus,
|
||||
@@ -26,7 +24,6 @@ import {
|
||||
checkActionVersion,
|
||||
checkDiskUsage,
|
||||
checkGitHubVersionInRange,
|
||||
getRequiredEnvParam,
|
||||
initializeEnvironment,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
@@ -92,17 +89,6 @@ async function run() {
|
||||
checkGitHubVersionInRange(gitHubVersion, logger);
|
||||
checkActionVersion(getActionVersion(), gitHubVersion);
|
||||
|
||||
const repositoryNwo = parseRepositoryNwo(
|
||||
getRequiredEnvParam("GITHUB_REPOSITORY"),
|
||||
);
|
||||
|
||||
const features = new Features(
|
||||
gitHubVersion,
|
||||
repositoryNwo,
|
||||
getTemporaryDirectory(),
|
||||
logger,
|
||||
);
|
||||
|
||||
config = await getConfig(getTemporaryDirectory(), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error(
|
||||
@@ -123,13 +109,13 @@ async function run() {
|
||||
}
|
||||
for (const language of languages) {
|
||||
currentLanguage = language;
|
||||
await runAutobuild(config, language, features, logger);
|
||||
await runAutobuild(config, language, logger);
|
||||
}
|
||||
}
|
||||
|
||||
// End tracing early to avoid tracing analyze. This improves the performance and reliability of
|
||||
// the analyze step.
|
||||
await endTracingForCluster(codeql, config, logger, features);
|
||||
await endTracingForCluster(codeql, config, logger);
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
core.setFailed(
|
||||
|
||||
@@ -5,12 +5,7 @@ import { getGitHubVersion } from "./api-client";
|
||||
import { CodeQL, getCodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import {
|
||||
Feature,
|
||||
featureConfig,
|
||||
FeatureEnablement,
|
||||
Features,
|
||||
} from "./feature-flags";
|
||||
import { Feature, featureConfig, Features } from "./feature-flags";
|
||||
import { isTracedLanguage, Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
@@ -159,7 +154,6 @@ export async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
|
||||
export async function runAutobuild(
|
||||
config: configUtils.Config,
|
||||
language: Language,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
) {
|
||||
logger.startGroup(`Attempting to automatically build ${language} code`);
|
||||
@@ -169,7 +163,7 @@ export async function runAutobuild(
|
||||
}
|
||||
if (
|
||||
config.buildMode &&
|
||||
(await features.getValue(Feature.AutobuildDirectTracing, codeQL))
|
||||
(await codeQL.supportsFeature(ToolsFeature.TraceCommandUseBuildMode))
|
||||
) {
|
||||
await codeQL.extractUsingBuildMode(config, language);
|
||||
} else {
|
||||
|
||||
@@ -482,7 +482,6 @@ const injectedConfigMacro = test.macro({
|
||||
"",
|
||||
undefined,
|
||||
undefined,
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
@@ -696,7 +695,6 @@ test("passes a code scanning config AND qlconfig to the CLI", async (t: Executio
|
||||
"",
|
||||
undefined,
|
||||
"/path/to/qlconfig.yml",
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
@@ -726,7 +724,6 @@ test("does not pass a qlconfig to the CLI when it is undefined", async (t: Execu
|
||||
"",
|
||||
undefined,
|
||||
undefined, // undefined qlconfigFile
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
@@ -991,7 +988,6 @@ test("Avoids duplicating --overwrite flag if specified in CODEQL_ACTION_EXTRA_OP
|
||||
"sourceRoot",
|
||||
undefined,
|
||||
undefined,
|
||||
createFeatures([]),
|
||||
getRunnerLogger(false),
|
||||
);
|
||||
|
||||
|
||||
@@ -82,7 +82,6 @@ export interface CodeQL {
|
||||
sourceRoot: string,
|
||||
processName: string | undefined,
|
||||
qlconfigFile: string | undefined,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<void>;
|
||||
/**
|
||||
@@ -558,13 +557,12 @@ export async function getCodeQLForCmd(
|
||||
sourceRoot: string,
|
||||
processName: string | undefined,
|
||||
qlconfigFile: string | undefined,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
) {
|
||||
const extraArgs = config.languages.map(
|
||||
(language) => `--language=${language}`,
|
||||
);
|
||||
if (await shouldEnableIndirectTracing(codeql, config, features)) {
|
||||
if (await shouldEnableIndirectTracing(codeql, config)) {
|
||||
extraArgs.push("--begin-tracing");
|
||||
extraArgs.push(...(await getTrapCachingExtractorConfigArgs(config)));
|
||||
extraArgs.push(`--trace-process-name=${processName}`);
|
||||
|
||||
@@ -45,7 +45,6 @@ export interface FeatureEnablement {
|
||||
* Legacy features should end with `_enabled`.
|
||||
*/
|
||||
export enum Feature {
|
||||
AutobuildDirectTracing = "autobuild_direct_tracing_v2",
|
||||
CleanupTrapCaches = "cleanup_trap_caches",
|
||||
CppDependencyInstallation = "cpp_dependency_installation_enabled",
|
||||
DisableCsharpBuildless = "disable_csharp_buildless",
|
||||
@@ -86,12 +85,6 @@ export const featureConfig: Record<
|
||||
toolsFeature?: ToolsFeature;
|
||||
}
|
||||
> = {
|
||||
[Feature.AutobuildDirectTracing]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_AUTOBUILD_BUILD_MODE_DIRECT_TRACING",
|
||||
minimumVersion: undefined,
|
||||
toolsFeature: ToolsFeature.TraceCommandUseBuildMode,
|
||||
},
|
||||
[Feature.CleanupTrapCaches]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
@@ -541,7 +541,6 @@ async function run() {
|
||||
"Runner.Worker.exe",
|
||||
getOptionalInput("registries"),
|
||||
apiDetails,
|
||||
features,
|
||||
logger,
|
||||
);
|
||||
if (tracerConfig !== undefined) {
|
||||
|
||||
@@ -9,7 +9,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, FeatureEnablement } from "./feature-flags";
|
||||
import { CodeQLDefaultVersionInfo } from "./feature-flags";
|
||||
import { Language, isScannedLanguage } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
@@ -71,7 +71,6 @@ export async function runInit(
|
||||
processName: string | undefined,
|
||||
registriesInput: string | undefined,
|
||||
apiDetails: GitHubApiCombinedDetails,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<TracerConfig | undefined> {
|
||||
fs.mkdirSync(config.dbLocation, { recursive: true });
|
||||
@@ -95,11 +94,10 @@ export async function runInit(
|
||||
sourceRoot,
|
||||
processName,
|
||||
qlconfigFile,
|
||||
features,
|
||||
logger,
|
||||
),
|
||||
);
|
||||
return await getCombinedTracerConfig(codeql, config, features);
|
||||
return await getCombinedTracerConfig(codeql, config);
|
||||
}
|
||||
|
||||
export function printPathFiltersWarning(
|
||||
|
||||
@@ -6,7 +6,6 @@ import test from "ava";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
import {
|
||||
createFeatures,
|
||||
createTestConfig,
|
||||
mockCodeQLVersion,
|
||||
setupTests,
|
||||
@@ -30,11 +29,7 @@ test("getCombinedTracerConfig - return undefined when no languages are traced la
|
||||
// No traced languages
|
||||
config.languages = [Language.javascript, Language.python];
|
||||
t.deepEqual(
|
||||
await getCombinedTracerConfig(
|
||||
mockCodeQLVersion("1.0.0"),
|
||||
config,
|
||||
createFeatures([]),
|
||||
),
|
||||
await getCombinedTracerConfig(mockCodeQLVersion("1.0.0"), config),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
@@ -72,7 +67,6 @@ test("getCombinedTracerConfig - with start-tracing.json environment file", async
|
||||
const result = await getCombinedTracerConfig(
|
||||
mockCodeQLVersion("1.0.0"),
|
||||
config,
|
||||
createFeatures([]),
|
||||
);
|
||||
t.notDeepEqual(result, undefined);
|
||||
|
||||
@@ -133,7 +127,6 @@ test("getCombinedTracerConfig - with SetsCodeqlRunnerEnvVar feature enabled in C
|
||||
const result = await getCombinedTracerConfig(
|
||||
mockCodeQLVersion("1.0.0", { setsCodeqlRunnerEnvVar: true }),
|
||||
config,
|
||||
createFeatures([]),
|
||||
);
|
||||
t.notDeepEqual(result, undefined);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import * as path from "path";
|
||||
|
||||
import { type CodeQL } from "./codeql";
|
||||
import { type Config } from "./config-utils";
|
||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||
import { isTracedLanguage } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { ToolsFeature } from "./tools-features";
|
||||
@@ -16,14 +15,23 @@ export type TracerConfig = {
|
||||
export async function shouldEnableIndirectTracing(
|
||||
codeql: CodeQL,
|
||||
config: Config,
|
||||
features: FeatureEnablement,
|
||||
): Promise<boolean> {
|
||||
return (
|
||||
(!config.buildMode ||
|
||||
config.buildMode === BuildMode.Manual ||
|
||||
!(await features.getValue(Feature.AutobuildDirectTracing, codeql))) &&
|
||||
config.languages.some((l) => isTracedLanguage(l))
|
||||
);
|
||||
// We don't need to trace build mode none, or languages which unconditionally don't need tracing.
|
||||
if (config.buildMode === BuildMode.None) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the CLI supports `trace-command` with a `--build-mode`, we'll use direct tracing instead of
|
||||
// indirect tracing.
|
||||
if (
|
||||
config.buildMode === BuildMode.Autobuild &&
|
||||
(await codeql.supportsFeature(ToolsFeature.TraceCommandUseBuildMode))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, use direct tracing if any of the languages need to be traced.
|
||||
return config.languages.some((l) => isTracedLanguage(l));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,9 +47,8 @@ export async function endTracingForCluster(
|
||||
codeql: CodeQL,
|
||||
config: Config,
|
||||
logger: Logger,
|
||||
features: FeatureEnablement,
|
||||
): Promise<void> {
|
||||
if (!(await shouldEnableIndirectTracing(codeql, config, features))) return;
|
||||
if (!(await shouldEnableIndirectTracing(codeql, config))) return;
|
||||
|
||||
logger.info(
|
||||
"Unsetting build tracing environment variables. Subsequent steps of this job will not be traced.",
|
||||
@@ -94,10 +101,10 @@ export async function getTracerConfigForCluster(
|
||||
export async function getCombinedTracerConfig(
|
||||
codeql: CodeQL,
|
||||
config: Config,
|
||||
features: FeatureEnablement,
|
||||
): Promise<TracerConfig | undefined> {
|
||||
if (!(await shouldEnableIndirectTracing(codeql, config, features)))
|
||||
if (!(await shouldEnableIndirectTracing(codeql, config))) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const mainTracerConfig = await getTracerConfigForCluster(config);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user