mirror of
https://github.com/github/codeql-action.git
synced 2025-12-29 02:30:11 +08:00
Use uploadSarif rather than uploadFiles in analyze action
This commit is contained in:
152
lib/analyze-action.js
generated
152
lib/analyze-action.js
generated
@@ -89971,6 +89971,11 @@ async function asyncSome(array, predicate) {
|
||||
const results = await Promise.all(array.map(predicate));
|
||||
return results.some((result) => result);
|
||||
}
|
||||
function unsafeEntriesInvariant(object) {
|
||||
return Object.entries(object).filter(
|
||||
([_, val2]) => val2 !== void 0
|
||||
);
|
||||
}
|
||||
|
||||
// src/actions-util.ts
|
||||
var pkg = require_package();
|
||||
@@ -90208,6 +90213,15 @@ var CodeQuality = {
|
||||
fixCategory: fixCodeQualityCategory,
|
||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_"
|
||||
};
|
||||
function getAnalysisConfig(kind) {
|
||||
switch (kind) {
|
||||
case "code-scanning" /* CodeScanning */:
|
||||
return CodeScanning;
|
||||
case "code-quality" /* CodeQuality */:
|
||||
return CodeQuality;
|
||||
}
|
||||
}
|
||||
var SarifScanOrder = [CodeQuality, CodeScanning];
|
||||
|
||||
// src/analyze.ts
|
||||
var fs15 = __toESM(require("fs"));
|
||||
@@ -95715,22 +95729,53 @@ function findSarifFilesInDir(sarifPath, isSarif) {
|
||||
walkSarifFiles(sarifPath);
|
||||
return sarifFiles;
|
||||
}
|
||||
function getSarifFilePaths(sarifPath, isSarif) {
|
||||
if (!fs18.existsSync(sarifPath)) {
|
||||
async function getGroupedSarifFilePaths(logger, sarifPath) {
|
||||
const stats = fs18.statSync(sarifPath, { throwIfNoEntry: false });
|
||||
if (stats === void 0) {
|
||||
throw new ConfigurationError(`Path does not exist: ${sarifPath}`);
|
||||
}
|
||||
let sarifFiles;
|
||||
if (fs18.lstatSync(sarifPath).isDirectory()) {
|
||||
sarifFiles = findSarifFilesInDir(sarifPath, isSarif);
|
||||
if (sarifFiles.length === 0) {
|
||||
throw new ConfigurationError(
|
||||
`No SARIF files found to upload in "${sarifPath}".`
|
||||
const results = {};
|
||||
if (stats.isDirectory()) {
|
||||
let unassignedSarifFiles = findSarifFilesInDir(
|
||||
sarifPath,
|
||||
(name) => path18.extname(name) === ".sarif"
|
||||
);
|
||||
logger.debug(
|
||||
`Found the following .sarif files in ${sarifPath}: ${unassignedSarifFiles.join(", ")}`
|
||||
);
|
||||
for (const analysisConfig of SarifScanOrder) {
|
||||
const filesForCurrentAnalysis = unassignedSarifFiles.filter(
|
||||
analysisConfig.sarifPredicate
|
||||
);
|
||||
if (filesForCurrentAnalysis.length > 0) {
|
||||
logger.debug(
|
||||
`The following SARIF files are for ${analysisConfig.name}: ${filesForCurrentAnalysis.join(", ")}`
|
||||
);
|
||||
unassignedSarifFiles = unassignedSarifFiles.filter(
|
||||
(name) => !analysisConfig.sarifPredicate(name)
|
||||
);
|
||||
results[analysisConfig.kind] = filesForCurrentAnalysis;
|
||||
} else {
|
||||
logger.debug(`Found no SARIF files for ${analysisConfig.name}`);
|
||||
}
|
||||
}
|
||||
if (unassignedSarifFiles.length !== 0) {
|
||||
logger.warning(
|
||||
`Found files in ${sarifPath} which do not belong to any analysis: ${unassignedSarifFiles.join(", ")}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
sarifFiles = [sarifPath];
|
||||
for (const analysisConfig of SarifScanOrder) {
|
||||
if (analysisConfig.kind === "code-scanning" /* CodeScanning */ || analysisConfig.sarifPredicate(sarifPath)) {
|
||||
logger.debug(
|
||||
`Using '${sarifPath}' as a SARIF file for ${analysisConfig.name}.`
|
||||
);
|
||||
results[analysisConfig.kind] = [sarifPath];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sarifFiles;
|
||||
return results;
|
||||
}
|
||||
function countResultsInSarif(sarif) {
|
||||
let numResults = 0;
|
||||
@@ -95827,20 +95872,6 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
|
||||
}
|
||||
return payloadObj;
|
||||
}
|
||||
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) {
|
||||
const sarifPaths = getSarifFilePaths(
|
||||
inputSarifPath,
|
||||
uploadTarget.sarifPredicate
|
||||
);
|
||||
return uploadSpecifiedFiles(
|
||||
sarifPaths,
|
||||
checkoutPath,
|
||||
category,
|
||||
features,
|
||||
logger,
|
||||
uploadTarget
|
||||
);
|
||||
}
|
||||
async function uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget) {
|
||||
logger.startGroup(`Uploading ${uploadTarget.name} results`);
|
||||
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
|
||||
@@ -96088,6 +96119,29 @@ function filterAlertsByDiffRange(logger, sarif) {
|
||||
return sarif;
|
||||
}
|
||||
|
||||
// src/upload-sarif.ts
|
||||
async function uploadSarif(logger, features, checkoutPath, sarifPath, category) {
|
||||
const sarifGroups = await getGroupedSarifFilePaths(
|
||||
logger,
|
||||
sarifPath
|
||||
);
|
||||
const uploadResults = {};
|
||||
for (const [analysisKind, sarifFiles] of unsafeEntriesInvariant(
|
||||
sarifGroups
|
||||
)) {
|
||||
const analysisConfig = getAnalysisConfig(analysisKind);
|
||||
uploadResults[analysisKind] = await uploadSpecifiedFiles(
|
||||
sarifFiles,
|
||||
checkoutPath,
|
||||
category,
|
||||
features,
|
||||
logger,
|
||||
analysisConfig
|
||||
);
|
||||
}
|
||||
return uploadResults;
|
||||
}
|
||||
|
||||
// src/analyze-action.ts
|
||||
async function sendStatusReport2(startedAt, config, stats, error2, trapCacheUploadTime, dbCreationTimings, didUploadTrapCaches, trapCacheCleanup, dependencyCacheResults, logger) {
|
||||
const status = getActionsStatus(error2, stats?.analyze_failure_language);
|
||||
@@ -96181,7 +96235,7 @@ async function runAutobuildIfLegacyGoWorkflow(config, logger) {
|
||||
}
|
||||
async function run() {
|
||||
const startedAt = /* @__PURE__ */ new Date();
|
||||
let uploadResult = void 0;
|
||||
let uploadResults = void 0;
|
||||
let runStats = void 0;
|
||||
let config = void 0;
|
||||
let trapCacheCleanupTelemetry = void 0;
|
||||
@@ -96284,29 +96338,23 @@ async function run() {
|
||||
core14.setOutput("sarif-output", import_path4.default.resolve(outputDir));
|
||||
const uploadInput = getOptionalInput("upload");
|
||||
if (runStats && getUploadValue(uploadInput) === "always") {
|
||||
if (isCodeScanningEnabled(config)) {
|
||||
uploadResult = await uploadFiles(
|
||||
outputDir,
|
||||
getRequiredInput("checkout_path"),
|
||||
getOptionalInput("category"),
|
||||
features,
|
||||
logger,
|
||||
CodeScanning
|
||||
);
|
||||
core14.setOutput("sarif-id", uploadResult.sarifID);
|
||||
}
|
||||
if (isCodeQualityEnabled(config)) {
|
||||
const analysis = CodeQuality;
|
||||
const qualityUploadResult = await uploadFiles(
|
||||
outputDir,
|
||||
getRequiredInput("checkout_path"),
|
||||
getOptionalInput("category"),
|
||||
features,
|
||||
logger,
|
||||
analysis
|
||||
);
|
||||
core14.setOutput("quality-sarif-id", qualityUploadResult.sarifID);
|
||||
}
|
||||
const checkoutPath = getRequiredInput("checkout_path");
|
||||
const category = getOptionalInput("category");
|
||||
uploadResults = await uploadSarif(
|
||||
logger,
|
||||
features,
|
||||
checkoutPath,
|
||||
outputDir,
|
||||
category
|
||||
);
|
||||
core14.setOutput(
|
||||
"sarif-id",
|
||||
uploadResults["code-scanning" /* CodeScanning */]?.sarifID
|
||||
);
|
||||
core14.setOutput(
|
||||
"quality-sarif-id",
|
||||
uploadResults["code-quality" /* CodeQuality */]?.sarifID
|
||||
);
|
||||
} else {
|
||||
logger.info("Not uploading results");
|
||||
}
|
||||
@@ -96333,10 +96381,10 @@ async function run() {
|
||||
}
|
||||
if (isInTestMode()) {
|
||||
logger.debug("In test mode. Waiting for processing is disabled.");
|
||||
} else if (uploadResult !== void 0 && getRequiredInput("wait-for-processing") === "true") {
|
||||
} else if (uploadResults !== void 0 && uploadResults["code-scanning" /* CodeScanning */] !== void 0 && getRequiredInput("wait-for-processing") === "true") {
|
||||
await waitForProcessing(
|
||||
getRepositoryNwo(),
|
||||
uploadResult.sarifID,
|
||||
uploadResults["code-scanning" /* CodeScanning */].sarifID,
|
||||
getActionsLogger()
|
||||
);
|
||||
}
|
||||
@@ -96365,13 +96413,13 @@ async function run() {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (runStats && uploadResult) {
|
||||
if (runStats && uploadResults && uploadResults["code-scanning" /* CodeScanning */]) {
|
||||
await sendStatusReport2(
|
||||
startedAt,
|
||||
config,
|
||||
{
|
||||
...runStats,
|
||||
...uploadResult.statusReport
|
||||
...uploadResults["code-scanning" /* CodeScanning */].statusReport
|
||||
},
|
||||
void 0,
|
||||
trapCacheUploadTime,
|
||||
|
||||
Reference in New Issue
Block a user