mirror of
https://github.com/github/codeql-action.git
synced 2026-05-12 17:00:15 +00:00
Refactor finding SARIF files for the different upload endpoints
This commit is contained in:
+35
-17
@@ -53,6 +53,28 @@ async function sendSuccessStatusReport(
|
||||
}
|
||||
}
|
||||
|
||||
async function findSecuritySarifFiles(sarifPath: string): Promise<string[]> {
|
||||
if (fs.lstatSync(sarifPath).isDirectory()) {
|
||||
return upload_lib.findSarifFilesInDir(
|
||||
sarifPath,
|
||||
upload_lib.CodeScanningTarget.sarifPredicate,
|
||||
);
|
||||
}
|
||||
|
||||
return [sarifPath];
|
||||
}
|
||||
|
||||
async function findQualitySarifFiles(sarifPath: string): Promise<string[]> {
|
||||
if (fs.lstatSync(sarifPath).isDirectory()) {
|
||||
return upload_lib.findSarifFilesInDir(
|
||||
sarifPath,
|
||||
upload_lib.CodeQualityTarget.sarifPredicate,
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
const logger = getActionsLogger();
|
||||
@@ -89,8 +111,11 @@ async function run() {
|
||||
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
|
||||
const category = actionsUtil.getOptionalInput("category");
|
||||
|
||||
const uploadResult = await upload_lib.uploadFiles(
|
||||
sarifPath,
|
||||
const securitySarifFiles = await findSecuritySarifFiles(sarifPath);
|
||||
const qualitySarifFiles = await findQualitySarifFiles(sarifPath);
|
||||
|
||||
const uploadResult = await upload_lib.uploadSpecifiedFiles(
|
||||
securitySarifFiles,
|
||||
checkoutPath,
|
||||
category,
|
||||
features,
|
||||
@@ -102,22 +127,15 @@ async function run() {
|
||||
// If there are `.quality.sarif` files in `sarifPath`, then upload those to the code quality service.
|
||||
// Code quality can currently only be enabled on top of security, so we'd currently always expect to
|
||||
// have a directory for the results here.
|
||||
if (fs.lstatSync(sarifPath).isDirectory()) {
|
||||
const qualitySarifFiles = upload_lib.findSarifFilesInDir(
|
||||
sarifPath,
|
||||
upload_lib.CodeQualityTarget.sarifPredicate,
|
||||
if (qualitySarifFiles.length !== 0) {
|
||||
await upload_lib.uploadSpecifiedFiles(
|
||||
qualitySarifFiles,
|
||||
checkoutPath,
|
||||
actionsUtil.fixCodeQualityCategory(logger, category),
|
||||
features,
|
||||
logger,
|
||||
upload_lib.CodeQualityTarget,
|
||||
);
|
||||
|
||||
if (qualitySarifFiles.length !== 0) {
|
||||
await upload_lib.uploadSpecifiedFiles(
|
||||
qualitySarifFiles,
|
||||
checkoutPath,
|
||||
actionsUtil.fixCodeQualityCategory(logger, category),
|
||||
features,
|
||||
logger,
|
||||
upload_lib.CodeQualityTarget,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// We don't upload results in test mode, so don't wait for processing
|
||||
|
||||
Reference in New Issue
Block a user