diff --git a/lib/entry-points.js b/lib/entry-points.js index b32a43df3..47083757b 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -187079,7 +187079,7 @@ async function maybeUploadFailedSarif(config, repositoryNwo, features, logger2) logger2, { isUnsuccessfulExecution: true } ); - if (uploadResult.sarifID && isInTestMode()) { + if (uploadResult.sarifID && shouldSkipSarifUpload()) { await uploadSarifArtifact(logger2, "test-mode-sarif", { // We defaulted to CodeScanning in the `uploadFiles` call above. sarifFile: getSavedPayloadPath(CodeScanning.kind), @@ -187098,19 +187098,22 @@ async function maybeUploadFailedSarifArtifact(config, features, logger2) { return uploadSarifArtifact(logger2, "sarif-artifact", failedSarif); } async function uploadSarifArtifact(logger2, prefix, failedSarif) { - logger2.info( - `Uploading failed SARIF file ${failedSarif.sarifFile} as artifact` - ); - const gitHubVersion = await getGitHubVersion(); - const client = await getArtifactUploaderClient(logger2, gitHubVersion.type); - const suffix = getArtifactSuffix(getOptionalInput("matrix")); - const name = sanitizeArtifactName(`${prefix}-${suffix}`); - await client.uploadArtifact( - name, - [import_path8.default.normalize(failedSarif.sarifFile)], - import_path8.default.normalize("..") - ); - return { sarifID: name }; + logger2.startGroup(`Uploading failed SARIF file as artifact`); + logger2.info(`Uploading '${failedSarif.sarifFile}' as artifact`); + try { + const gitHubVersion = await getGitHubVersion(); + const client = await getArtifactUploaderClient(logger2, gitHubVersion.type); + const suffix = getArtifactSuffix(getOptionalInput("matrix")); + const name = sanitizeArtifactName(`${prefix}-${suffix}`); + await client.uploadArtifact( + name, + [import_path8.default.normalize(failedSarif.sarifFile)], + import_path8.default.normalize("..") + ); + return { sarifID: name }; + } finally { + logger2.endGroup(); + } } async function tryUploadSarifIfRunFailed(config, repositoryNwo, features, logger2) { if (process.env["CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY" /* ANALYZE_DID_COMPLETE_SUCCESSFULLY */] === "true") { diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 78210793a..ed875ed2d 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -25,7 +25,7 @@ import { } from "./debug-artifacts"; import * as dependencyCaching from "./dependency-caching"; import { getTempDiagnosticPath } from "./diagnostics"; -import { EnvVar, isInTestMode, ReadOnlyEnv } from "./environment"; +import { EnvVar, ReadOnlyEnv } from "./environment"; import { Feature, FeatureEnablement } from "./feature-flags"; import { Logger } from "./logging"; import { OverlayDatabaseMode } from "./overlay/overlay-database-mode"; @@ -46,6 +46,7 @@ import { parseMatrixInput, Result, shouldSkipGenerateFailedSarif, + shouldSkipSarifUpload, Success, wrapError, } from "./util"; @@ -263,10 +264,10 @@ async function maybeUploadFailedSarif( { isUnsuccessfulExecution: true }, ); - // If we are in test mode, `uploadFiles` will not have uploaded the failed SARIF file - // and instead will have written it to disk. Upload it as a workflow artifact so that + // If SARIF upload is disabled for testing, `uploadFiles` will not have uploaded the failed + // SARIF file and instead will have written it to disk. Upload it as a workflow artifact so that // we can inspect it in validation jobs. - if (uploadResult.sarifID && isInTestMode()) { + if (uploadResult.sarifID && shouldSkipSarifUpload()) { await uploadSarifArtifact(logger, "test-mode-sarif", { // We defaulted to CodeScanning in the `uploadFiles` call above. sarifFile: uploadLib.getSavedPayloadPath(CodeScanning.kind), @@ -302,22 +303,25 @@ async function uploadSarifArtifact( prefix: string, failedSarif: FailedSarifInfo, ): Promise { - logger.info( - `Uploading failed SARIF file ${failedSarif.sarifFile} as artifact`, - ); + logger.startGroup(`Uploading failed SARIF file as artifact`); + logger.info(`Uploading '${failedSarif.sarifFile}' as artifact`); - const gitHubVersion = await getGitHubVersion(); - const client = await getArtifactUploaderClient(logger, gitHubVersion.type); + try { + const gitHubVersion = await getGitHubVersion(); + const client = await getArtifactUploaderClient(logger, gitHubVersion.type); - const suffix = getArtifactSuffix(actionsUtil.getOptionalInput("matrix")); - const name = sanitizeArtifactName(`${prefix}-${suffix}`); - await client.uploadArtifact( - name, - [path.normalize(failedSarif.sarifFile)], - path.normalize(".."), - ); + const suffix = getArtifactSuffix(actionsUtil.getOptionalInput("matrix")); + const name = sanitizeArtifactName(`${prefix}-${suffix}`); + await client.uploadArtifact( + name, + [path.normalize(failedSarif.sarifFile)], + path.normalize(".."), + ); - return { sarifID: name }; + return { sarifID: name }; + } finally { + logger.endGroup(); + } } /**