Skip to content

Commit

Permalink
Introduce a rollback mechanism for Java buildless
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Feb 12, 2024
1 parent 77be28f commit 4e5f9c0
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 22 deletions.
30 changes: 20 additions & 10 deletions lib/config-utils.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/config-utils.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions lib/config-utils.test.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/config-utils.test.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/init-action.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/init-action.js.map

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ import {
} from "./codeql";
import * as configUtils from "./config-utils";
import { BuildMode } from "./config-utils";
import { Feature } from "./feature-flags";
import { Language } from "./languages";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import {
setupTests,
mockLanguagesInRepo as mockLanguagesInRepo,
createFeatures,
getRecordingLogger,
LoggedMessage,
} from "./testing-utils";
import {
GitHubVariant,
Expand Down Expand Up @@ -63,6 +67,7 @@ function createTestInitConfigInputs(
apiURL: undefined,
registriesAuthTokens: undefined,
},
features: createFeatures([]),
logger: getRunnerLogger(true),
},
overrides,
Expand Down Expand Up @@ -1080,3 +1085,45 @@ const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
t.deepEqual(mockRequest.called, args.expectedApiCall);
});
});

test("Build mode not overridden when disable Java buildless feature flag disabled", async (t) => {
const messages: LoggedMessage[] = [];
const buildMode = await configUtils.parseBuildModeInput(
"none",
[Language.java],
createFeatures([]),
getRecordingLogger(messages),
);
t.is(buildMode, BuildMode.None);
t.deepEqual(messages, []);
});

test("Build mode not overridden for other languages", async (t) => {
const messages: LoggedMessage[] = [];
const buildMode = await configUtils.parseBuildModeInput(
"none",
[Language.python],
createFeatures([Feature.DisableJavaBuildlessEnabled]),
getRecordingLogger(messages),
);
t.is(buildMode, BuildMode.None);
t.deepEqual(messages, []);
});

test("Build mode overridden when analyzing Java and disable Java buildless feature flag enabled", async (t) => {
const messages: LoggedMessage[] = [];
const buildMode = await configUtils.parseBuildModeInput(
"none",
[Language.java],
createFeatures([Feature.DisableJavaBuildlessEnabled]),
getRecordingLogger(messages),
);
t.is(buildMode, BuildMode.Autobuild);
t.deepEqual(messages, [
{
message:
"Scanning Java code without a build is temporarily unavailable. Falling back to 'autobuild' build mode.",
type: "warning",
},
]);
});
51 changes: 42 additions & 9 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as semver from "semver";

import * as api from "./api-client";
import { CodeQL, CODEQL_VERSION_LANGUAGE_ALIASING } from "./codeql";
import { Feature, FeatureEnablement } from "./feature-flags";
import { Language, parseLanguage } from "./languages";
import { Logger } from "./logging";
import { RepositoryNwo } from "./repository";
Expand Down Expand Up @@ -420,6 +421,7 @@ export interface InitConfigInputs {
workspacePath: string;
githubVersion: GitHubVersion;
apiDetails: api.GitHubApiCombinedDetails;
features: FeatureEnablement;
logger: Logger;
}

Expand Down Expand Up @@ -449,6 +451,7 @@ export async function getDefaultConfig({
tempDir,
codeql,
githubVersion,
features,
logger,
}: GetDefaultConfigInputs): Promise<Config> {
const languages = await getLanguages(
Expand All @@ -457,6 +460,14 @@ export async function getDefaultConfig({
repository,
logger,
);

const buildMode = await parseBuildModeInput(
buildModeInput,
languages,
features,
logger,
);

const augmentationProperties = calculateAugmentation(
packsInput,
queriesInput,
Expand All @@ -472,7 +483,7 @@ export async function getDefaultConfig({

return {
languages,
buildMode: validateBuildModeInput(buildModeInput),
buildMode,
originalUserInput: {},
tempDir,
codeQLCmd: codeql.getPath(),
Expand Down Expand Up @@ -526,6 +537,7 @@ async function loadConfig({
workspacePath,
githubVersion,
apiDetails,
features,
logger,
}: LoadConfigInputs): Promise<Config> {
let parsedYAML: UserConfig;
Expand All @@ -545,6 +557,13 @@ async function loadConfig({
logger,
);

const buildMode = await parseBuildModeInput(
buildModeInput,
languages,
features,
logger,
);

const augmentationProperties = calculateAugmentation(
packsInput,
queriesInput,
Expand All @@ -560,7 +579,7 @@ async function loadConfig({

return {
languages,
buildMode: validateBuildModeInput(buildModeInput),
buildMode,
originalUserInput: parsedYAML,
tempDir,
codeQLCmd: codeql.getPath(),
Expand Down Expand Up @@ -1073,19 +1092,33 @@ export async function wrapEnvironment(
}
}

function validateBuildModeInput(
buildModeInput: string | undefined,
): BuildMode | undefined {
if (buildModeInput === undefined) {
// Exported for testing
export async function parseBuildModeInput(
input: string | undefined,
languages: Language[],
features: FeatureEnablement,
logger: Logger,
): Promise<BuildMode | undefined> {
if (input === undefined) {
return undefined;
}

if (!Object.values(BuildMode).includes(buildModeInput as BuildMode)) {
if (!Object.values(BuildMode).includes(input as BuildMode)) {
throw new ConfigurationError(
`Invalid build mode: '${buildModeInput}'. Supported build modes are: ${Object.values(
`Invalid build mode: '${input}'. Supported build modes are: ${Object.values(
BuildMode,
).join(", ")}.`,
);
}
return buildModeInput as BuildMode;

if (
languages.includes(Language.java) &&
(await features.getValue(Feature.DisableJavaBuildlessEnabled))
) {
logger.warning(
"Scanning Java code without a build is temporarily unavailable. Falling back to 'autobuild' build mode.",
);
return BuildMode.Autobuild;
}
return input as BuildMode;
}
1 change: 1 addition & 0 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ async function run() {
workspacePath: getRequiredEnvParam("GITHUB_WORKSPACE"),
githubVersion: gitHubVersion,
apiDetails,
features,
logger,
});

Expand Down

0 comments on commit 4e5f9c0

Please sign in to comment.