Skip to content

Commit 5132eb5

Browse files
committed
Fix CodeScanning config's sarifPredicate and add test
1 parent 5b3261b commit 5132eb5

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

lib/analyze-action.js

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-post.js

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

lib/upload-lib.js

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/upload-sarif-action.js

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/analyses.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import * as sinon from "sinon";
44
import * as actionsUtil from "./actions-util";
55
import {
66
AnalysisKind,
7+
CodeScanning,
78
compatibilityMatrix,
9+
getAnalysisConfig,
810
getAnalysisKinds,
911
parseAnalysisKinds,
1012
supportedAnalysisKinds,
1113
} from "./analyses";
1214
import { getRunnerLogger } from "./logging";
1315
import { setupTests } from "./testing-utils";
1416
import { ConfigurationError } from "./util";
17+
import path from "path";
1518

1619
setupTests(test);
1720

@@ -101,3 +104,16 @@ for (let i = 0; i < analysisKinds.length; i++) {
101104
}
102105
}
103106
}
107+
108+
test("Code Scanning configuration does not accept other SARIF extensions", (t) => {
109+
for (const analysisKind of supportedAnalysisKinds) {
110+
if (analysisKind === AnalysisKind.CodeScanning) continue;
111+
112+
const analysis = getAnalysisConfig(analysisKind);
113+
const sarifPath = path.join("path", "to", `file${analysis.sarifExtension}`);
114+
115+
// The Code Scanning configuration's `sarifPredicate` should not accept a path which
116+
// ends in a different configuration's `sarifExtension`.
117+
t.false(CodeScanning.sarifPredicate(sarifPath));
118+
}
119+
});

src/analyses.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ export const CodeScanning: AnalysisConfig = {
156156
sarifExtension: ".sarif",
157157
sarifPredicate: (name) =>
158158
name.endsWith(CodeScanning.sarifExtension) &&
159-
!CodeQuality.sarifPredicate(name),
159+
!CodeQuality.sarifPredicate(name) &&
160+
!CSRA.sarifPredicate(name),
160161
fixCategory: (_, category) => category,
161162
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
162163
};

0 commit comments

Comments
 (0)