mirror of
https://github.com/github/codeql-action.git
synced 2025-12-31 19:50:32 +08:00
Consistently use "post-processing"
This commit is contained in:
@@ -52,7 +52,7 @@ import {
|
||||
} from "./trap-caching";
|
||||
import * as uploadLib from "./upload-lib";
|
||||
import { UploadResult } from "./upload-lib";
|
||||
import { processAndUploadSarif } from "./upload-sarif";
|
||||
import { postProcessAndUploadSarif } from "./upload-sarif";
|
||||
import * as util from "./util";
|
||||
|
||||
interface AnalysisStatusReport
|
||||
@@ -352,14 +352,14 @@ async function run() {
|
||||
const category = actionsUtil.getOptionalInput("category");
|
||||
|
||||
if (await features.getValue(Feature.AnalyzeUseNewUpload)) {
|
||||
uploadResults = await processAndUploadSarif(
|
||||
uploadResults = await postProcessAndUploadSarif(
|
||||
logger,
|
||||
features,
|
||||
uploadKind,
|
||||
checkoutPath,
|
||||
outputDir,
|
||||
category,
|
||||
actionsUtil.getOptionalInput("processed-sarif-path"),
|
||||
actionsUtil.getOptionalInput("post-processed-sarif-path"),
|
||||
);
|
||||
} else if (uploadKind === "always") {
|
||||
uploadResults = {};
|
||||
|
||||
@@ -715,7 +715,7 @@ export async function postProcessSarifFiles(
|
||||
category: string | undefined,
|
||||
analysis: analyses.AnalysisConfig,
|
||||
): Promise<PostProcessingResults> {
|
||||
logger.info(`Processing sarif files: ${JSON.stringify(sarifPaths)}`);
|
||||
logger.info(`Post-processing sarif files: ${JSON.stringify(sarifPaths)}`);
|
||||
|
||||
const gitHubVersion = await getGitHubVersion();
|
||||
|
||||
@@ -760,18 +760,18 @@ export async function postProcessSarifFiles(
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the processed SARIF file to disk, if needed based on `pathInput` or the `SARIF_DUMP_DIR`.
|
||||
* Writes the post-processed SARIF file to disk, if needed based on `pathInput` or the `SARIF_DUMP_DIR`.
|
||||
*
|
||||
* @param logger The logger to use.
|
||||
* @param pathInput The input provided for `processed-sarif-path`.
|
||||
* @param pathInput The input provided for `post-processed-sarif-path`.
|
||||
* @param uploadTarget The upload target.
|
||||
* @param processingResults The results of post-processing SARIF files.
|
||||
*/
|
||||
export async function writeProcessedFiles(
|
||||
export async function writePostProcessedFiles(
|
||||
logger: Logger,
|
||||
pathInput: string | undefined,
|
||||
uploadTarget: analyses.AnalysisConfig,
|
||||
processingResults: PostProcessingResults,
|
||||
postProcessingResults: PostProcessingResults,
|
||||
) {
|
||||
// If there's an explicit input, use that. Otherwise, use the value from the environment variable.
|
||||
const outputPath = pathInput || process.env[EnvVar.SARIF_DUMP_DIR];
|
||||
@@ -779,13 +779,13 @@ export async function writeProcessedFiles(
|
||||
// If we have an output path, write the SARIF file to it.
|
||||
if (outputPath !== undefined) {
|
||||
dumpSarifFile(
|
||||
JSON.stringify(processingResults.sarif),
|
||||
JSON.stringify(postProcessingResults.sarif),
|
||||
outputPath,
|
||||
logger,
|
||||
uploadTarget,
|
||||
);
|
||||
} else {
|
||||
logger.debug(`Not writing processed SARIF files.`);
|
||||
logger.debug(`Not writing post-processed SARIF files.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,7 +836,7 @@ async function uploadSpecifiedFiles(
|
||||
uploadTarget,
|
||||
);
|
||||
|
||||
return uploadProcessedFiles(
|
||||
return uploadPostProcessedFiles(
|
||||
logger,
|
||||
checkoutPath,
|
||||
uploadTarget,
|
||||
@@ -845,25 +845,24 @@ async function uploadSpecifiedFiles(
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads the results of processing SARIF files to the specified upload target.
|
||||
* Uploads the results of post-processing SARIF files to the specified upload target.
|
||||
*
|
||||
* @param logger The logger to use.
|
||||
* @param checkoutPath The path at which the repository was checked out.
|
||||
* @param uploadTarget The analysis configuration.
|
||||
* @param processingResults The results of post-processing SARIF files.
|
||||
* @param postProcessingResults The results of post-processing SARIF files.
|
||||
*
|
||||
* @returns The results of uploading the `processingResults` to `uploadTarget`.
|
||||
* @returns The results of uploading the `postProcessingResults` to `uploadTarget`.
|
||||
*/
|
||||
export async function uploadProcessedFiles(
|
||||
export async function uploadPostProcessedFiles(
|
||||
logger: Logger,
|
||||
checkoutPath: string,
|
||||
uploadTarget: analyses.AnalysisConfig,
|
||||
processingResults: PostProcessingResults,
|
||||
postProcessingResults: PostProcessingResults,
|
||||
): Promise<UploadResult> {
|
||||
logger.startGroup(`Uploading ${uploadTarget.name} results`);
|
||||
|
||||
const sarif = processingResults.sarif;
|
||||
|
||||
const sarif = postProcessingResults.sarif;
|
||||
const toolNames = util.getToolNames(sarif);
|
||||
|
||||
logger.debug(`Validating that each SARIF run has a unique category`);
|
||||
@@ -878,13 +877,13 @@ export async function uploadProcessedFiles(
|
||||
const payload = buildPayload(
|
||||
await gitUtils.getCommitOid(checkoutPath),
|
||||
await gitUtils.getRef(),
|
||||
processingResults.analysisKey,
|
||||
postProcessingResults.analysisKey,
|
||||
util.getRequiredEnvParam("GITHUB_WORKFLOW"),
|
||||
zippedSarif,
|
||||
actionsUtil.getWorkflowRunID(),
|
||||
actionsUtil.getWorkflowRunAttempt(),
|
||||
checkoutURI,
|
||||
processingResults.environment,
|
||||
postProcessingResults.environment,
|
||||
toolNames,
|
||||
await gitUtils.determineBaseBranchHeadCommitOid(),
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
isThirdPartyAnalysis,
|
||||
} from "./status-report";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import { processAndUploadSarif } from "./upload-sarif";
|
||||
import { postProcessAndUploadSarif } from "./upload-sarif";
|
||||
import {
|
||||
ConfigurationError,
|
||||
checkActionVersion,
|
||||
@@ -90,7 +90,7 @@ async function run() {
|
||||
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
|
||||
const category = actionsUtil.getOptionalInput("category");
|
||||
|
||||
const uploadResults = await processAndUploadSarif(
|
||||
const uploadResults = await postProcessAndUploadSarif(
|
||||
logger,
|
||||
features,
|
||||
"always",
|
||||
|
||||
@@ -9,7 +9,7 @@ import { getRunnerLogger } from "./logging";
|
||||
import { createFeatures, setupTests } from "./testing-utils";
|
||||
import { UploadResult } from "./upload-lib";
|
||||
import * as uploadLib from "./upload-lib";
|
||||
import { processAndUploadSarif } from "./upload-sarif";
|
||||
import { postProcessAndUploadSarif } from "./upload-sarif";
|
||||
import * as util from "./util";
|
||||
|
||||
setupTests(test);
|
||||
@@ -39,7 +39,7 @@ function mockPostProcessSarifFiles() {
|
||||
return postProcessSarifFiles;
|
||||
}
|
||||
|
||||
const processAndUploadSarifMacro = test.macro({
|
||||
const postProcessAndUploadSarifMacro = test.macro({
|
||||
exec: async (
|
||||
t: ExecutionContext<unknown>,
|
||||
sarifFiles: string[],
|
||||
@@ -54,14 +54,14 @@ const processAndUploadSarifMacro = test.macro({
|
||||
const toFullPath = (filename: string) => path.join(tempDir, filename);
|
||||
|
||||
const postProcessSarifFiles = mockPostProcessSarifFiles();
|
||||
const uploadProcessedFiles = sinon.stub(
|
||||
const uploadPostProcessedFiles = sinon.stub(
|
||||
uploadLib,
|
||||
"uploadProcessedFiles",
|
||||
"uploadPostProcessedFiles",
|
||||
);
|
||||
|
||||
for (const analysisKind of Object.values(AnalysisKind)) {
|
||||
const analysisConfig = getAnalysisConfig(analysisKind);
|
||||
uploadProcessedFiles
|
||||
uploadPostProcessedFiles
|
||||
.withArgs(logger, sinon.match.any, analysisConfig, sinon.match.any)
|
||||
.resolves(expectedResult[analysisKind as AnalysisKind]?.uploadResult);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ const processAndUploadSarifMacro = test.macro({
|
||||
fs.writeFileSync(sarifFile, "");
|
||||
}
|
||||
|
||||
const actual = await processAndUploadSarif(
|
||||
const actual = await postProcessAndUploadSarif(
|
||||
logger,
|
||||
features,
|
||||
"always",
|
||||
@@ -104,7 +104,7 @@ const processAndUploadSarifMacro = test.macro({
|
||||
t.is(actual[analysisKind], undefined);
|
||||
// Therefore, we also check that the mocked `uploadProcessedFiles` was not called for this analysis kind.
|
||||
t.assert(
|
||||
!uploadProcessedFiles.calledWith(
|
||||
!uploadPostProcessedFiles.calledWith(
|
||||
logger,
|
||||
sinon.match.any,
|
||||
getAnalysisConfig(analysisKind),
|
||||
@@ -121,7 +121,7 @@ const processAndUploadSarifMacro = test.macro({
|
||||
|
||||
test(
|
||||
"SARIF file",
|
||||
processAndUploadSarifMacro,
|
||||
postProcessAndUploadSarifMacro,
|
||||
["test.sarif"],
|
||||
(tempDir) => path.join(tempDir, "test.sarif"),
|
||||
{
|
||||
@@ -136,7 +136,7 @@ test(
|
||||
|
||||
test(
|
||||
"JSON file",
|
||||
processAndUploadSarifMacro,
|
||||
postProcessAndUploadSarifMacro,
|
||||
["test.json"],
|
||||
(tempDir) => path.join(tempDir, "test.json"),
|
||||
{
|
||||
@@ -151,7 +151,7 @@ test(
|
||||
|
||||
test(
|
||||
"Code Scanning files",
|
||||
processAndUploadSarifMacro,
|
||||
postProcessAndUploadSarifMacro,
|
||||
["test.json", "test.sarif"],
|
||||
undefined,
|
||||
{
|
||||
@@ -167,7 +167,7 @@ test(
|
||||
|
||||
test(
|
||||
"Code Quality file",
|
||||
processAndUploadSarifMacro,
|
||||
postProcessAndUploadSarifMacro,
|
||||
["test.quality.sarif"],
|
||||
(tempDir) => path.join(tempDir, "test.quality.sarif"),
|
||||
{
|
||||
@@ -182,7 +182,7 @@ test(
|
||||
|
||||
test(
|
||||
"Mixed files",
|
||||
processAndUploadSarifMacro,
|
||||
postProcessAndUploadSarifMacro,
|
||||
["test.sarif", "test.quality.sarif"],
|
||||
undefined,
|
||||
{
|
||||
@@ -203,7 +203,7 @@ test(
|
||||
},
|
||||
);
|
||||
|
||||
test("processAndUploadSarif doesn't upload if upload is disabled", async (t) => {
|
||||
test("postProcessAndUploadSarif doesn't upload if upload is disabled", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
const features = createFeatures([]);
|
||||
@@ -211,12 +211,15 @@ test("processAndUploadSarif doesn't upload if upload is disabled", async (t) =>
|
||||
const toFullPath = (filename: string) => path.join(tempDir, filename);
|
||||
|
||||
const postProcessSarifFiles = mockPostProcessSarifFiles();
|
||||
const uploadProcessedFiles = sinon.stub(uploadLib, "uploadProcessedFiles");
|
||||
const uploadPostProcessedFiles = sinon.stub(
|
||||
uploadLib,
|
||||
"uploadPostProcessedFiles",
|
||||
);
|
||||
|
||||
fs.writeFileSync(toFullPath("test.sarif"), "");
|
||||
fs.writeFileSync(toFullPath("test.quality.sarif"), "");
|
||||
|
||||
const actual = await processAndUploadSarif(
|
||||
const actual = await postProcessAndUploadSarif(
|
||||
logger,
|
||||
features,
|
||||
"never",
|
||||
@@ -226,11 +229,11 @@ test("processAndUploadSarif doesn't upload if upload is disabled", async (t) =>
|
||||
|
||||
t.truthy(actual);
|
||||
t.assert(postProcessSarifFiles.calledTwice);
|
||||
t.assert(uploadProcessedFiles.notCalled);
|
||||
t.assert(uploadPostProcessedFiles.notCalled);
|
||||
});
|
||||
});
|
||||
|
||||
test("processAndUploadSarif writes processed SARIF files if output directory is provided", async (t) => {
|
||||
test("postProcessAndUploadSarif writes post-processed SARIF files if output directory is provided", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
const features = createFeatures([]);
|
||||
@@ -242,22 +245,22 @@ test("processAndUploadSarif writes processed SARIF files if output directory is
|
||||
fs.writeFileSync(toFullPath("test.sarif"), "");
|
||||
fs.writeFileSync(toFullPath("test.quality.sarif"), "");
|
||||
|
||||
const processedOutPath = path.join(tempDir, "processed");
|
||||
const actual = await processAndUploadSarif(
|
||||
const postProcessedOutPath = path.join(tempDir, "post-processed");
|
||||
const actual = await postProcessAndUploadSarif(
|
||||
logger,
|
||||
features,
|
||||
"never",
|
||||
"",
|
||||
tempDir,
|
||||
"",
|
||||
processedOutPath,
|
||||
postProcessedOutPath,
|
||||
);
|
||||
|
||||
t.truthy(actual);
|
||||
t.assert(postProcessSarifFiles.calledTwice);
|
||||
t.assert(fs.existsSync(path.join(processedOutPath, "upload.sarif")));
|
||||
t.assert(fs.existsSync(path.join(postProcessedOutPath, "upload.sarif")));
|
||||
t.assert(
|
||||
fs.existsSync(path.join(processedOutPath, "upload.quality.sarif")),
|
||||
fs.existsSync(path.join(postProcessedOutPath, "upload.quality.sarif")),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ export type UploadSarifResults = Partial<
|
||||
>;
|
||||
|
||||
/**
|
||||
* Finds SARIF files in `sarifPath` and uploads them to the appropriate services.
|
||||
* Finds SARIF files in `sarifPath`, post-processes them, and uploads them to the appropriate services.
|
||||
*
|
||||
* @param logger The logger to use.
|
||||
* @param features Information about enabled features.
|
||||
@@ -19,18 +19,18 @@ export type UploadSarifResults = Partial<
|
||||
* @param checkoutPath The path where the repository was checked out at.
|
||||
* @param sarifPath The path to the file or directory to upload.
|
||||
* @param category The analysis category.
|
||||
* @param processedOutputPath The path to a directory to which the post-processed SARIF files should be written to.
|
||||
* @param postProcessedOutputPath The path to a directory to which the post-processed SARIF files should be written to.
|
||||
*
|
||||
* @returns A partial mapping from analysis kinds to the upload results.
|
||||
*/
|
||||
export async function processAndUploadSarif(
|
||||
export async function postProcessAndUploadSarif(
|
||||
logger: Logger,
|
||||
features: FeatureEnablement,
|
||||
uploadKind: UploadKind,
|
||||
checkoutPath: string,
|
||||
sarifPath: string,
|
||||
category?: string,
|
||||
processedOutputPath?: string,
|
||||
postProcessedOutputPath?: string,
|
||||
): Promise<UploadSarifResults> {
|
||||
const sarifGroups = await upload_lib.getGroupedSarifFilePaths(
|
||||
logger,
|
||||
@@ -42,7 +42,7 @@ export async function processAndUploadSarif(
|
||||
sarifGroups,
|
||||
)) {
|
||||
const analysisConfig = analyses.getAnalysisConfig(analysisKind);
|
||||
const processingResults = await upload_lib.postProcessSarifFiles(
|
||||
const postProcessingResults = await upload_lib.postProcessSarifFiles(
|
||||
logger,
|
||||
features,
|
||||
checkoutPath,
|
||||
@@ -51,22 +51,22 @@ export async function processAndUploadSarif(
|
||||
analysisConfig,
|
||||
);
|
||||
|
||||
// Write the processed SARIF files to disk. This will only write them if needed based on user inputs
|
||||
// Write the post-processed SARIF files to disk. This will only write them if needed based on user inputs
|
||||
// or environment variables.
|
||||
await upload_lib.writeProcessedFiles(
|
||||
await upload_lib.writePostProcessedFiles(
|
||||
logger,
|
||||
processedOutputPath,
|
||||
postProcessedOutputPath,
|
||||
analysisConfig,
|
||||
processingResults,
|
||||
postProcessingResults,
|
||||
);
|
||||
|
||||
// Only perform the actual upload of the processed files, if `uploadKind` is `always`.
|
||||
// Only perform the actual upload of the post-processed files if `uploadKind` is `always`.
|
||||
if (uploadKind === "always") {
|
||||
uploadResults[analysisKind] = await upload_lib.uploadProcessedFiles(
|
||||
uploadResults[analysisKind] = await upload_lib.uploadPostProcessedFiles(
|
||||
logger,
|
||||
checkoutPath,
|
||||
analysisConfig,
|
||||
processingResults,
|
||||
postProcessingResults,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user