Skip to content

Commit 6ee400e

Browse files
Merge pull request #55 from blackduck-inc/fix-enterprise-api-url-build-status
fix: update mark_build_status functionality with GitHub Enterprise API URL changes for SARIF upload support
2 parents af91032 + f45da4f commit 6ee400e

File tree

5 files changed

+113
-42
lines changed

5 files changed

+113
-42
lines changed

dist/index.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
1010
exports.POLARIS_SERVERURL_KEY = exports.POLARIS_ASSESSMENT_TYPES_KEY = exports.POLARIS_PROJECT_NAME_KEY = exports.POLARIS_APPLICATION_NAME_KEY = exports.POLARIS_ACCESS_TOKEN_KEY = exports.POLARIS_ACCESSTOKEN_KEY = exports.COVERITY_VERSION_KEY = exports.BRIDGE_COVERITY_VERSION_KEY = exports.COVERITY_LOCAL_KEY = exports.COVERITY_PRCOMMENT_ENABLED_KEY = exports.COVERITY_AUTOMATION_PRCOMMENT_KEY = exports.COVERITY_ARGS_KEY = exports.COVERITY_CONFIG_PATH_KEY = exports.COVERITY_CLEAN_COMMAND_KEY = exports.COVERITY_BUILD_COMMAND_KEY = exports.COVERITY_WAITFORSCAN_KEY = exports.COVERITY_POLICY_VIEW_KEY = exports.COVERITY_INSTALL_DIRECTORY_KEY = exports.COVERITY_STREAM_NAME_KEY = exports.COVERITY_PROJECT_NAME_KEY = exports.COVERITY_PASSPHRASE_KEY = exports.COVERITY_USER_KEY = exports.COVERITY_URL_KEY = exports.DETECT_EXECUTION_PATH_KEY = exports.BLACKDUCK_EXECUTION_PATH_KEY = exports.COVERITY_EXECUTION_PATH_KEY = exports.SRM_WAITFORSCAN_KEY = exports.SRM_BRANCH_PARENT_KEY = exports.SRM_BRANCH_NAME_KEY = exports.SRM_PROJECT_ID_KEY = exports.SRM_PROJECT_NAME_KEY = exports.SRM_ASSESSMENT_TYPES_KEY = exports.SRM_API_KEY = exports.SRM_URL_KEY = exports.SRM_KEY = exports.BLACKDUCK_KEY = exports.POLARIS_KEY = exports.COVERITY_KEY = exports.MIN_SUPPORTED_BRIDGE_CLI_MAC_ARM_VERSION = exports.BRIDGE_CLI_DOWNLOAD_VERSION_KEY = exports.BRIDGE_DOWNLOAD_VERSION_KEY = exports.BRIDGE_CLI_DOWNLOAD_URL_KEY = exports.BRIDGE_DOWNLOAD_URL_KEY = exports.BRIDGE_CLI_INSTALL_DIRECTORY_KEY = exports.BRIDGE_INSTALL_DIRECTORY_KEY = exports.APPLICATION_NAME = exports.BRIDGE_CLI_ARTIFACTORY_URL = exports.BRIDGE_CLI_DEFAULT_PATH_LINUX = exports.BRIDGE_CLI_DEFAULT_PATH_WINDOWS = exports.BRIDGE_CLI_DEFAULT_PATH_MAC = void 0;
1111
exports.BLACKDUCKSCA_UPLOAD_SARIF_REPORT_KEY = exports.BLACKDUCK_UPLOAD_SARIF_REPORT_KEY = exports.BLACKDUCKSCA_REPORTS_SARIF_GROUP_SCA_ISSUES_KEY = exports.BLACKDUCK_REPORTS_SARIF_GROUP_SCA_ISSUES_KEY = exports.BLACKDUCKSCA_REPORTS_SARIF_SEVERITIES_KEY = exports.BLACKDUCK_REPORTS_SARIF_SEVERITIES_KEY = exports.BLACKDUCKSCA_REPORTS_SARIF_FILE_PATH_KEY = exports.BLACKDUCK_REPORTS_SARIF_FILE_PATH_KEY = exports.BLACKDUCKSCA_REPORTS_SARIF_CREATE_KEY = exports.BLACKDUCK_REPORTS_SARIF_CREATE_KEY = exports.BLACKDUCKSCA_PRCOMMENT_ENABLED_KEY = exports.BLACKDUCK_PRCOMMENT_ENABLED_KEY = exports.BLACKDUCKSCA_FIXPR_UPGRADE_GUIDANCE_KEY = exports.BLACKDUCK_FIXPR_USE_UPGRADE_GUIDANCE_KEY = exports.BLACKDUCKSCA_FIXPR_FILTER_SEVERITIES_KEY = exports.BLACKDUCK_FIXPR_FILTER_SEVERITIES_KEY = exports.BLACKDUCKSCA_FIXPR_CREATE_SINGLE_PR_KEY = exports.BLACKDUCK_FIXPR_CREATE_SINGLE_PR_KEY = exports.BLACKDUCKSCA_FIXPR_MAX_COUNT_KEY = exports.BLACKDUCK_FIXPR_MAXCOUNT_KEY = exports.BLACKDUCKSCA_FIXPR_ENABLED_KEY = exports.BLACKDUCK_FIXPR_ENABLED_KEY = exports.BLACKDUCKSCA_SCAN_FAILURE_SEVERITIES_KEY = exports.BLACKDUCK_SCAN_FAILURE_SEVERITIES_KEY = exports.BLACKDUCKSCA_SCAN_FULL_KEY = exports.BLACKDUCK_SCAN_FULL_KEY = exports.DETECT_INSTALL_DIRECTORY_KEY = exports.BLACKDUCK_INSTALL_DIRECTORY_KEY = exports.BLACKDUCKSCA_TOKEN_KEY = exports.BLACKDUCK_TOKEN_KEY = exports.BLACKDUCKSCA_URL_KEY = exports.BLACKDUCK_URL_KEY = exports.PROJECT_DIRECTORY_KEY = exports.PROJECT_SOURCE_EXCLUDES_KEY = exports.PROJECT_SOURCE_PRESERVESYMLINKS_KEY = exports.PROJECT_SOURCE_ARCHIVE_KEY = exports.POLARIS_ASSESSMENT_MODE_KEY = exports.POLARIS_WAITFORSCAN_KEY = exports.POLARIS_UPLOAD_SARIF_REPORT_KEY = exports.POLARIS_REPORTS_SARIF_ISSUE_TYPES_KEY = exports.POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES_KEY = exports.POLARIS_REPORTS_SARIF_SEVERITIES_KEY = exports.POLARIS_REPORTS_SARIF_FILE_PATH_KEY = exports.POLARIS_REPORTS_SARIF_CREATE_KEY = exports.POLARIS_TEST_SCA_TYPE_KEY = exports.POLARIS_BRANCH_PARENT_NAME_KEY = exports.POLARIS_BRANCH_NAME_KEY = exports.POLARIS_PRCOMMENT_SEVERITIES_KEY = exports.POLARIS_PRCOMMENT_ENABLED_KEY = exports.POLARIS_SERVER_URL_KEY = void 0;
1212
exports.BRIDGE_EXECUTABLE_NOT_FOUND_ERROR = exports.BRIDGE_CLI_URL_EMPTY_ERROR = exports.PROVIDED_BRIDGE_CLI_URL_EMPTY_ERROR = exports.BRIDGE_CLI_URL_NOT_VALID_ERROR = exports.BRIDGE_CLI_URL_NOT_VALID_OS_ERROR = exports.BRIDGE_VERSION_NOT_FOUND_ERROR = exports.MISSING_GITHUB_TOKEN_FOR_FIX_PR_AND_PR_COMMENT_ERROR = exports.GITHUB_TOKEN_VALIDATION_SARIF_UPLOAD_ERROR = exports.BLACKDUCK_FIXPR_LOG_INFO_FOR_PR_SCANS = exports.BLACKDUCK_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS = exports.COVERITY_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS = exports.POLARIS_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS = exports.SARIF_REPORT_LOG_INFO_FOR_PR_SCANS = exports.GITHUB_ENVIRONMENT_VARIABLES = exports.HTTP_STATUS_FORBIDDEN = exports.HTTP_STATUS_ACCEPTED = exports.HTTP_STATUS_OK = exports.SECONDARY_RATE_LIMIT = exports.X_RATE_LIMIT_REMAINING = exports.X_RATE_LIMIT_RESET = exports.SARIF_DEFAULT_FILE_NAME = exports.POLARIS_SARIF_ARTIFACT_NAME = exports.POLARIS_SARIF_GENERATOR_DIRECTORY = exports.BLACKDUCK_SARIF_ARTIFACT_NAME = exports.BLACKDUCK_SARIF_GENERATOR_DIRECTORY = exports.BRIDGE_LOCAL_DIRECTORY = exports.GITHUB_CLOUD_API_URL = exports.GITHUB_CLOUD_URL = exports.NON_RETRY_HTTP_CODES = exports.RETRY_COUNT = exports.RETRY_DELAY_IN_MILLISECONDS = exports.EXIT_CODE_MAP = exports.DIAGNOSTICS_RETENTION_DAYS_KEY = exports.NETWORK_AIRGAP_KEY = exports.BRIDGE_NETWORK_AIRGAP_KEY = exports.INCLUDE_DIAGNOSTICS_KEY = exports.GITHUB_TOKEN_KEY = exports.GITHUB_HOST_URL_KEY = exports.BLACKDUCKSCA_POLICY_BADGES_MAX_COUNT_KEY = exports.BLACKDUCK_POLICY_BADGES_MAX_COUNT_KEY = exports.BLACKDUCKSCA_POLICY_BADGES_CREATE_KEY = exports.BLACKDUCK_POLICY_BADGES_CREATE_KEY = exports.DETECT_ARGS_KEY = exports.BLACKDUCK_ARGS_KEY = exports.DETECT_CONFIG_PATH_KEY = exports.BLACKDUCK_CONFIG_PATH_KEY = exports.DETECT_SEARCH_DEPTH_KEY = exports.BLACKDUCK_SEARCH_DEPTH_KEY = exports.BLACKDUCKSCA_WAITFORSCAN_KEY = exports.BLACKDUCK_WAITFORSCAN_KEY = void 0;
13-
exports.EXIT_CODE_ERROR = exports.TASK_RETURN_STATUS = exports.MARK_BUILD_STATUS_DEFAULT = exports.BUILD_STATUS = exports.MARK_BUILD_STATUS_KEY = exports.RETURN_STATUS_KEY = exports.POLARIS_POLICY_BADGES_MAX_COUNT_KEY = exports.POLARIS_POLICY_BADGES_CREATE_KEY = exports.WINDOWS_PLATFORM_NAME = exports.LINUX_PLATFORM_NAME = exports.MAC_PLATFORM_NAME = exports.SARIF_FILE_NO_FOUND_FOR_UPLOAD_ERROR = exports.SARIF_GAS_UPLOAD_FAILED_ERROR = exports.SARIF_GAS_API_RATE_LIMIT_FOR_ERROR = exports.PROVIDED_BLACKDUCKSCA_FAILURE_SEVERITIES_ERROR = exports.MISSING_BOOLEAN_VALUE_ERROR = exports.INVALID_VALUE_ERROR = exports.BRIDGE_DOWNLOAD_RETRY_ERROR = exports.BRIDGE_EXTRACT_directory_NOT_FOUND_ERROR = exports.BRIDGE_ZIP_NOT_FOUND_FOR_EXTRACT_ERROR = exports.SCAN_TYPE_REQUIRED_ERROR = exports.BRIDGE_DEFAULT_DIRECTORY_NOT_FOUND_ERROR = exports.BRIDGE_INSTALL_DIRECTORY_NOT_FOUND_ERROR = void 0;
13+
exports.BRIDGE_BREAK_EXIT_CODE = exports.TASK_RETURN_STATUS = exports.MARK_BUILD_STATUS_DEFAULT = exports.BUILD_STATUS = exports.MARK_BUILD_STATUS_KEY = exports.RETURN_STATUS_KEY = exports.POLARIS_POLICY_BADGES_MAX_COUNT_KEY = exports.POLARIS_POLICY_BADGES_CREATE_KEY = exports.WINDOWS_PLATFORM_NAME = exports.LINUX_PLATFORM_NAME = exports.MAC_PLATFORM_NAME = exports.SARIF_FILE_NO_FOUND_FOR_UPLOAD_ERROR = exports.SARIF_GAS_UPLOAD_FAILED_ERROR = exports.SARIF_GAS_API_RATE_LIMIT_FOR_ERROR = exports.PROVIDED_BLACKDUCKSCA_FAILURE_SEVERITIES_ERROR = exports.MISSING_BOOLEAN_VALUE_ERROR = exports.INVALID_VALUE_ERROR = exports.BRIDGE_DOWNLOAD_RETRY_ERROR = exports.BRIDGE_EXTRACT_directory_NOT_FOUND_ERROR = exports.BRIDGE_ZIP_NOT_FOUND_FOR_EXTRACT_ERROR = exports.SCAN_TYPE_REQUIRED_ERROR = exports.BRIDGE_DEFAULT_DIRECTORY_NOT_FOUND_ERROR = exports.BRIDGE_INSTALL_DIRECTORY_NOT_FOUND_ERROR = void 0;
1414
exports.BRIDGE_CLI_DEFAULT_PATH_MAC = '/bridge-cli-bundle'; //Path will be in home
1515
exports.BRIDGE_CLI_DEFAULT_PATH_WINDOWS = '\\bridge-cli-bundle';
1616
exports.BRIDGE_CLI_DEFAULT_PATH_LINUX = '/bridge-cli-bundle';
@@ -302,7 +302,7 @@ var BUILD_STATUS;
302302
})(BUILD_STATUS = exports.BUILD_STATUS || (exports.BUILD_STATUS = {}));
303303
exports.MARK_BUILD_STATUS_DEFAULT = BUILD_STATUS.FAILURE;
304304
exports.TASK_RETURN_STATUS = 'status';
305-
exports.EXIT_CODE_ERROR = 8;
305+
exports.BRIDGE_BREAK_EXIT_CODE = 8;
306306

