Skip to content

Commit

Permalink
C++: introduce automatic installation of dependencies in the autobuilder
Browse files Browse the repository at this point in the history
This introduces the possibility to automatically install dependencies
when running the C++ autobuilder on an Ubuntu runner, that will be
available with upcoming version 2.15.0.

An experimental `cpp-autoinstall-dependencies` input is added to the
`autobuild` action. When not set, the default is driven by a feature
flag.
  • Loading branch information
redsun82 committed Sep 18, 2023
1 parent c459726 commit 1dc6288
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 4 deletions.
11 changes: 11 additions & 0 deletions autobuild/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ inputs:
working directory. If this input is not set, the autobuilder runs with
$GITHUB_WORKSPACE as its working directory.
required: false
cpp-autoinstall-dependencies:
description: >-
Experimental input, the API may change in the future.
Set to true to enable trying to automatically detect and install
dependencies when running the C/C++ autobuilder, set to anything else
to explicitly disable it. This only works when running on Ubuntu and
is automatically disabled otherwise. If this input is not set the
default is currently driven by the cpp_dependency_installation_enabled
feature flag or the CODEQL_CPP_DEPENDENCY_INSTALLATION environment
variable.
required: false
runs:
using: 'node16'
main: '../lib/autobuild-action.js'
64 changes: 64 additions & 0 deletions lib/autobuild.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/autobuild.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Large diffs are not rendered by default.

58 changes: 56 additions & 2 deletions src/autobuild.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { getCodeQL } from "./codeql";
import * as core from "@actions/core";

import { getOptionalInput, getTemporaryDirectory } from "./actions-util";
import { getGitHubVersion } from "./api-client";
import { CodeQL, getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { Language, isTracedLanguage } from "./languages";
import { Feature, Features } from "./feature-flags";
import { isTracedLanguage, Language } from "./languages";
import { Logger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { codeQlVersionAbove, getRequiredEnvParam } from "./util";

export async function determineAutobuildLanguages(
config: configUtils.Config,
Expand Down Expand Up @@ -91,13 +98,60 @@ export async function determineAutobuildLanguages(
return languages;
}

async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
const envVar = "CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES";
const actionInput = getOptionalInput("cpp-autoinstall-dependencies");
const featureName = "C++ automatic installation of dependencies";
if (actionInput === "true") {
if (!(await codeQlVersionAbove(codeql, "2.15.0"))) {
logger.warning(
`${featureName} was explicitly requested but is only available starting from CodeQL version 2.15.0, disabling it`,
);
core.exportVariable(envVar, "false");
} else {
logger.info(
`${
actionInput === "true" ? "Enabling" : "Disabling"
} ${featureName} explicitly requested`,
);
core.exportVariable(envVar, actionInput);
}
} else if (process.env["RUNNER_ENVIRONMENT"] === "self-hosted") {

Check warning

Code scanning / CodeQL

Some environment variables may not exist in default setup workflows Warning

The environment variable RUNNER_ENVIRONMENT may not exist in default setup workflows. If all uses are safe, add it to the list of environment variables that are known to be safe in 'queries/default-setup-environment-variables.ql'. If this use is safe but others are not, dismiss this alert as a false positive.
logger.info(
`Disabling ${featureName} which is the default for self-hosted runners`,
);
core.exportVariable(envVar, "false");
} else {
const gitHubVersion = await getGitHubVersion();
const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const features = new Features(
gitHubVersion,
repositoryNwo,
getTemporaryDirectory(),
logger,
);
if (await features.getValue(Feature.CppDependencyInstallation, codeql)) {
logger.info(`Enabling ${featureName}`);
core.exportVariable(envVar, "true");
} else {
logger.info(`Disabling ${featureName}`);
core.exportVariable(envVar, "false");
}
}
}

export async function runAutobuild(
language: Language,
config: configUtils.Config,
logger: Logger,
) {
logger.startGroup(`Attempting to automatically build ${language} code`);
const codeQL = await getCodeQL(config.codeQLCmd);
if (language === Language.cpp) {
await setupCppAutobuild(codeQL, logger);
}
await codeQL.runAutobuild(language);
logger.endGroup();
}
6 changes: 6 additions & 0 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export enum Feature {
AnalysisSummaryV2Enabled = "analysis_summary_v2_enabled",
CliConfigFileEnabled = "cli_config_file_enabled",
CodeqlJavaLombokEnabled = "codeql_java_lombok_enabled",
CppDependencyInstallation = "cpp_dependency_installation_enabled",
DisableKotlinAnalysisEnabled = "disable_kotlin_analysis_enabled",
DisablePythonDependencyInstallationEnabled = "disable_python_dependency_installation_enabled",
EvaluatorIntraLayerParallelismEnabled = "evaluator_intra_layer_parallelism_enabled",
Expand All @@ -74,6 +75,11 @@ export const featureConfig: Record<
minimumVersion: "2.14.0",
defaultValue: false,
},
[Feature.CppDependencyInstallation]: {
envVar: "CODEQL_CPP_DEPENDENCY_INSTALLATION",
minimumVersion: "2.15.0",
defaultValue: false,
},
[Feature.DisableKotlinAnalysisEnabled]: {
envVar: "CODEQL_DISABLE_KOTLIN_ANALYSIS",
minimumVersion: undefined,
Expand Down

0 comments on commit 1dc6288

Please sign in to comment.