Skip to content

Commit 49aaa9a

Browse files
authored
Merge pull request #1889 from github/redsun82/cpp-autoinstall-dependencies
C++: introduce automatic installation of dependencies in the autobuilder
2 parents 8e0b1c7 + c21e1dd commit 49aaa9a

File tree

8 files changed

+127
-6
lines changed

8 files changed

+127
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th
44

55
## [UNRELEASED]
66

7-
No user facing changes.
7+
- We are rolling out a feature in October 2023 that will improve the success rate of C/C++ autobuild. [#1889](https://github.com/github/codeql-action/pull/1889)
88

99
## 2.21.8 - 19 Sep 2023
1010

lib/autobuild.js

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

queries/default-setup-environment-variables.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ predicate isSafeForDefaultSetup(string envVar) {
2323
"GITHUB_BASE_REF", "GITHUB_EVENT_NAME", "GITHUB_JOB", "GITHUB_RUN_ATTEMPT", "GITHUB_RUN_ID",
2424
"GITHUB_SHA", "GITHUB_REPOSITORY", "GITHUB_SERVER_URL", "GITHUB_TOKEN", "GITHUB_WORKFLOW",
2525
"GITHUB_WORKSPACE", "GOFLAGS", "ImageVersion", "JAVA_TOOL_OPTIONS", "RUNNER_ARCH",
26-
"RUNNER_NAME", "RUNNER_OS", "RUNNER_TEMP", "RUNNER_TOOL_CACHE"
26+
"RUNNER_ENVIRONMENT", "RUNNER_NAME", "RUNNER_OS", "RUNNER_TEMP", "RUNNER_TOOL_CACHE"
2727
]
2828
}
2929

src/autobuild.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { getCodeQL } from "./codeql";
1+
import * as core from "@actions/core";
2+
3+
import { getTemporaryDirectory, getWorkflowEventName } from "./actions-util";
4+
import { getGitHubVersion } from "./api-client";
5+
import { CodeQL, getCodeQL } from "./codeql";
26
import * as configUtils from "./config-utils";
3-
import { Language, isTracedLanguage } from "./languages";
7+
import { Feature, featureConfig, Features } from "./feature-flags";
8+
import { isTracedLanguage, Language } from "./languages";
49
import { Logger } from "./logging";
10+
import { parseRepositoryNwo } from "./repository";
11+
import { getRequiredEnvParam } from "./util";
512

613
export async function determineAutobuildLanguages(
714
config: configUtils.Config,
@@ -91,13 +98,57 @@ export async function determineAutobuildLanguages(
9198
return languages;
9299
}
93100

101+
async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
102+
const envVar = featureConfig[Feature.CppDependencyInstallation].envVar;
103+
const featureName = "C++ automatic installation of dependencies";
104+
const envDoc =
105+
"https://docs.github.com/en/actions/learn-github-actions/variables#defining-environment-variables-for-a-single-workflow";
106+
const gitHubVersion = await getGitHubVersion();
107+
const repositoryNwo = parseRepositoryNwo(
108+
getRequiredEnvParam("GITHUB_REPOSITORY"),
109+
);
110+
const features = new Features(
111+
gitHubVersion,
112+
repositoryNwo,
113+
getTemporaryDirectory(),
114+
logger,
115+
);
116+
if (await features.getValue(Feature.CppDependencyInstallation, codeql)) {
117+
// disable autoinstall on self-hosted runners unless explicitly requested
118+
if (
119+
process.env["RUNNER_ENVIRONMENT"] === "self-hosted" &&
120+
process.env[envVar] !== "true"
121+
) {
122+
logger.info(
123+
`Disabling ${featureName} as we are on a self-hosted runner.${
124+
getWorkflowEventName() !== "dynamic"
125+
? ` To override this, set the ${envVar} environment variable to 'true' in your workflow (see ${envDoc}).`
126+
: ""
127+
}`,
128+
);
129+
core.exportVariable(envVar, "false");
130+
} else {
131+
logger.info(
132+
`Enabling ${featureName}. This can be disabled by setting the ${envVar} environment variable to 'false' (see ${envDoc}).`,
133+
);
134+
core.exportVariable(envVar, "true");
135+
}
136+
} else {
137+
logger.info(`Disabling ${featureName}.`);
138+
core.exportVariable(envVar, "false");
139+
}
140+
}
141+
94142
export async function runAutobuild(
95143
language: Language,
96144
config: configUtils.Config,
97145
logger: Logger,
98146
) {
99147
logger.startGroup(`Attempting to automatically build ${language} code`);
100148
const codeQL = await getCodeQL(config.codeQLCmd);
149+
if (language === Language.cpp) {
150+
await setupCppAutobuild(codeQL, logger);
151+
}
101152
await codeQL.runAutobuild(language);
102153
logger.endGroup();
103154
}

src/feature-flags.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum Feature {
5151
AnalysisSummaryV2Enabled = "analysis_summary_v2_enabled",
5252
CliConfigFileEnabled = "cli_config_file_enabled",
5353
CodeqlJavaLombokEnabled = "codeql_java_lombok_enabled",
54+
CppDependencyInstallation = "cpp_dependency_installation_enabled",
5455
DisableKotlinAnalysisEnabled = "disable_kotlin_analysis_enabled",
5556
DisablePythonDependencyInstallationEnabled = "disable_python_dependency_installation_enabled",
5657
EvaluatorIntraLayerParallelismEnabled = "evaluator_intra_layer_parallelism_enabled",
@@ -74,6 +75,11 @@ export const featureConfig: Record<
7475
minimumVersion: "2.14.0",
7576
defaultValue: false,
7677
},
78+
[Feature.CppDependencyInstallation]: {
79+
envVar: "CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES",
80+
minimumVersion: "2.15.0",
81+
defaultValue: false,
82+
},
7783
[Feature.DisableKotlinAnalysisEnabled]: {
7884
envVar: "CODEQL_DISABLE_KOTLIN_ANALYSIS",
7985
minimumVersion: undefined,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy