Skip to content

Commit 4e5f9c0

Browse files
committed
Introduce a rollback mechanism for Java buildless
1 parent 77be28f commit 4e5f9c0

9 files changed

+139
-22
lines changed

lib/config-utils.js

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

lib/config-utils.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/config-utils.test.js

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

lib/config-utils.test.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/init-action.js

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

lib/init-action.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.

src/config-utils.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ import {
1515
} from "./codeql";
1616
import * as configUtils from "./config-utils";
1717
import { BuildMode } from "./config-utils";
18+
import { Feature } from "./feature-flags";
1819
import { Language } from "./languages";
1920
import { getRunnerLogger } from "./logging";
2021
import { parseRepositoryNwo } from "./repository";
2122
import {
2223
setupTests,
2324
mockLanguagesInRepo as mockLanguagesInRepo,
25+
createFeatures,
26+
getRecordingLogger,
27+
LoggedMessage,
2428
} from "./testing-utils";
2529
import {
2630
GitHubVariant,
@@ -63,6 +67,7 @@ function createTestInitConfigInputs(
6367
apiURL: undefined,
6468
registriesAuthTokens: undefined,
6569
},
70+
features: createFeatures([]),
6671
logger: getRunnerLogger(true),
6772
},
6873
overrides,
@@ -1080,3 +1085,45 @@ const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
10801085
t.deepEqual(mockRequest.called, args.expectedApiCall);
10811086
});
10821087
});
1088+
1089+
test("Build mode not overridden when disable Java buildless feature flag disabled", async (t) => {
1090+
const messages: LoggedMessage[] = [];
1091+
const buildMode = await configUtils.parseBuildModeInput(
1092+
"none",
1093+
[Language.java],
1094+
createFeatures([]),
1095+
getRecordingLogger(messages),
1096+
);
1097+
t.is(buildMode, BuildMode.None);
1098+
t.deepEqual(messages, []);
1099+
});
1100+
1101+
test("Build mode not overridden for other languages", async (t) => {
1102+
const messages: LoggedMessage[] = [];
1103+
const buildMode = await configUtils.parseBuildModeInput(
1104+
"none",
1105+
[Language.python],
1106+
createFeatures([Feature.DisableJavaBuildlessEnabled]),
1107+
getRecordingLogger(messages),
1108+
);
1109+
t.is(buildMode, BuildMode.None);
1110+
t.deepEqual(messages, []);
1111+
});
1112+
1113+
test("Build mode overridden when analyzing Java and disable Java buildless feature flag enabled", async (t) => {
1114+
const messages: LoggedMessage[] = [];
1115+
const buildMode = await configUtils.parseBuildModeInput(
1116+
"none",
1117+
[Language.java],
1118+
createFeatures([Feature.DisableJavaBuildlessEnabled]),
1119+
getRecordingLogger(messages),
1120+
);
1121+
t.is(buildMode, BuildMode.Autobuild);
1122+
t.deepEqual(messages, [
1123+
{
1124+
message:
1125+
"Scanning Java code without a build is temporarily unavailable. Falling back to 'autobuild' build mode.",
1126+
type: "warning",
1127+
},
1128+
]);
1129+
});

src/config-utils.ts

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as semver from "semver";
77

88
import * as api from "./api-client";
99
import { CodeQL, CODEQL_VERSION_LANGUAGE_ALIASING } from "./codeql";
10+
import { Feature, FeatureEnablement } from "./feature-flags";
1011
import { Language, parseLanguage } from "./languages";
1112
import { Logger } from "./logging";
1213
import { RepositoryNwo } from "./repository";
@@ -420,6 +421,7 @@ export interface InitConfigInputs {
420421
workspacePath: string;
421422
githubVersion: GitHubVersion;
422423
apiDetails: api.GitHubApiCombinedDetails;
424+
features: FeatureEnablement;
423425
logger: Logger;
424426
}
425427

@@ -449,6 +451,7 @@ export async function getDefaultConfig({
449451
tempDir,
450452
codeql,
451453
githubVersion,
454+
features,
452455
logger,
453456
}: GetDefaultConfigInputs): Promise<Config> {
454457
const languages = await getLanguages(
@@ -457,6 +460,14 @@ export async function getDefaultConfig({
457460
repository,
458461
logger,
459462
);
463+
464+
const buildMode = await parseBuildModeInput(
465+
buildModeInput,
466+
languages,
467+
features,
468+
logger,
469+
);
470+
460471
const augmentationProperties = calculateAugmentation(
461472
packsInput,
462473
queriesInput,
@@ -472,7 +483,7 @@ export async function getDefaultConfig({
472483

473484
return {
474485
languages,
475-
buildMode: validateBuildModeInput(buildModeInput),
486+
buildMode,
476487
originalUserInput: {},
477488
tempDir,
478489
codeQLCmd: codeql.getPath(),
@@ -526,6 +537,7 @@ async function loadConfig({
526537
workspacePath,
527538
githubVersion,
528539
apiDetails,
540+
features,
529541
logger,
530542
}: LoadConfigInputs): Promise<Config> {
531543
let parsedYAML: UserConfig;
@@ -545,6 +557,13 @@ async function loadConfig({
545557
logger,
546558
);
547559

560+
const buildMode = await parseBuildModeInput(
561+
buildModeInput,
562+
languages,
563+
features,
564+
logger,
565+
);
566+
548567
const augmentationProperties = calculateAugmentation(
549568
packsInput,
550569
queriesInput,
@@ -560,7 +579,7 @@ async function loadConfig({
560579

561580
return {
562581
languages,
563-
buildMode: validateBuildModeInput(buildModeInput),
582+
buildMode,
564583
originalUserInput: parsedYAML,
565584
tempDir,
566585
codeQLCmd: codeql.getPath(),
@@ -1073,19 +1092,33 @@ export async function wrapEnvironment(
10731092
}
10741093
}
10751094

1076-
function validateBuildModeInput(
1077-
buildModeInput: string | undefined,
1078-
): BuildMode | undefined {
1079-
if (buildModeInput === undefined) {
1095+
// Exported for testing
1096+
export async function parseBuildModeInput(
1097+
input: string | undefined,
1098+
languages: Language[],
1099+
features: FeatureEnablement,
1100+
logger: Logger,
1101+
): Promise<BuildMode | undefined> {
1102+
if (input === undefined) {
10801103
return undefined;
10811104
}
10821105

1083-
if (!Object.values(BuildMode).includes(buildModeInput as BuildMode)) {
1106+
if (!Object.values(BuildMode).includes(input as BuildMode)) {
10841107
throw new ConfigurationError(
1085-
`Invalid build mode: '${buildModeInput}'. Supported build modes are: ${Object.values(
1108+
`Invalid build mode: '${input}'. Supported build modes are: ${Object.values(
10861109
BuildMode,
10871110
).join(", ")}.`,
10881111
);
10891112
}
1090-
return buildModeInput as BuildMode;
1113+
1114+
if (
1115+
languages.includes(Language.java) &&
1116+
(await features.getValue(Feature.DisableJavaBuildlessEnabled))
1117+
) {
1118+
logger.warning(
1119+
"Scanning Java code without a build is temporarily unavailable. Falling back to 'autobuild' build mode.",
1120+
);
1121+
return BuildMode.Autobuild;
1122+
}
1123+
return input as BuildMode;
10911124
}

src/init-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ async function run() {
285285
workspacePath: getRequiredEnvParam("GITHUB_WORKSPACE"),
286286
githubVersion: gitHubVersion,
287287
apiDetails,
288+
features,
288289
logger,
289290
});
290291

0 commit comments

Comments
 (0)