diff --git a/lib/init-action-post-helper.js b/lib/init-action-post-helper.js index 41e0a6fdf..4fb47eb45 100644 --- a/lib/init-action-post-helper.js +++ b/lib/init-action-post-helper.js @@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.run = exports.uploadFailedSarif = void 0; +exports.run = exports.uploadSarifIfRunFailed = exports.uploadFailedSarif = void 0; const core = __importStar(require("@actions/core")); const actionsUtil = __importStar(require("./actions-util")); const codeql_1 = require("./codeql"); @@ -29,6 +29,12 @@ const shared_environment_1 = require("./shared-environment"); const uploadLib = __importStar(require("./upload-lib")); const util_1 = require("./util"); const workflow_1 = require("./workflow"); +function createFailedUploadFailedSarifResult(error) { + return { + upload_failed_run_error: error instanceof Error ? error.message : String(error), + upload_failed_run_stack_trace: error instanceof Error ? error.stack : undefined, + }; +} async function uploadFailedSarif(config, repositoryNwo, featureEnablement, logger) { var _a, _b; if (!config.codeQLCmd) { @@ -61,18 +67,12 @@ async function uploadFailedSarif(config, repositoryNwo, featureEnablement, logge }; } exports.uploadFailedSarif = uploadFailedSarif; -async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, printDebugLogs, repositoryNwo, featureEnablement, logger) { - const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger); - if (config === undefined) { - logger.warning("Debugging artifacts are unavailable since the 'init' Action failed before it could produce any."); - return; - } +async function uploadSarifIfRunFailed(config, repositoryNwo, featureEnablement, logger) { // Environment variable used to integration test uploading a SARIF file for failed runs const expectFailedSarifUpload = process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true"; - let uploadFailedSarifResult; if (process.env[shared_environment_1.CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF] !== "true") { try { - uploadFailedSarifResult = await uploadFailedSarif(config, repositoryNwo, featureEnablement, logger); + return await uploadFailedSarif(config, repositoryNwo, featureEnablement, logger); } catch (e) { if (expectFailedSarifUpload) { @@ -80,19 +80,26 @@ async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, p `the following error: ${e}`); } logger.info(`Failed to upload a SARIF file for the failed run. Error: ${e}`); - uploadFailedSarifResult = { - upload_failed_run_error: e instanceof Error ? e.message : String(e), - }; + return createFailedUploadFailedSarifResult(e); } } else if (expectFailedSarifUpload) { throw new Error("Expected to upload a SARIF file for the failed run, but didn't."); } else { - uploadFailedSarifResult = { + return { upload_failed_run_skipped_because: "SARIF file already uploaded", }; } +} +exports.uploadSarifIfRunFailed = uploadSarifIfRunFailed; +async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, printDebugLogs, repositoryNwo, featureEnablement, logger) { + const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger); + if (config === undefined) { + logger.warning("Debugging artifacts are unavailable since the 'init' Action failed before it could produce any."); + return; + } + const uploadFailedSarifResult = await uploadSarifIfRunFailed(config, repositoryNwo, featureEnablement, logger); // Upload appropriate Actions artifacts for debugging if (config.debugMode) { core.info("Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts..."); diff --git a/lib/init-action-post-helper.js.map b/lib/init-action-post-helper.js.map index 5d431ef54..7356546d7 100644 --- a/lib/init-action-post-helper.js.map +++ b/lib/init-action-post-helper.js.map @@ -1 +1 @@ -{"version":3,"file":"init-action-post-helper.js","sourceRoot":"","sources":["../src/init-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,4DAA8C;AAC9C,qCAAqC;AACrC,iDAAmD;AACnD,mDAA6D;AAG7D,6DAA8E;AAC9E,wDAA0C;AAC1C,iCAA6E;AAC7E,yCAKoB;AAcb,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,aAA4B,EAC5B,iBAAoC,EACpC,MAAc;;IAEd,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;QACrB,MAAM,CAAC,OAAO,CACZ,+DAA+D,CAChE,CAAC;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,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;aACpE,CAAC;SACH;KACF;SAAM,IAAI,uBAAuB,EAAE;QAClC,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;KACH;SAAM;QACL,uBAAuB,GAAG;YACxB,iCAAiC,EAAE,6BAA6B;SACjE,CAAC;KACH;IAED,qDAAqD;IACrD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,IAAI,CAAC,IAAI,CACP,mGAAmG,CACpG,CAAC;QACF,MAAM,iCAAiC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;KAC9B;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAlED,kBAkEC"} \ No newline at end of file +{"version":3,"file":"init-action-post-helper.js","sourceRoot":"","sources":["../src/init-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,4DAA8C;AAC9C,qCAAqC;AACrC,iDAAmD;AACnD,mDAA6D;AAG7D,6DAA8E;AAC9E,wDAA0C;AAC1C,iCAA6E;AAC7E,yCAKoB;AAsBpB,SAAS,mCAAmC,CAC1C,KAAc;IAEd,OAAO;QACL,uBAAuB,EACrB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACxD,6BAA6B,EAC3B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;KACnD,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,aAA4B,EAC5B,iBAAoC,EACpC,MAAc;;IAEd,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;QACrB,MAAM,CAAC,OA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xB,aAA4B,EAC5B,iBAAoC,EACpC,MAAc;IAEd,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,MAAM,CAAC,OAAO,CACZ,iGAAiG,CAClG,CAAC;QACF,OAAO;KACR;IAED,MAAM,uBAAuB,GAAG,MAAM,sBAAsB,CAC1D,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,MAAM,CACP,CAAC;IAEF,qDAAqD;IACrD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,IAAI,CAAC,IAAI,CACP,mGAAmG,CACpG,CAAC;QACF,MAAM,iCAAiC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;KAC9B;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAnCD,kBAmCC"} \ No newline at end of file diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 90cb11948..7e014b93b 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -17,17 +17,36 @@ import { } from "./workflow"; export interface UploadFailedSarifResult { - /** Size in bytes of the unzipped SARIF payload uploaded for the failed run. */ + /** + * If a SARIF file was uploaded for a failed run, this is the size in bytes of the unzipped + * SARIF payload. + */ upload_failed_run_raw_upload_size_bytes?: number; - /** Size in bytes of actual SARIF payload uploaded for the failed run. */ + /** + * If a SARIF file was uploaded for a failed run, this is the size in bytes of the actual + * zipped payload. + */ upload_failed_run_zipped_upload_size_bytes?: number; - /** Error encountered during uploading the failed run. */ + /** If there was an error while uploading a failed run, this is its message. */ upload_failed_run_error?: string; + /** If there was an error while uploading a failed run, this is its stack trace. */ + upload_failed_run_stack_trace?: string; /** Reason why we did not upload a SARIF payload with `executionSuccessful: false`. */ upload_failed_run_skipped_because?: string; } +function createFailedUploadFailedSarifResult( + error: unknown +): UploadFailedSarifResult { + return { + upload_failed_run_error: + error instanceof Error ? error.message : String(error), + upload_failed_run_stack_trace: + error instanceof Error ? error.stack : undefined, + }; +} + export async function uploadFailedSarif( config: Config, repositoryNwo: RepositoryNwo, @@ -89,31 +108,19 @@ export async function uploadFailedSarif( }; } -export async function run( - uploadDatabaseBundleDebugArtifact: Function, - uploadLogsDebugArtifact: Function, - printDebugLogs: Function, +export async function uploadSarifIfRunFailed( + config: Config, repositoryNwo: RepositoryNwo, featureEnablement: FeatureEnablement, logger: Logger -) { - const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger); - if (config === undefined) { - logger.warning( - "Debugging artifacts are unavailable since the 'init' Action failed before it could produce any." - ); - return; - } - +): Promise { // Environment variable used to integration test uploading a SARIF file for failed runs const expectFailedSarifUpload = process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true"; - let uploadFailedSarifResult: UploadFailedSarifResult; - if (process.env[CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF] !== "true") { try { - uploadFailedSarifResult = await uploadFailedSarif( + return await uploadFailedSarif( config, repositoryNwo, featureEnablement, @@ -129,19 +136,41 @@ export async function run( logger.info( `Failed to upload a SARIF file for the failed run. Error: ${e}` ); - uploadFailedSarifResult = { - upload_failed_run_error: e instanceof Error ? e.message : String(e), - }; + return createFailedUploadFailedSarifResult(e); } } else if (expectFailedSarifUpload) { throw new Error( "Expected to upload a SARIF file for the failed run, but didn't." ); } else { - uploadFailedSarifResult = { + return { upload_failed_run_skipped_because: "SARIF file already uploaded", }; } +} + +export async function run( + uploadDatabaseBundleDebugArtifact: Function, + uploadLogsDebugArtifact: Function, + printDebugLogs: Function, + repositoryNwo: RepositoryNwo, + featureEnablement: FeatureEnablement, + logger: Logger +) { + const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger); + if (config === undefined) { + logger.warning( + "Debugging artifacts are unavailable since the 'init' Action failed before it could produce any." + ); + return; + } + + const uploadFailedSarifResult = await uploadSarifIfRunFailed( + config, + repositoryNwo, + featureEnablement, + logger + ); // Upload appropriate Actions artifacts for debugging if (config.debugMode) {