Skip to content

Commit

Permalink
Merge pull request #2329 from github/henrymercer/csharp-buildless-rol…
Browse files Browse the repository at this point in the history
…lback-mechanism

Add rollback mechanism for C# buildless
  • Loading branch information
henrymercer authored Jun 13, 2024
2 parents 789b5f8 + feec81c commit 5bf6dad
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 65 deletions.
5 changes: 5 additions & 0 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.

59 changes: 36 additions & 23 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.

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.

90 changes: 51 additions & 39 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,44 +1086,56 @@ const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
});
});

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, []);
});
for (const { displayName, language, feature } of [
{
displayName: "Java",
language: Language.java,
feature: Feature.DisableJavaBuildlessEnabled,
},
{
displayName: "C#",
language: Language.csharp,
feature: Feature.DisableCsharpBuildless,
},
]) {
test(`Build mode not overridden when disable ${displayName} buildless feature flag disabled`, async (t) => {
const messages: LoggedMessage[] = [];
const buildMode = await configUtils.parseBuildModeInput(
"none",
[language],
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 not overridden for other languages when disable ${displayName} buildless feature flag enabled`, async (t) => {
const messages: LoggedMessage[] = [];
const buildMode = await configUtils.parseBuildModeInput(
"none",
[Language.python],
createFeatures([feature]),
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",
},
]);
});
test(`Build mode overridden when analyzing ${displayName} and disable ${displayName} buildless feature flag enabled`, async (t) => {
const messages: LoggedMessage[] = [];
const buildMode = await configUtils.parseBuildModeInput(
"none",
[language],
createFeatures([feature]),
getRecordingLogger(messages),
);
t.is(buildMode, BuildMode.Autobuild);
t.deepEqual(messages, [
{
message: `Scanning ${displayName} code without a build is temporarily unavailable. Falling back to 'autobuild' build mode.`,
type: "warning",
},
]);
});
}
10 changes: 10 additions & 0 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,16 @@ export async function parseBuildModeInput(
);
}

if (
languages.includes(Language.csharp) &&
(await features.getValue(Feature.DisableCsharpBuildless))
) {
logger.warning(
"Scanning C# code without a build is temporarily unavailable. Falling back to 'autobuild' build mode.",
);
return BuildMode.Autobuild;
}

if (
languages.includes(Language.java) &&
(await features.getValue(Feature.DisableJavaBuildlessEnabled))
Expand Down
6 changes: 6 additions & 0 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum Feature {
CleanupTrapCaches = "cleanup_trap_caches",
CppDependencyInstallation = "cpp_dependency_installation_enabled",
CppTrapCachingEnabled = "cpp_trap_caching_enabled",
DisableCsharpBuildless = "disable_csharp_buildless",
DisableJavaBuildlessEnabled = "disable_java_buildless_enabled",
DisableKotlinAnalysisEnabled = "disable_kotlin_analysis_enabled",
ExportDiagnosticsEnabled = "export_diagnostics_enabled",
Expand Down Expand Up @@ -109,6 +110,11 @@ export const featureConfig: Record<
legacyApi: true,
minimumVersion: "2.16.1",
},
[Feature.DisableCsharpBuildless]: {
defaultValue: false,
envVar: "CODEQL_ACTION_DISABLE_CSHARP_BUILDLESS",
minimumVersion: undefined,
},
[Feature.DisableJavaBuildlessEnabled]: {
defaultValue: false,
envVar: "CODEQL_ACTION_DISABLE_JAVA_BUILDLESS",
Expand Down

0 comments on commit 5bf6dad

Please sign in to comment.