Remove redundant layer from upload files functions
This commit is contained in:
parent
79e9a50e51
commit
6c2a71ced3
15 changed files with 54 additions and 80 deletions
|
|
@ -301,7 +301,7 @@ async function run() {
|
|||
core.setOutput("sarif-output", path.resolve(outputDir));
|
||||
const uploadInput = actionsUtil.getOptionalInput("upload");
|
||||
if (runStats && actionsUtil.getUploadValue(uploadInput) === "always") {
|
||||
uploadResult = await uploadLib.uploadFromActions(
|
||||
uploadResult = await uploadLib.uploadFiles(
|
||||
outputDir,
|
||||
actionsUtil.getRequiredInput("checkout_path"),
|
||||
actionsUtil.getOptionalInput("category"),
|
||||
|
|
|
|||
|
|
@ -368,8 +368,8 @@ async function testFailedSarifUpload(
|
|||
|
||||
sinon.stub(workflow, "getWorkflow").resolves(actionsWorkflow);
|
||||
|
||||
const uploadFromActions = sinon.stub(uploadLib, "uploadFromActions");
|
||||
uploadFromActions.resolves({
|
||||
const uploadFiles = sinon.stub(uploadLib, "uploadFiles");
|
||||
uploadFiles.resolves({
|
||||
sarifID: "42",
|
||||
statusReport: { raw_upload_size_bytes: 20, zipped_upload_size_bytes: 10 },
|
||||
} as uploadLib.UploadResult);
|
||||
|
|
@ -414,13 +414,13 @@ async function testFailedSarifUpload(
|
|||
);
|
||||
}
|
||||
t.true(
|
||||
uploadFromActions.calledOnceWith(
|
||||
uploadFiles.calledOnceWith(
|
||||
sinon.match.string,
|
||||
sinon.match.string,
|
||||
category,
|
||||
sinon.match.any,
|
||||
),
|
||||
`Actual args were: ${uploadFromActions.args}`,
|
||||
`Actual args were: ${uploadFiles.args}`,
|
||||
);
|
||||
t.true(
|
||||
waitForProcessing.calledOnceWith(sinon.match.any, "42", sinon.match.any, {
|
||||
|
|
@ -429,7 +429,7 @@ async function testFailedSarifUpload(
|
|||
);
|
||||
} else {
|
||||
t.true(diagnosticsExportStub.notCalled);
|
||||
t.true(uploadFromActions.notCalled);
|
||||
t.true(uploadFiles.notCalled);
|
||||
t.true(waitForProcessing.notCalled);
|
||||
}
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ async function maybeUploadFailedSarif(
|
|||
}
|
||||
|
||||
logger.info(`Uploading failed SARIF file ${sarifFile}`);
|
||||
const uploadResult = await uploadLib.uploadFromActions(
|
||||
const uploadResult = await uploadLib.uploadFiles(
|
||||
sarifFile,
|
||||
checkoutPath,
|
||||
category,
|
||||
|
|
|
|||
|
|
@ -391,32 +391,6 @@ export function findSarifFilesInDir(sarifPath: string): string[] {
|
|||
return sarifFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a single SARIF file or a directory of SARIF files depending on what `sarifPath` refers
|
||||
* to.
|
||||
*/
|
||||
export async function uploadFromActions(
|
||||
sarifPath: string,
|
||||
checkoutPath: string,
|
||||
category: string | undefined,
|
||||
logger: Logger,
|
||||
): Promise<UploadResult> {
|
||||
return await uploadFiles(
|
||||
getSarifFilePaths(sarifPath),
|
||||
parseRepositoryNwo(util.getRequiredEnvParam("GITHUB_REPOSITORY")),
|
||||
await actionsUtil.getCommitOid(checkoutPath),
|
||||
await actionsUtil.getRef(),
|
||||
await api.getAnalysisKey(),
|
||||
category,
|
||||
util.getRequiredEnvParam("GITHUB_WORKFLOW"),
|
||||
actionsUtil.getWorkflowRunID(),
|
||||
actionsUtil.getWorkflowRunAttempt(),
|
||||
checkoutPath,
|
||||
actionsUtil.getRequiredInput("matrix"),
|
||||
logger,
|
||||
);
|
||||
}
|
||||
|
||||
function getSarifFilePaths(sarifPath: string) {
|
||||
if (!fs.existsSync(sarifPath)) {
|
||||
// This is always a configuration error, even for first-party runs.
|
||||
|
|
@ -563,22 +537,21 @@ export function buildPayload(
|
|||
return payloadObj;
|
||||
}
|
||||
|
||||
// Uploads the given set of sarif files.
|
||||
// Returns true iff the upload occurred and succeeded
|
||||
async function uploadFiles(
|
||||
sarifFiles: string[],
|
||||
repositoryNwo: RepositoryNwo,
|
||||
commitOid: string,
|
||||
ref: string,
|
||||
analysisKey: string,
|
||||
/**
|
||||
* Uploads a single SARIF file or a directory of SARIF files depending on what `sarifPath` refers
|
||||
* to.
|
||||
*/
|
||||
export async function uploadFiles(
|
||||
sarifPath: string,
|
||||
checkoutPath: string,
|
||||
category: string | undefined,
|
||||
analysisName: string | undefined,
|
||||
workflowRunID: number,
|
||||
workflowRunAttempt: number,
|
||||
sourceRoot: string,
|
||||
environment: string | undefined,
|
||||
logger: Logger,
|
||||
): Promise<UploadResult> {
|
||||
const repositoryNwo = parseRepositoryNwo(
|
||||
util.getRequiredEnvParam("GITHUB_REPOSITORY"),
|
||||
);
|
||||
const sarifFiles = getSarifFilePaths(sarifPath);
|
||||
|
||||
logger.startGroup("Uploading results");
|
||||
logger.info(`Processing sarif files: ${JSON.stringify(sarifFiles)}`);
|
||||
|
||||
|
|
@ -601,8 +574,10 @@ async function uploadFiles(
|
|||
features,
|
||||
logger,
|
||||
);
|
||||
sarif = await fingerprints.addFingerprints(sarif, sourceRoot, logger);
|
||||
sarif = await fingerprints.addFingerprints(sarif, checkoutPath, logger);
|
||||
|
||||
const analysisKey = await api.getAnalysisKey();
|
||||
const environment = actionsUtil.getRequiredInput("matrix");
|
||||
sarif = populateRunAutomationDetails(
|
||||
sarif,
|
||||
category,
|
||||
|
|
@ -618,16 +593,16 @@ async function uploadFiles(
|
|||
const sarifPayload = JSON.stringify(sarif);
|
||||
logger.debug(`Compressing serialized SARIF`);
|
||||
const zippedSarif = zlib.gzipSync(sarifPayload).toString("base64");
|
||||
const checkoutURI = fileUrl(sourceRoot);
|
||||
const checkoutURI = fileUrl(checkoutPath);
|
||||
|
||||
const payload = buildPayload(
|
||||
commitOid,
|
||||
ref,
|
||||
await actionsUtil.getCommitOid(checkoutPath),
|
||||
await actionsUtil.getRef(),
|
||||
analysisKey,
|
||||
analysisName,
|
||||
category,
|
||||
zippedSarif,
|
||||
workflowRunID,
|
||||
workflowRunAttempt,
|
||||
actionsUtil.getWorkflowRunID(),
|
||||
actionsUtil.getWorkflowRunAttempt(),
|
||||
checkoutURI,
|
||||
environment,
|
||||
toolNames,
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ async function run() {
|
|||
}
|
||||
|
||||
try {
|
||||
const uploadResult = await upload_lib.uploadFromActions(
|
||||
const uploadResult = await upload_lib.uploadFiles(
|
||||
actionsUtil.getRequiredInput("sarif_file"),
|
||||
actionsUtil.getRequiredInput("checkout_path"),
|
||||
actionsUtil.getOptionalInput("category"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue