Skip to content

Avoid throwing exit error code if we get 404 for build artifacts #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 13 additions & 3 deletions bin/helpers/buildArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const decompress = require('decompress');
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
let BUILD_ARTIFACTS_FAIL_COUNT = 0;

const parseAndDownloadArtifacts = async (buildId, data) => {
const parseAndDownloadArtifacts = async (buildId, data, bsConfig, args, rawArgs, buildReportData) => {
return new Promise(async (resolve, reject) => {
let all_promises = [];
let combs = Object.keys(data);
Expand All @@ -28,7 +28,14 @@ const parseAndDownloadArtifacts = async (buildId, data) => {
let fileName = 'build_artifacts.zip';
BUILD_ARTIFACTS_TOTAL_COUNT += 1;
all_promises.push(downloadAndUnzip(filePath, fileName, data[comb][sessionId]).catch((error) => {
BUILD_ARTIFACTS_FAIL_COUNT += 1;
if (error === Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND) {
// Don't consider build artifact 404 error as a failure
let warningMessage = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND.replace('<session-id>', sessionId);
logger.warn(warningMessage);
utils.sendUsageReport(bsConfig, args, warningMessage, Constants.messageTypes.ERROR, 'build_artifacts_not_found', buildReportData, rawArgs);
} else {
BUILD_ARTIFACTS_FAIL_COUNT += 1;
}
// delete malformed zip if present
let tmpFilePath = path.join(filePath, fileName);
if(fs.existsSync(tmpFilePath)){
Expand Down Expand Up @@ -99,6 +106,9 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
request.get(url).on('response', function(response) {

if(response.statusCode != 200) {
if (response.statusCode === 404) {
reject(Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND);
}
reject();
} else {
//ensure that the user can call `then()` only when the file has
Expand Down Expand Up @@ -220,7 +230,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
process.exitCode = Constants.ERROR_EXIT_CODE;
} else {
await createDirectories(buildId, buildDetails);
await parseAndDownloadArtifacts(buildId, buildDetails);
await parseAndDownloadArtifacts(buildId, buildDetails, bsConfig, args, rawArgs, buildReportData);
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
messageType = Constants.messageTypes.ERROR;
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
Expand Down
4 changes: 3 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ const userMessages = {
SPEC_LIMIT_WARNING:
"You might not see all your results on the dashboard because of high spec count, please consider reducing the number of spec files in this folder.",
DOWNLOAD_BUILD_ARTIFACTS_FAILED:
"Downloading build artifacts for the build <build-id> failed for <machine-count> machines.",
"Downloading build artifact(s) for the build <build-id> failed for <machine-count> machines.",
DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND:
"Build artifact(s) for the session <session-id> was either not generated or not uploaded.",
ASYNC_DOWNLOADS:
"Test artifacts as specified under 'downloads' can be downloaded after the build has completed its run, using 'browserstack-cypress generate-downloads <build-id>'",
DOWNLOAD_BUILD_ARTIFACTS_SUCCESS:
Expand Down
32 changes: 18 additions & 14 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,25 +1314,29 @@ exports.readBsConfigJSON = (bsConfigPath) => {
}

exports.getCypressConfigFile = (bsConfig) => {
let cypressConfigFile = undefined;
if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
if (bsConfig.run_settings.cypress_config_filename.endsWith("cypress.config.js")) {
try {
let cypressConfigFile = undefined;
if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
if (bsConfig.run_settings.cypress_config_filename.endsWith("cypress.config.js")) {
if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
cypressConfigFile = require(path.resolve(bsConfig.run_settings.cypressConfigFilePath));
} else if (bsConfig.run_settings.cypressProjectDir) {
cypressConfigFile = require(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename));
}
} else {
cypressConfigFile = {};
}
} else {
if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
cypressConfigFile = require(path.resolve(bsConfig.run_settings.cypressConfigFilePath));
cypressConfigFile = JSON.parse(fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath))
} else if (bsConfig.run_settings.cypressProjectDir) {
cypressConfigFile = require(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename));
cypressConfigFile = JSON.parse(fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename)));
}
} else {
cypressConfigFile = {};
}
} else {
if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
cypressConfigFile = JSON.parse(fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath))
} else if (bsConfig.run_settings.cypressProjectDir) {
cypressConfigFile = JSON.parse(fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename)));
}
return cypressConfigFile;
} catch (err) {
return {}
}
return cypressConfigFile;
}

exports.setCLIMode = (bsConfig, args) => {
Expand Down