mirror of
https://github.com/github/codeql-action.git
synced 2026-04-29 10:28:52 +00:00
Merge pull request #3206 from github/mbg/analyze/use-upload-sarif
Use `uploadSarif` rather than `uploadFiles` in `analyze` action
This commit is contained in:
Generated
+5
@@ -119134,6 +119134,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+136
-24
@@ -89986,6 +89986,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();
|
||||
@@ -90223,6 +90228,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"));
|
||||
@@ -91112,6 +91126,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
@@ -95736,6 +95755,54 @@ function getSarifFilePaths(sarifPath, isSarif) {
|
||||
}
|
||||
return sarifFiles;
|
||||
}
|
||||
async function getGroupedSarifFilePaths(logger, sarifPath) {
|
||||
const stats = fs18.statSync(sarifPath, { throwIfNoEntry: false });
|
||||
if (stats === void 0) {
|
||||
throw new ConfigurationError(`Path does not exist: ${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 {
|
||||
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 results;
|
||||
}
|
||||
function countResultsInSarif(sarif) {
|
||||
let numResults = 0;
|
||||
const parsedSarif = JSON.parse(sarif);
|
||||
@@ -96092,6 +96159,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);
|
||||
@@ -96185,7 +96275,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;
|
||||
@@ -96288,28 +96378,50 @@ 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,
|
||||
const checkoutPath = getRequiredInput("checkout_path");
|
||||
const category = getOptionalInput("category");
|
||||
if (await features.getValue("analyze_use_new_upload" /* AnalyzeUseNewUpload */)) {
|
||||
uploadResults = await uploadSarif(
|
||||
logger,
|
||||
CodeScanning
|
||||
features,
|
||||
checkoutPath,
|
||||
outputDir,
|
||||
category
|
||||
);
|
||||
core14.setOutput("sarif-id", uploadResult.sarifID);
|
||||
} else {
|
||||
uploadResults = {};
|
||||
if (isCodeScanningEnabled(config)) {
|
||||
uploadResults["code-scanning" /* CodeScanning */] = await uploadFiles(
|
||||
outputDir,
|
||||
checkoutPath,
|
||||
category,
|
||||
features,
|
||||
logger,
|
||||
CodeScanning
|
||||
);
|
||||
}
|
||||
if (isCodeQualityEnabled(config)) {
|
||||
uploadResults["code-quality" /* CodeQuality */] = await uploadFiles(
|
||||
outputDir,
|
||||
checkoutPath,
|
||||
category,
|
||||
features,
|
||||
logger,
|
||||
CodeQuality
|
||||
);
|
||||
}
|
||||
}
|
||||
if (isCodeQualityEnabled(config)) {
|
||||
const analysis = CodeQuality;
|
||||
const qualityUploadResult = await uploadFiles(
|
||||
outputDir,
|
||||
getRequiredInput("checkout_path"),
|
||||
getOptionalInput("category"),
|
||||
features,
|
||||
logger,
|
||||
analysis
|
||||
if (uploadResults["code-scanning" /* CodeScanning */] !== void 0) {
|
||||
core14.setOutput(
|
||||
"sarif-id",
|
||||
uploadResults["code-scanning" /* CodeScanning */].sarifID
|
||||
);
|
||||
}
|
||||
if (uploadResults["code-quality" /* CodeQuality */] !== void 0) {
|
||||
core14.setOutput(
|
||||
"quality-sarif-id",
|
||||
uploadResults["code-quality" /* CodeQuality */].sarifID
|
||||
);
|
||||
core14.setOutput("quality-sarif-id", qualityUploadResult.sarifID);
|
||||
}
|
||||
} else {
|
||||
logger.info("Not uploading results");
|
||||
@@ -96337,10 +96449,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?.["code-scanning" /* CodeScanning */] !== void 0 && getRequiredInput("wait-for-processing") === "true") {
|
||||
await waitForProcessing(
|
||||
getRepositoryNwo(),
|
||||
uploadResult.sarifID,
|
||||
uploadResults["code-scanning" /* CodeScanning */].sarifID,
|
||||
getActionsLogger()
|
||||
);
|
||||
}
|
||||
@@ -96369,13 +96481,13 @@ async function run() {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (runStats && uploadResult) {
|
||||
if (runStats !== void 0 && uploadResults?.["code-scanning" /* CodeScanning */] !== void 0) {
|
||||
await sendStatusReport2(
|
||||
startedAt,
|
||||
config,
|
||||
{
|
||||
...runStats,
|
||||
...uploadResult.statusReport
|
||||
...uploadResults["code-scanning" /* CodeScanning */].statusReport
|
||||
},
|
||||
void 0,
|
||||
trapCacheUploadTime,
|
||||
@@ -96385,7 +96497,7 @@ async function run() {
|
||||
dependencyCacheResults,
|
||||
logger
|
||||
);
|
||||
} else if (runStats) {
|
||||
} else if (runStats !== void 0) {
|
||||
await sendStatusReport2(
|
||||
startedAt,
|
||||
config,
|
||||
|
||||
Generated
+5
@@ -79887,6 +79887,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -129250,6 +129250,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -88552,6 +88552,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -79878,6 +79878,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -86357,6 +86357,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -118540,6 +118540,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -96669,6 +96669,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -89349,6 +89349,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -118706,6 +118706,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Generated
+5
@@ -89300,6 +89300,11 @@ var featureConfig = {
|
||||
envVar: "CODEQL_ACTION_ALLOW_TOOLCACHE_INPUT",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["analyze_use_new_upload" /* AnalyzeUseNewUpload */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_ANALYZE_USE_NEW_UPLOAD",
|
||||
minimumVersion: void 0
|
||||
},
|
||||
["cleanup_trap_caches" /* CleanupTrapCaches */]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
|
||||
|
||||
Reference in New Issue
Block a user