Skip to content

Commit 2c76207

Browse files
committed
Upload .quality.sarif files to CQ service in upload-sarif action
1 parent 86f47e8 commit 2c76207

File tree

6 files changed

+66
-7
lines changed

6 files changed

+66
-7
lines changed

lib/upload-lib.js

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

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

lib/upload-sarif-action.js

Lines changed: 11 additions & 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.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-lib.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export function findSarifFilesInDir(
405405
return sarifFiles;
406406
}
407407

408-
function getSarifFilePaths(
408+
export function getSarifFilePaths(
409409
sarifPath: string,
410410
isSarif: (name: string) => boolean = defaultIsSarif,
411411
) {
@@ -622,6 +622,27 @@ export async function uploadFiles(
622622
uploadTarget.sarifFilter,
623623
);
624624

625+
return uploadSpecifiedFiles(
626+
sarifPaths,
627+
checkoutPath,
628+
category,
629+
features,
630+
logger,
631+
uploadTarget,
632+
);
633+
}
634+
635+
/**
636+
* Uploads the given array of SARIF files.
637+
*/
638+
export async function uploadSpecifiedFiles(
639+
sarifPaths: string[],
640+
checkoutPath: string,
641+
category: string | undefined,
642+
features: FeatureEnablement,
643+
logger: Logger,
644+
uploadTarget: UploadTarget = CodeScanningTarget,
645+
): Promise<UploadResult> {
625646
logger.startGroup(`Uploading ${uploadTarget.name} results`);
626647
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
627648

src/upload-sarif-action.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,33 @@ async function run() {
8383
}
8484

8585
try {
86+
const sarifPath = actionsUtil.getRequiredInput("sarif_file");
87+
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
88+
const category = actionsUtil.getOptionalInput("category");
89+
8690
const uploadResult = await upload_lib.uploadFiles(
87-
actionsUtil.getRequiredInput("sarif_file"),
88-
actionsUtil.getRequiredInput("checkout_path"),
89-
actionsUtil.getOptionalInput("category"),
91+
sarifPath,
92+
checkoutPath,
93+
category,
9094
features,
9195
logger,
9296
);
9397
core.setOutput("sarif-id", uploadResult.sarifID);
9498

99+
// If there are `.quality.sarif` files in `sarifPath`, then upload those to the code quality service.
100+
const qualitySarifFiles = upload_lib.getSarifFilePaths(sarifPath);
101+
102+
if (qualitySarifFiles.length !== 0) {
103+
await upload_lib.uploadSpecifiedFiles(
104+
qualitySarifFiles,
105+
checkoutPath,
106+
category,
107+
features,
108+
logger,
109+
upload_lib.CodeQualityTarget,
110+
);
111+
}
112+
95113
// We don't upload results in test mode, so don't wait for processing
96114
if (isInTestMode()) {
97115
core.debug("In test mode. Waiting for processing is disabled.");
@@ -101,6 +119,8 @@ async function run() {
101119
uploadResult.sarifID,
102120
logger,
103121
);
122+
// The code quality service does not currently have an endpoint to wait for SARIF processing,
123+
// so we can't wait for that here.
104124
}
105125
await sendSuccessStatusReport(startedAt, uploadResult.statusReport, logger);
106126
} catch (unwrappedError) {

0 commit comments

Comments
 (0)