Skip to content

Commit 7b3d150

Browse files
committed
Use findSarifFilesInDir in upload-sarif to avoid error when there are no quality.sarif files
1 parent ad6046f commit 7b3d150

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

lib/upload-sarif-action.js

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

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as fs from "fs";
2+
13
import * as core from "@actions/core";
24

35
import * as actionsUtil from "./actions-util";
@@ -98,20 +100,24 @@ async function run() {
98100
core.setOutput("sarif-id", uploadResult.sarifID);
99101

100102
// If there are `.quality.sarif` files in `sarifPath`, then upload those to the code quality service.
101-
const qualitySarifFiles = upload_lib.getSarifFilePaths(
102-
sarifPath,
103-
upload_lib.CodeQualityTarget.sarifPredicate,
104-
);
105-
106-
if (qualitySarifFiles.length !== 0) {
107-
await upload_lib.uploadSpecifiedFiles(
108-
qualitySarifFiles,
109-
checkoutPath,
110-
category,
111-
features,
112-
logger,
113-
upload_lib.CodeQualityTarget,
103+
// Code quality can currently only be enabled on top of security, so we'd currently always expect to
104+
// have a directory for the results here.
105+
if (fs.lstatSync(sarifPath).isDirectory()) {
106+
const qualitySarifFiles = upload_lib.findSarifFilesInDir(
107+
sarifPath,
108+
upload_lib.CodeQualityTarget.sarifPredicate,
114109
);
110+
111+
if (qualitySarifFiles.length !== 0) {
112+
await upload_lib.uploadSpecifiedFiles(
113+
qualitySarifFiles,
114+
checkoutPath,
115+
category,
116+
features,
117+
logger,
118+
upload_lib.CodeQualityTarget,
119+
);
120+
}
115121
}
116122

117123
// We don't upload results in test mode, so don't wait for processing

0 commit comments

Comments
 (0)