Skip to content

Commit 09d87ee

Browse files
committed
Remove redundant layer from upload files functions
1 parent 79e9a50 commit 09d87ee

File tree

4 files changed

+24
-49
lines changed

4 files changed

+24
-49
lines changed

Diff for: src/analyze-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ async function run() {
301301
core.setOutput("sarif-output", path.resolve(outputDir));
302302
const uploadInput = actionsUtil.getOptionalInput("upload");
303303
if (runStats && actionsUtil.getUploadValue(uploadInput) === "always") {
304-
uploadResult = await uploadLib.uploadFromActions(
304+
uploadResult = await uploadLib.uploadFiles(
305305
outputDir,
306306
actionsUtil.getRequiredInput("checkout_path"),
307307
actionsUtil.getOptionalInput("category"),

Diff for: src/init-action-post-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async function maybeUploadFailedSarif(
104104
}
105105

106106
logger.info(`Uploading failed SARIF file ${sarifFile}`);
107-
const uploadResult = await uploadLib.uploadFromActions(
107+
const uploadResult = await uploadLib.uploadFiles(
108108
sarifFile,
109109
checkoutPath,
110110
category,

Diff for: src/upload-lib.ts

+21-46
Original file line numberDiff line numberDiff line change
@@ -391,32 +391,6 @@ export function findSarifFilesInDir(sarifPath: string): string[] {
391391
return sarifFiles;
392392
}
393393

394-
/**
395-
* Uploads a single SARIF file or a directory of SARIF files depending on what `sarifPath` refers
396-
* to.
397-
*/
398-
export async function uploadFromActions(
399-
sarifPath: string,
400-
checkoutPath: string,
401-
category: string | undefined,
402-
logger: Logger,
403-
): Promise<UploadResult> {
404-
return await uploadFiles(
405-
getSarifFilePaths(sarifPath),
406-
parseRepositoryNwo(util.getRequiredEnvParam("GITHUB_REPOSITORY")),
407-
await actionsUtil.getCommitOid(checkoutPath),
408-
await actionsUtil.getRef(),
409-
await api.getAnalysisKey(),
410-
category,
411-
util.getRequiredEnvParam("GITHUB_WORKFLOW"),
412-
actionsUtil.getWorkflowRunID(),
413-
actionsUtil.getWorkflowRunAttempt(),
414-
checkoutPath,
415-
actionsUtil.getRequiredInput("matrix"),
416-
logger,
417-
);
418-
}
419-
420394
function getSarifFilePaths(sarifPath: string) {
421395
if (!fs.existsSync(sarifPath)) {
422396
// This is always a configuration error, even for first-party runs.
@@ -563,22 +537,21 @@ export function buildPayload(
563537
return payloadObj;
564538
}
565539

566-
// Uploads the given set of sarif files.
567-
// Returns true iff the upload occurred and succeeded
568-
async function uploadFiles(
569-
sarifFiles: string[],
570-
repositoryNwo: RepositoryNwo,
571-
commitOid: string,
572-
ref: string,
573-
analysisKey: string,
540+
/**
541+
* Uploads a single SARIF file or a directory of SARIF files depending on what `sarifPath` refers
542+
* to.
543+
*/
544+
export async function uploadFiles(
545+
sarifPath: string,
546+
checkoutPath: string,
574547
category: string | undefined,
575-
analysisName: string | undefined,
576-
workflowRunID: number,
577-
workflowRunAttempt: number,
578-
sourceRoot: string,
579-
environment: string | undefined,
580548
logger: Logger,
581549
): Promise<UploadResult> {
550+
const repositoryNwo = parseRepositoryNwo(
551+
util.getRequiredEnvParam("GITHUB_REPOSITORY"),
552+
);
553+
const sarifFiles = getSarifFilePaths(sarifPath);
554+
582555
logger.startGroup("Uploading results");
583556
logger.info(`Processing sarif files: ${JSON.stringify(sarifFiles)}`);
584557

@@ -601,8 +574,10 @@ async function uploadFiles(
601574
features,
602575
logger,
603576
);
604-
sarif = await fingerprints.addFingerprints(sarif, sourceRoot, logger);
577+
sarif = await fingerprints.addFingerprints(sarif, checkoutPath, logger);
605578

579+
const analysisKey = await api.getAnalysisKey();
580+
const environment = actionsUtil.getRequiredInput("matrix");
606581
sarif = populateRunAutomationDetails(
607582
sarif,
608583
category,
@@ -618,16 +593,16 @@ async function uploadFiles(
618593
const sarifPayload = JSON.stringify(sarif);
619594
logger.debug(`Compressing serialized SARIF`);
620595
const zippedSarif = zlib.gzipSync(sarifPayload).toString("base64");
621-
const checkoutURI = fileUrl(sourceRoot);
596+
const checkoutURI = fileUrl(checkoutPath);
622597

623598
const payload = buildPayload(
624-
commitOid,
625-
ref,
599+
await actionsUtil.getCommitOid(checkoutPath),
600+
await actionsUtil.getRef(),
626601
analysisKey,
627-
analysisName,
602+
category,
628603
zippedSarif,
629-
workflowRunID,
630-
workflowRunAttempt,
604+
actionsUtil.getWorkflowRunID(),
605+
actionsUtil.getWorkflowRunAttempt(),
631606
checkoutURI,
632607
environment,
633608
toolNames,

Diff for: src/upload-sarif-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async function run() {
7171
}
7272

7373
try {
74-
const uploadResult = await upload_lib.uploadFromActions(
74+
const uploadResult = await upload_lib.uploadFiles(
7575
actionsUtil.getRequiredInput("sarif_file"),
7676
actionsUtil.getRequiredInput("checkout_path"),
7777
actionsUtil.getOptionalInput("category"),

0 commit comments

Comments
 (0)