Skip to content

Commit 8289a49

Browse files
committed
Ignore repository property for unsupported analysis kinds
1 parent 2a8731c commit 8289a49

4 files changed

Lines changed: 55 additions & 9 deletions

File tree

lib/entry-points.js

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

src/config/file.test.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as github from "@actions/github";
22
import test from "ava";
33
import sinon from "sinon";
44

5+
import { AnalysisKind } from "../analyses";
56
import * as api from "../api-client";
67
import { RegistryProxyVars } from "../environment";
78
import { Feature } from "../feature-flags";
@@ -18,7 +19,7 @@ setupTests(test);
1819

1920
test("getConfigFileInput returns undefined by default", async (t) => {
2021
await callee(getConfigFileInput)
21-
.withArgs({})
22+
.withArgs({}, undefined)
2223
.withFeatures([Feature.ConfigFileRepositoryProperty])
2324
.passes(t.is, undefined);
2425
});
@@ -40,7 +41,7 @@ test("getConfigFileInput returns input value", async (t) => {
4041
.withArgs("config-file")
4142
.returns(testInput);
4243
})
43-
.withArgs(repositoryProperties)
44+
.withArgs(repositoryProperties, undefined)
4445
.logs(t, "Using configuration file input from workflow")
4546
.passes(t.is, testInput);
4647
});
@@ -49,24 +50,52 @@ test("getConfigFileInput returns repository property value", async (t) => {
4950
// Since there is no direct input, we should use the repository property.
5051
await callee(getConfigFileInput)
5152
.withFeatures([Feature.ConfigFileRepositoryProperty])
52-
.withArgs(repositoryProperties)
53+
.withArgs(repositoryProperties, undefined)
5354
.logs(t, "Using configuration file input from repository property")
5455
.passes(t.is, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]);
5556
});
5657

58+
test("getConfigFileInput returns repository property value for Code Scanning", async (t) => {
59+
// Since there is no direct input, we should use the repository property.
60+
await callee(getConfigFileInput)
61+
.withFeatures([Feature.ConfigFileRepositoryProperty])
62+
.withArgs(repositoryProperties, [AnalysisKind.CodeScanning])
63+
.logs(t, "Using configuration file input from repository property")
64+
.passes(t.is, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]);
65+
});
66+
67+
test("getConfigFileInput ignores repository property for other analysis kinds", async (t) => {
68+
const unsupportedCases = [
69+
[AnalysisKind.CodeQuality],
70+
[AnalysisKind.RiskAssessment],
71+
[AnalysisKind.CodeScanning, AnalysisKind.CodeQuality],
72+
];
73+
74+
const target = callee(getConfigFileInput).withFeatures([
75+
Feature.ConfigFileRepositoryProperty,
76+
]);
77+
78+
for (const unsupportedCase of unsupportedCases) {
79+
// Since the analysis kind is unsupported, we should ignore the repository property.
80+
await target
81+
.withArgs(repositoryProperties, unsupportedCase)
82+
.passes(t.is, undefined);
83+
}
84+
});
85+
5786
test("getConfigFileInput ignores empty repository property value", async (t) => {
5887
// Since the repository property value is an empty/whitespace string, we should ignore it.
5988
await callee(getConfigFileInput)
6089
.withFeatures([Feature.ConfigFileRepositoryProperty])
61-
.withArgs({ [RepositoryPropertyName.CONFIG_FILE]: " " })
90+
.withArgs({ [RepositoryPropertyName.CONFIG_FILE]: " " }, undefined)
6291
.passes(t.is, undefined);
6392
});
6493

6594
test("getConfigFileInput ignores repository property value when FF is off", async (t) => {
6695
// Since the FF is off, we should ignore the repository property value.
6796
await callee(getConfigFileInput)
6897
.withFeatures([])
69-
.withArgs(repositoryProperties)
98+
.withArgs(repositoryProperties, undefined)
7099
.notLogs(t, "Using configuration file input from repository property")
71100
.logs(
72101
t,

src/config/file.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ActionState } from "../action-common";
2+
import { AnalysisKind } from "../analyses";
23
import * as api from "../api-client";
34
import * as errorMessages from "../error-messages";
45
import { Feature } from "../feature-flags";
@@ -34,6 +35,7 @@ export async function getConfigFileInput(
3435
features,
3536
}: ActionState<["Logger", "Actions", "FeatureFlags"]>,
3637
repositoryProperties: Partial<RepositoryProperties>,
38+
analysisKinds: AnalysisKind[] | undefined,
3739
): Promise<string | undefined> {
3840
const input = actions.getOptionalInput("config-file");
3941

@@ -45,7 +47,19 @@ export async function getConfigFileInput(
4547
const propertyValue =
4648
repositoryProperties[RepositoryPropertyName.CONFIG_FILE];
4749

48-
if (propertyValue !== undefined && propertyValue.trim().length > 0) {
50+
// Only allow the repository property to be used for standard Code Scanning analyses,
51+
// since we don't currently support some customisation options for Code Quality.
52+
// We don't expect customisations for Risk Assessments either.
53+
const analysisKindSupported =
54+
analysisKinds === undefined ||
55+
(analysisKinds.includes(AnalysisKind.CodeScanning) &&
56+
analysisKinds.length === 1);
57+
58+
if (
59+
analysisKindSupported &&
60+
propertyValue !== undefined &&
61+
propertyValue.trim().length > 0
62+
) {
4963
// Only use the repository property value if the FF is enabled.
5064
const useRepositoryProperty = await features.getValue(
5165
Feature.ConfigFileRepositoryProperty,

src/init-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ async function run(
289289
configFile = await getConfigFileInput(
290290
actionStateWithFeatures,
291291
repositoryProperties,
292+
analysisKinds,
292293
);
293294

294295
// Send a status report indicating that an analysis is starting.

0 commit comments

Comments
 (0)