Introduce CODEQL_ACTION_SARIF_DUMP_DIR

Setting it will cause the SARIF files that would be uploaded to be
dumped to the specified directory as `upload.sarif` or
`upload.quality.sarif`. Crucially, this happens even if uploads are
disabled, which is useful for testing.
This commit is contained in:
Paolo Tranquilli
2025-09-09 15:05:40 +02:00
parent 52ddbe1e52
commit a7fb336064
7 changed files with 699 additions and 396 deletions

210
lib/analyze-action.js generated
View File

@@ -95562,94 +95562,128 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
}
return payloadObj;
}
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) {
async function maybeUploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const sarifPaths = getSarifFilePaths(
inputSarifPath,
uploadTarget.sarifPredicate
);
return uploadSpecifiedFiles(
return maybeUploadSpecifiedFiles(
sarifPaths,
checkoutPath,
category,
features,
logger,
uploadTarget
uploadTarget,
uploadKind
);
}
async function uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget) {
logger.startGroup(`Uploading ${uploadTarget.name} results`);
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
async function maybeUploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const dumpDir = process.env["CODEQL_ACTION_SARIF_DUMP_DIR" /* SARIF_DUMP_DIR */];
const upload = uploadKind === "always";
if (!upload && !dumpDir) {
logger.info(`Skipping upload of ${uploadTarget.name} results`);
return void 0;
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
category,
analysisKey,
environment
logger.startGroup(`Processing ${uploadTarget.name} results`);
try {
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
category,
analysisKey,
environment
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
if (dumpDir) {
dumpSarifFile(sarif, dumpDir, logger, uploadTarget);
}
if (!upload) {
logger.info(
`Skipping upload of ${uploadTarget.name} results because upload kind is "${uploadKind}"`
);
return void 0;
}
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
logger,
uploadTarget.target
);
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
} finally {
logger.endGroup();
}
}
function dumpSarifFile(sarif, outputDir, logger, uploadTarget) {
if (!fs18.existsSync(outputDir)) {
fs18.mkdirSync(outputDir, { recursive: true });
} else if (!fs18.lstatSync(outputDir).isDirectory()) {
throw new ConfigurationError(
`The path specified by the CODEQL_ACTION_SARIF_DUMP_DIR environment variable exists and is not a directory: ${outputDir}`
);
}
const outputFile = path18.resolve(
outputDir,
`upload${uploadTarget.sarifExtension}`
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
logger,
uploadTarget.target
);
logger.endGroup();
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
logger.info(`Dumping processed SARIF file to ${outputFile}`);
fs18.writeFileSync(outputFile, JSON.stringify(sarif, null, 2));
}
var STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1e3;
var STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1e3;
@@ -95995,21 +96029,26 @@ async function run() {
}
core14.setOutput("db-locations", dbLocations);
core14.setOutput("sarif-output", import_path4.default.resolve(outputDir));
const uploadInput = getOptionalInput("upload");
if (runStats && getUploadValue(uploadInput) === "always") {
const uploadInput = getUploadValue(
getOptionalInput("upload")
);
if (runStats) {
if (isCodeScanningEnabled(config)) {
uploadResult = await uploadFiles(
uploadResult = await maybeUploadFiles(
outputDir,
getRequiredInput("checkout_path"),
getOptionalInput("category"),
features,
logger,
CodeScanning
CodeScanning,
uploadInput
);
core14.setOutput("sarif-id", uploadResult.sarifID);
if (uploadResult) {
core14.setOutput("sarif-id", uploadResult.sarifID);
}
}
if (isCodeQualityEnabled(config)) {
const qualityUploadResult = await uploadFiles(
const qualityUploadResult = await maybeUploadFiles(
outputDir,
getRequiredInput("checkout_path"),
fixCodeQualityCategory(
@@ -96018,12 +96057,15 @@ async function run() {
),
features,
logger,
CodeQuality
CodeQuality,
uploadInput
);
core14.setOutput("quality-sarif-id", qualityUploadResult.sarifID);
if (qualityUploadResult) {
core14.setOutput("quality-sarif-id", qualityUploadResult.sarifID);
}
}
} else {
logger.info("Not uploading results");
logger.info("No query status report, skipping upload");
}
await uploadOverlayBaseDatabaseToCache(codeql, config, logger);
await uploadDatabases(repositoryNwo, codeql, config, apiDetails, logger);

193
lib/init-action-post.js generated
View File

@@ -133000,93 +133000,138 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
return payloadObj;
}
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) {
return maybeUploadFiles(
inputSarifPath,
checkoutPath,
category,
features,
logger,
uploadTarget,
"always"
);
}
async function maybeUploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const sarifPaths = getSarifFilePaths(
inputSarifPath,
uploadTarget.sarifPredicate
);
return uploadSpecifiedFiles(
return maybeUploadSpecifiedFiles(
sarifPaths,
checkoutPath,
category,
features,
logger,
uploadTarget
uploadTarget,
uploadKind
);
}
async function uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget) {
logger.startGroup(`Uploading ${uploadTarget.name} results`);
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
async function maybeUploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const dumpDir = process.env["CODEQL_ACTION_SARIF_DUMP_DIR" /* SARIF_DUMP_DIR */];
const upload = uploadKind === "always";
if (!upload && !dumpDir) {
logger.info(`Skipping upload of ${uploadTarget.name} results`);
return void 0;
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
category,
analysisKey,
environment
logger.startGroup(`Processing ${uploadTarget.name} results`);
try {
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
category,
analysisKey,
environment
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
if (dumpDir) {
dumpSarifFile(sarif, dumpDir, logger, uploadTarget);
}
if (!upload) {
logger.info(
`Skipping upload of ${uploadTarget.name} results because upload kind is "${uploadKind}"`
);
return void 0;
}
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
logger,
uploadTarget.target
);
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
} finally {
logger.endGroup();
}
}
function dumpSarifFile(sarif, outputDir, logger, uploadTarget) {
if (!fs17.existsSync(outputDir)) {
fs17.mkdirSync(outputDir, { recursive: true });
} else if (!fs17.lstatSync(outputDir).isDirectory()) {
throw new ConfigurationError(
`The path specified by the CODEQL_ACTION_SARIF_DUMP_DIR environment variable exists and is not a directory: ${outputDir}`
);
}
const outputFile = path17.resolve(
outputDir,
`upload${uploadTarget.sarifExtension}`
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
logger,
uploadTarget.target
);
logger.endGroup();
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
logger.info(`Dumping processed SARIF file to ${outputFile}`);
fs17.writeFileSync(outputFile, JSON.stringify(sarif, null, 2));
}
var STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1e3;
var STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1e3;

202
lib/upload-lib.js generated
View File

@@ -84782,6 +84782,7 @@ __export(upload_lib_exports, {
buildPayload: () => buildPayload,
findSarifFilesInDir: () => findSarifFilesInDir,
getSarifFilePaths: () => getSarifFilePaths,
maybeUploadFiles: () => maybeUploadFiles,
populateRunAutomationDetails: () => populateRunAutomationDetails,
readSarifFile: () => readSarifFile,
shouldConsiderConfigurationError: () => shouldConsiderConfigurationError,
@@ -92372,93 +92373,149 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
return payloadObj;
}
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) {
return maybeUploadFiles(
inputSarifPath,
checkoutPath,
category,
features,
logger,
uploadTarget,
"always"
);
}
async function maybeUploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const sarifPaths = getSarifFilePaths(
inputSarifPath,
uploadTarget.sarifPredicate
);
return uploadSpecifiedFiles(
return maybeUploadSpecifiedFiles(
sarifPaths,
checkoutPath,
category,
features,
logger,
uploadTarget
uploadTarget,
uploadKind
);
}
async function uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget) {
logger.startGroup(`Uploading ${uploadTarget.name} results`);
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
return maybeUploadSpecifiedFiles(
sarifPaths,
checkoutPath,
category,
analysisKey,
environment
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
features,
logger,
uploadTarget.target
uploadTarget,
"always"
);
logger.endGroup();
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
}
async function maybeUploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const dumpDir = process.env["CODEQL_ACTION_SARIF_DUMP_DIR" /* SARIF_DUMP_DIR */];
const upload = uploadKind === "always";
if (!upload && !dumpDir) {
logger.info(`Skipping upload of ${uploadTarget.name} results`);
return void 0;
}
logger.startGroup(`Processing ${uploadTarget.name} results`);
try {
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
category,
analysisKey,
environment
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
if (dumpDir) {
dumpSarifFile(sarif, dumpDir, logger, uploadTarget);
}
if (!upload) {
logger.info(
`Skipping upload of ${uploadTarget.name} results because upload kind is "${uploadKind}"`
);
return void 0;
}
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
logger,
uploadTarget.target
);
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
} finally {
logger.endGroup();
}
}
function dumpSarifFile(sarif, outputDir, logger, uploadTarget) {
if (!fs13.existsSync(outputDir)) {
fs13.mkdirSync(outputDir, { recursive: true });
} else if (!fs13.lstatSync(outputDir).isDirectory()) {
throw new ConfigurationError(
`The path specified by the CODEQL_ACTION_SARIF_DUMP_DIR environment variable exists and is not a directory: ${outputDir}`
);
}
const outputFile = path14.resolve(
outputDir,
`upload${uploadTarget.sarifExtension}`
);
logger.info(`Dumping processed SARIF file to ${outputFile}`);
fs13.writeFileSync(outputFile, JSON.stringify(sarif, null, 2));
}
var STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1e3;
var STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1e3;
@@ -92617,6 +92674,7 @@ function filterAlertsByDiffRange(logger, sarif) {
buildPayload,
findSarifFilesInDir,
getSarifFilePaths,
maybeUploadFiles,
populateRunAutomationDetails,
readSarifFile,
shouldConsiderConfigurationError,

View File

@@ -93073,93 +93073,149 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
return payloadObj;
}
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) {
return maybeUploadFiles(
inputSarifPath,
checkoutPath,
category,
features,
logger,
uploadTarget,
"always"
);
}
async function maybeUploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const sarifPaths = getSarifFilePaths(
inputSarifPath,
uploadTarget.sarifPredicate
);
return uploadSpecifiedFiles(
return maybeUploadSpecifiedFiles(
sarifPaths,
checkoutPath,
category,
features,
logger,
uploadTarget
uploadTarget,
uploadKind
);
}
async function uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget) {
logger.startGroup(`Uploading ${uploadTarget.name} results`);
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
return maybeUploadSpecifiedFiles(
sarifPaths,
checkoutPath,
category,
analysisKey,
environment
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
features,
logger,
uploadTarget.target
uploadTarget,
"always"
);
logger.endGroup();
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
}
async function maybeUploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget, uploadKind) {
const dumpDir = process.env["CODEQL_ACTION_SARIF_DUMP_DIR" /* SARIF_DUMP_DIR */];
const upload = uploadKind === "always";
if (!upload && !dumpDir) {
logger.info(`Skipping upload of ${uploadTarget.name} results`);
return void 0;
}
logger.startGroup(`Processing ${uploadTarget.name} results`);
try {
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
const gitHubVersion = await getGitHubVersion();
let sarif;
if (sarifPaths.length > 1) {
for (const sarifPath of sarifPaths) {
const parsedSarif = readSarifFile(sarifPath);
validateSarifFileSchema(parsedSarif, sarifPath, logger);
}
sarif = await combineSarifFilesUsingCLI(
sarifPaths,
gitHubVersion,
features,
logger
);
} else {
const sarifPath = sarifPaths[0];
sarif = readSarifFile(sarifPath);
validateSarifFileSchema(sarif, sarifPath, logger);
await throwIfCombineSarifFilesDisabled([sarif], gitHubVersion);
}
sarif = filterAlertsByDiffRange(logger, sarif);
sarif = await addFingerprints(sarif, checkoutPath, logger);
const analysisKey = await getAnalysisKey();
const environment = getRequiredInput("matrix");
sarif = populateRunAutomationDetails(
sarif,
category,
analysisKey,
environment
);
const toolNames = getToolNames(sarif);
logger.debug(`Validating that each SARIF run has a unique category`);
validateUniqueCategory(sarif, uploadTarget.sentinelPrefix);
if (dumpDir) {
dumpSarifFile(sarif, dumpDir, logger, uploadTarget);
}
if (!upload) {
logger.info(
`Skipping upload of ${uploadTarget.name} results because upload kind is "${uploadKind}"`
);
return void 0;
}
logger.debug(`Serializing SARIF for upload`);
const sarifPayload = JSON.stringify(sarif);
logger.debug(`Compressing serialized SARIF`);
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
const checkoutURI = url.pathToFileURL(checkoutPath).href;
const payload = buildPayload(
await getCommitOid(checkoutPath),
await getRef(),
analysisKey,
getRequiredEnvParam("GITHUB_WORKFLOW"),
zippedSarif,
getWorkflowRunID(),
getWorkflowRunAttempt(),
checkoutURI,
environment,
toolNames,
await determineBaseBranchHeadCommitOid()
);
const rawUploadSizeBytes = sarifPayload.length;
logger.debug(`Raw upload size: ${rawUploadSizeBytes} bytes`);
const zippedUploadSizeBytes = zippedSarif.length;
logger.debug(`Base64 zipped upload size: ${zippedUploadSizeBytes} bytes`);
const numResultInSarif = countResultsInSarif(sarifPayload);
logger.debug(`Number of results in upload: ${numResultInSarif}`);
const sarifID = await uploadPayload(
payload,
getRepositoryNwo(),
logger,
uploadTarget.target
);
return {
statusReport: {
raw_upload_size_bytes: rawUploadSizeBytes,
zipped_upload_size_bytes: zippedUploadSizeBytes,
num_results_in_sarif: numResultInSarif
},
sarifID
};
} finally {
logger.endGroup();
}
}
function dumpSarifFile(sarif, outputDir, logger, uploadTarget) {
if (!fs14.existsSync(outputDir)) {
fs14.mkdirSync(outputDir, { recursive: true });
} else if (!fs14.lstatSync(outputDir).isDirectory()) {
throw new ConfigurationError(
`The path specified by the CODEQL_ACTION_SARIF_DUMP_DIR environment variable exists and is not a directory: ${outputDir}`
);
}
const outputFile = path15.resolve(
outputDir,
`upload${uploadTarget.sarifExtension}`
);
logger.info(`Dumping processed SARIF file to ${outputFile}`);
fs14.writeFileSync(outputFile, JSON.stringify(sarif, null, 2));
}
var STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1e3;
var STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1e3;