Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use postProcessSarifFiles and uploadProcessedFiles in uploadSarif
  • Loading branch information
mbg committed Oct 22, 2025
commit 899bf2fd1e2a8cdc62e04f8c35ae6c710522f072
14 changes: 10 additions & 4 deletions lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions lib/upload-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 10 additions & 20 deletions lib/upload-sarif-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ export async function uploadFiles(
/**
* Uploads the given array of SARIF files.
*/
export async function uploadSpecifiedFiles(
async function uploadSpecifiedFiles(
sarifPaths: string[],
checkoutPath: string,
category: string | undefined,
Expand Down
44 changes: 25 additions & 19 deletions src/upload-sarif.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,29 @@ const uploadSarifMacro = test.macro({

const toFullPath = (filename: string) => path.join(tempDir, filename);

const uploadSpecifiedFiles = sinon.stub(
const postProcessSarifFiles = sinon.stub(
uploadLib,
"uploadSpecifiedFiles",
"postProcessSarifFiles",
);
const uploadProcessedFiles = sinon.stub(
uploadLib,
"uploadProcessedFiles",
);

for (const analysisKind of Object.values(AnalysisKind)) {
uploadSpecifiedFiles
const analysisConfig = getAnalysisConfig(analysisKind);
postProcessSarifFiles
.withArgs(
logger,
sinon.match.any,
sinon.match.any,
sinon.match.any,
features,
logger,
getAnalysisConfig(analysisKind),
sinon.match.any,
analysisConfig,
)
.resolves({ sarif: { runs: [] }, analysisKey: "", environment: "" });
uploadProcessedFiles
.withArgs(logger, sinon.match.any, analysisConfig, sinon.match.any)
.resolves(expectedResult[analysisKind as AnalysisKind]?.uploadResult);
}

Expand All @@ -63,35 +71,33 @@ const uploadSarifMacro = test.macro({
if (analysisKindResult) {
// We are expecting a result for this analysis kind, check that we have it.
t.deepEqual(actual[analysisKind], analysisKindResult.uploadResult);
// Additionally, check that the mocked `uploadSpecifiedFiles` was called with only the file paths
// Additionally, check that the mocked `postProcessSarifFiles` was called with only the file paths
// that we expected it to be called with.
t.assert(
uploadSpecifiedFiles.calledWith(
postProcessSarifFiles.calledWith(
logger,
features,
sinon.match.any,
analysisKindResult.expectedFiles?.map(toFullPath) ??
fullSarifPaths,
sinon.match.any,
sinon.match.any,
features,
logger,
getAnalysisConfig(analysisKind),
),
);
} else {
// Otherwise, we are not expecting a result for this analysis kind. However, note that `undefined`
// is also returned by our mocked `uploadSpecifiedFiles` when there is no expected result for this
// is also returned by our mocked `uploadProcessedFiles` when there is no expected result for this
// analysis kind.
t.is(actual[analysisKind], undefined);
// Therefore, we also check that the mocked `uploadSpecifiedFiles` was not called for this analysis kind.
// Therefore, we also check that the mocked `uploadProcessedFiles` was not called for this analysis kind.
t.assert(
!uploadSpecifiedFiles.calledWith(
sinon.match.any,
sinon.match.any,
sinon.match.any,
features,
!uploadProcessedFiles.calledWith(
logger,
sinon.match.any,
getAnalysisConfig(analysisKind),
sinon.match.any,
),
`uploadSpecifiedFiles was called for ${analysisKind}, but should not have been.`,
`uploadProcessedFiles was called for ${analysisKind}, but should not have been.`,
);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/upload-sarif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ export async function uploadSarif(
sarifGroups,
)) {
const analysisConfig = analyses.getAnalysisConfig(analysisKind);
uploadResults[analysisKind] = await upload_lib.uploadSpecifiedFiles(
sarifFiles,
const processingResults = await upload_lib.postProcessSarifFiles(
logger,
features,
checkoutPath,
sarifFiles,
category,
features,
analysisConfig,
);

uploadResults[analysisKind] = await upload_lib.uploadProcessedFiles(
logger,
checkoutPath,
analysisConfig,
processingResults,
);
}

Expand Down