mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
Merge pull request #3166 from github/mbg/upload-sarif/add-tests
Add tests for `upload-sarif`
This commit is contained in:
84
lib/upload-sarif-action.js
generated
84
lib/upload-sarif-action.js
generated
@@ -84816,7 +84816,6 @@ var require_sarif_schema_2_1_0 = __commonJS({
|
||||
});
|
||||
|
||||
// src/upload-sarif-action.ts
|
||||
var fs15 = __toESM(require("fs"));
|
||||
var core13 = __toESM(require_core());
|
||||
|
||||
// src/actions-util.ts
|
||||
@@ -93416,7 +93415,8 @@ function filterAlertsByDiffRange(logger, sarif) {
|
||||
return sarif;
|
||||
}
|
||||
|
||||
// src/upload-sarif-action.ts
|
||||
// src/upload-sarif.ts
|
||||
var fs15 = __toESM(require("fs"));
|
||||
async function findAndUpload(logger, features, sarifPath, pathStats, checkoutPath, analysis, category) {
|
||||
let sarifFiles;
|
||||
if (pathStats.isDirectory()) {
|
||||
@@ -93441,6 +93441,40 @@ async function findAndUpload(logger, features, sarifPath, pathStats, checkoutPat
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
async function uploadSarif(logger, features, checkoutPath, sarifPath, category) {
|
||||
const pathStats = fs15.lstatSync(sarifPath, { throwIfNoEntry: false });
|
||||
if (pathStats === void 0) {
|
||||
throw new ConfigurationError(`Path does not exist: ${sarifPath}.`);
|
||||
}
|
||||
const uploadResults = {};
|
||||
const uploadResult = await findAndUpload(
|
||||
logger,
|
||||
features,
|
||||
sarifPath,
|
||||
pathStats,
|
||||
checkoutPath,
|
||||
CodeScanning,
|
||||
category
|
||||
);
|
||||
if (uploadResult !== void 0) {
|
||||
uploadResults["code-scanning" /* CodeScanning */] = uploadResult;
|
||||
}
|
||||
const qualityUploadResult = await findAndUpload(
|
||||
logger,
|
||||
features,
|
||||
sarifPath,
|
||||
pathStats,
|
||||
checkoutPath,
|
||||
CodeQuality,
|
||||
fixCodeQualityCategory(logger, category)
|
||||
);
|
||||
if (qualityUploadResult !== void 0) {
|
||||
uploadResults["code-quality" /* CodeQuality */] = qualityUploadResult;
|
||||
}
|
||||
return uploadResults;
|
||||
}
|
||||
|
||||
// src/upload-sarif-action.ts
|
||||
async function sendSuccessStatusReport(startedAt, uploadStats, logger) {
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
"upload-sarif" /* UploadSarif */,
|
||||
@@ -93487,57 +93521,37 @@ async function run() {
|
||||
const sarifPath = getRequiredInput("sarif_file");
|
||||
const checkoutPath = getRequiredInput("checkout_path");
|
||||
const category = getOptionalInput("category");
|
||||
const pathStats = fs15.lstatSync(sarifPath, { throwIfNoEntry: false });
|
||||
if (pathStats === void 0) {
|
||||
throw new ConfigurationError(`Path does not exist: ${sarifPath}.`);
|
||||
}
|
||||
const sarifIds = [];
|
||||
const uploadResult = await findAndUpload(
|
||||
const uploadResults = await uploadSarif(
|
||||
logger,
|
||||
features,
|
||||
sarifPath,
|
||||
pathStats,
|
||||
checkoutPath,
|
||||
CodeScanning,
|
||||
sarifPath,
|
||||
category
|
||||
);
|
||||
if (uploadResult !== void 0) {
|
||||
core13.setOutput("sarif-id", uploadResult.sarifID);
|
||||
sarifIds.push({
|
||||
analysis: "code-scanning" /* CodeScanning */,
|
||||
id: uploadResult.sarifID
|
||||
});
|
||||
if (Object.keys(uploadResults).length === 0) {
|
||||
throw new ConfigurationError(
|
||||
`No SARIF files found to upload in "${sarifPath}".`
|
||||
);
|
||||
}
|
||||
const qualityUploadResult = await findAndUpload(
|
||||
logger,
|
||||
features,
|
||||
sarifPath,
|
||||
pathStats,
|
||||
checkoutPath,
|
||||
CodeQuality,
|
||||
fixCodeQualityCategory(logger, category)
|
||||
);
|
||||
if (qualityUploadResult !== void 0) {
|
||||
sarifIds.push({
|
||||
analysis: "code-quality" /* CodeQuality */,
|
||||
id: qualityUploadResult.sarifID
|
||||
});
|
||||
const codeScanningResult = uploadResults["code-scanning" /* CodeScanning */];
|
||||
if (codeScanningResult !== void 0) {
|
||||
core13.setOutput("sarif-id", codeScanningResult.sarifID);
|
||||
}
|
||||
core13.setOutput("sarif-ids", JSON.stringify(sarifIds));
|
||||
core13.setOutput("sarif-ids", JSON.stringify(uploadResults));
|
||||
if (isInTestMode()) {
|
||||
core13.debug("In test mode. Waiting for processing is disabled.");
|
||||
} else if (getRequiredInput("wait-for-processing") === "true") {
|
||||
if (uploadResult !== void 0) {
|
||||
if (codeScanningResult !== void 0) {
|
||||
await waitForProcessing(
|
||||
getRepositoryNwo(),
|
||||
uploadResult.sarifID,
|
||||
codeScanningResult.sarifID,
|
||||
logger
|
||||
);
|
||||
}
|
||||
}
|
||||
await sendSuccessStatusReport(
|
||||
startedAt,
|
||||
uploadResult?.statusReport || {},
|
||||
codeScanningResult?.statusReport || {},
|
||||
logger
|
||||
);
|
||||
} catch (unwrappedError) {
|
||||
|
||||
Reference in New Issue
Block a user