307307

308308
/***/ }),
@@ -2740,7 +2740,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27402740
});
27412741
};
27422742
Object.defineProperty(exports, "__esModule", ({ value: true }));
2743-
exports.getBridgeExitCode = exports.getBridgeExitCodeAsNumericValue = exports.logBridgeExitCodes = exports.run = void 0;
2743+
exports.markBuildStatusIfIssuesArePresent = exports.getBridgeExitCode = exports.getBridgeExitCodeAsNumericValue = exports.logBridgeExitCodes = exports.run = void 0;
27442744
const core_1 = __nccwpck_require__(42186);
27452745
const utility_1 = __nccwpck_require__(4201);
27462746
const bridge_cli_1 = __nccwpck_require__(61848);
@@ -2775,24 +2775,19 @@ function run() {
27752775
(0, core_1.info)('Black Duck Security Action workflow execution completed successfully.');
27762776
isBridgeExecuted = true;
27772777
}
2778-
return exitCode;
2779-
}
2780-
catch (error) {
2781-
const err = error;
2782-
exitCode = getBridgeExitCodeAsNumericValue(err);
2783-
if (exitCode === constants.EXIT_CODE_ERROR && (0, utility_1.checkJobResult)(inputs.MARK_BUILD_STATUS) === constants.BUILD_STATUS.SUCCESS) {
2784-
(0, core_1.info)(`Workflow failed! ${logBridgeExitCodes(err.message)}.\nMarking the build ${inputs.MARK_BUILD_STATUS} as configured in the task.`);
2785-
isBridgeExecuted = true;
2786-
}
2787-
else
2788-
throw error;
2789-
}
2790-
finally {
27912778
// The statement set the exit code in the 'status' variable which can be used in the YAML file
27922779
if ((0, utility_1.parseToBoolean)(inputs.RETURN_STATUS)) {
27932780
(0, core_1.debug)(`Setting output variable ${constants.TASK_RETURN_STATUS} with exit code ${exitCode}`);
27942781
(0, core_1.setOutput)(constants.TASK_RETURN_STATUS, exitCode);
27952782
}
2783+
return exitCode;
2784+
}
2785+
catch (error) {
2786+
exitCode = getBridgeExitCodeAsNumericValue(error);
2787+
isBridgeExecuted = getBridgeExitCode(error);
2788+
throw error;
2789+
}
2790+
finally {
27962791
const uploadSarifReportBasedOnExitCode = exitCode === 0 || exitCode === 8;
27972792
(0, core_1.debug)(`Bridge CLI execution completed: ${isBridgeExecuted}`);
27982793
if (isBridgeExecuted) {
@@ -2849,12 +2844,35 @@ function getBridgeExitCode(error) {
28492844
return false;
28502845
}
28512846
exports.getBridgeExitCode = getBridgeExitCode;
2852-
run().catch(error => {
2853-
if (error.message != undefined) {
2854-
(0, core_1.setFailed)('Workflow failed! '.concat(logBridgeExitCodes(error.message)));
2847+
function markBuildStatusIfIssuesArePresent(status, taskResult, errorMessage) {
2848+
const exitMessage = logBridgeExitCodes(errorMessage);
2849+
if (status === constants.BRIDGE_BREAK_EXIT_CODE) {
2850+
(0, core_1.debug)(errorMessage);
2851+
if (taskResult === constants.BUILD_STATUS.SUCCESS) {
2852+
(0, core_1.info)(exitMessage);
2853+
}
2854+
(0, core_1.info)(`Marking the build ${taskResult} as configured in the task.`);
28552855
}
28562856
else {
2857-
(0, core_1.setFailed)('Workflow failed! '.concat(logBridgeExitCodes(error)));
2857+
(0, core_1.setFailed)('Workflow failed! '.concat(logBridgeExitCodes(exitMessage)));
2858+
}
2859+
}
2860+
exports.markBuildStatusIfIssuesArePresent = markBuildStatusIfIssuesArePresent;
2861+
run().catch(error => {
2862+
if (error.message !== undefined) {
2863+
const isReturnStatusEnabled = (0, utility_1.parseToBoolean)(inputs.RETURN_STATUS);
2864+
const exitCode = getBridgeExitCodeAsNumericValue(error);
2865+
if (isReturnStatusEnabled) {
2866+
(0, core_1.debug)(`Setting output variable ${constants.TASK_RETURN_STATUS} with exit code ${exitCode}`);
2867+
(0, core_1.setOutput)(constants.TASK_RETURN_STATUS, exitCode);
2868+
}
2869+
const taskResult = (0, utility_1.checkJobResult)(inputs.MARK_BUILD_STATUS);
2870+
if (taskResult && taskResult !== constants.BUILD_STATUS.FAILURE) {
2871+
markBuildStatusIfIssuesArePresent(exitCode, taskResult, error.message);
2872+
}
2873+
else {
2874+
(0, core_1.setFailed)('Workflow failed! '.concat(logBridgeExitCodes(error.message)));
2875+
}
28582876
}
28592877
});
28602878

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/application-constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,4 @@ export enum BUILD_STATUS {
300300
}
301301
export const MARK_BUILD_STATUS_DEFAULT = BUILD_STATUS.FAILURE
302302
export const TASK_RETURN_STATUS = 'status'
303-
export const EXIT_CODE_ERROR = 8
303+
export const BRIDGE_BREAK_EXIT_CODE = 8

src/main.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as inputs from './blackduck-security-action/inputs'
77
import {uploadDiagnostics, uploadSarifReportAsArtifact} from './blackduck-security-action/artifacts'
88
import {isNullOrEmptyValue} from './blackduck-security-action/validators'
99
import {GitHubClientServiceFactory} from './blackduck-security-action/factory/github-client-service-factory'
10-
import {EXIT_CODE_ERROR} from './application-constants'
1110

1211
export async function run() {
1312
info('Black Duck Security Action started...')
@@ -33,20 +32,17 @@ export async function run() {
3332
info('Black Duck Security Action workflow execution completed successfully.')
3433
isBridgeExecuted = true
3534
}
36-
return exitCode
37-
} catch (error) {
38-
const err = error as Error
39-
exitCode = getBridgeExitCodeAsNumericValue(err)
40-
if (exitCode === constants.EXIT_CODE_ERROR && checkJobResult(inputs.MARK_BUILD_STATUS) === constants.BUILD_STATUS.SUCCESS) {
41-
info(`Workflow failed! ${logBridgeExitCodes(err.message)}.\nMarking the build ${inputs.MARK_BUILD_STATUS} as configured in the task.`)
42-
isBridgeExecuted = true
43-
} else throw error
44-
} finally {
4535
// The statement set the exit code in the 'status' variable which can be used in the YAML file
4636
if (parseToBoolean(inputs.RETURN_STATUS)) {
4737
debug(`Setting output variable ${constants.TASK_RETURN_STATUS} with exit code ${exitCode}`)
4838
setOutput(constants.TASK_RETURN_STATUS, exitCode)
4939
}
40+
return exitCode
41+
} catch (error) {
42+
exitCode = getBridgeExitCodeAsNumericValue(error as Error)
43+
isBridgeExecuted = getBridgeExitCode(error as Error)
44+
throw error
45+
} finally {
5046
const uploadSarifReportBasedOnExitCode = exitCode === 0 || exitCode === 8
5147
debug(`Bridge CLI execution completed: ${isBridgeExecuted}`)
5248
if (isBridgeExecuted) {
@@ -103,10 +99,36 @@ export function getBridgeExitCode(error: Error): boolean {
10399
return false
104100
}
105101

106-
run().catch(error => {
107-
if (error.message != undefined) {
108-
setFailed('Workflow failed! '.concat(logBridgeExitCodes(error.message)))
102+
export function markBuildStatusIfIssuesArePresent(status: number, taskResult: string, errorMessage: string): void {
103+
const exitMessage = logBridgeExitCodes(errorMessage)
104+
105+
if (status === constants.BRIDGE_BREAK_EXIT_CODE) {
106+
debug(errorMessage)
107+
if (taskResult === constants.BUILD_STATUS.SUCCESS) {
108+
info(exitMessage)
109+
}
110+
info(`Marking the build ${taskResult} as configured in the task.`)
109111
} else {
110-
setFailed('Workflow failed! '.concat(logBridgeExitCodes(error)))
112+
setFailed('Workflow failed! '.concat(logBridgeExitCodes(exitMessage)))
113+
}
114+
}
115+
116+
run().catch(error => {
117+
if (error.message !== undefined) {
118+
const isReturnStatusEnabled = parseToBoolean(inputs.RETURN_STATUS)
119+
const exitCode = getBridgeExitCodeAsNumericValue(error)
120+
121+
if (isReturnStatusEnabled) {
122+
debug(`Setting output variable ${constants.TASK_RETURN_STATUS} with exit code ${exitCode}`)
123+
setOutput(constants.TASK_RETURN_STATUS, exitCode)
124+
}
125+
126+
const taskResult: string | undefined = checkJobResult(inputs.MARK_BUILD_STATUS)
127+
128+
if (taskResult && taskResult !== constants.BUILD_STATUS.FAILURE) {
129+
markBuildStatusIfIssuesArePresent(exitCode, taskResult, error.message)
130+
} else {
131+
setFailed('Workflow failed! '.concat(logBridgeExitCodes(error.message)))
132+
}
111133
}
112134
})

test/unit/main.test.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getBridgeExitCode, logBridgeExitCodes, run} from '../../src/main'
1+
import {getBridgeExitCode, logBridgeExitCodes, markBuildStatusIfIssuesArePresent, run} from '../../src/main'
22
import * as inputs from '../../src/blackduck-security-action/inputs'
33
import {Bridge} from '../../src/blackduck-security-action/bridge-cli'
44
import {DownloadFileResponse} from '../../src/blackduck-security-action/download-utility'
@@ -87,9 +87,7 @@ describe('Black Duck Security Action: Handling isBridgeExecuted and Exit Code In
8787
try {
8888
await run()
8989
} catch (error: any) {
90-
expect(error.message).toContain('Exit Code: 8')
91-
expect(core.info).toHaveBeenCalledWith('Marking the build success as configured in the task.')
92-
expect(core.setOutput).toHaveBeenCalledWith('status', 8)
90+
expect(error.message).toContain('Bridge CLI execution failed with exit code 8')
9391
expect(core.debug).toHaveBeenCalledWith('Bridge CLI execution completed: true')
9492
}
9593
})
@@ -125,10 +123,43 @@ describe('Black Duck Security Action: Handling isBridgeExecuted and Exit Code In
125123
try {
126124
await run()
127125
} catch (error: any) {
128-
expect(error.message).toContain('Exit Code: 8')
129-
expect(diagnostics.uploadSarifReportAsArtifact).toHaveBeenCalledWith('blackduck-sca-sarif-generator', '/', 'blackduck-sca-sarif-artifact')
126+
expect(error.message).toContain('Bridge CLI execution failed with exit code 8')
127+
expect(diagnostics.uploadSarifReportAsArtifact).toHaveBeenCalledWith('Blackduck SCA SARIF Generator', '/', 'blackduck_sarif_report')
130128
}
131129
})
130+
131+
test('markBuildStatusIfIssuesArePresent sets build status correctly', () => {
132+
const status = 8
133+
const errorMessage = 'Error: The process failed with exit code 2'
134+
135+
const debugSpy = jest.spyOn(core, 'debug')
136+
const infoSpy = jest.spyOn(core, 'info')
137+
const setFailedSpy = jest.spyOn(core, 'setFailed')
138+
139+
markBuildStatusIfIssuesArePresent(status, 'success', errorMessage)
140+
141+
expect(debugSpy).toHaveBeenCalledWith(errorMessage)
142+
expect(infoSpy).toHaveBeenCalledWith('Exit Code: 2 Error from adapter end')
143+
expect(infoSpy).toHaveBeenCalledWith('Marking the build success as configured in the task.')
144+
expect(setFailedSpy).not.toHaveBeenCalled()
145+
146+
debugSpy.mockRestore()
147+
infoSpy.mockRestore()
148+
setFailedSpy.mockRestore()
149+
})
150+
151+
test('markBuildStatusIfIssuesArePresent sets workflow as failed', () => {
152+
const status = 2
153+
const errorMessage = 'Error: The process failed with exit code 2'
154+
155+
const setFailedSpy = jest.spyOn(core, 'setFailed')
156+
157+
markBuildStatusIfIssuesArePresent(status, 'failure', errorMessage)
158+
159+
expect(setFailedSpy).toHaveBeenCalledWith('Workflow failed! Exit Code: 2 Error from adapter end')
160+
161+
setFailedSpy.mockRestore()
162+
})
132163
})
133164

134165
test('Not supported flow error - run', async () => {

0 commit comments

Comments
 (0)