browserstack-cypress-cli 1.31.10 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/accessibility-automation/cypress/index.js +274 -276
- package/bin/accessibility-automation/helper.js +41 -27
- package/bin/accessibility-automation/plugin/index.js +2 -3
- package/bin/commands/generateReport.js +0 -1
- package/bin/commands/info.js +39 -38
- package/bin/commands/runs.js +7 -9
- package/bin/commands/stop.js +0 -1
- package/bin/helpers/atsHelper.js +48 -39
- package/bin/helpers/build.js +39 -31
- package/bin/helpers/buildArtifacts.js +87 -69
- package/bin/helpers/capabilityHelper.js +1 -0
- package/bin/helpers/checkUploaded.js +43 -33
- package/bin/helpers/downloadBuildStacktrace.js +23 -14
- package/bin/helpers/getInitialDetails.js +33 -22
- package/bin/helpers/helper.js +10 -2
- package/bin/helpers/reporterHTML.js +52 -39
- package/bin/helpers/sync/syncSpecsLogs.js +36 -23
- package/bin/helpers/usageReporting.js +52 -34
- package/bin/helpers/utils.js +96 -77
- package/bin/helpers/zipUpload.js +61 -85
- package/bin/testObservability/crashReporter/index.js +23 -14
- package/bin/testObservability/cypress/index.js +7 -7
- package/bin/testObservability/helper/helper.js +59 -43
- package/bin/testObservability/helper/requestQueueHandler.js +2 -2
- package/bin/testObservability/plugin/ipcServer.js +6 -6
- package/bin/testObservability/reporter/index.js +8 -10
- package/package.json +5 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
const { default: axios } = require("axios");
|
|
4
|
+
|
|
5
|
+
const config = require("../config"),
|
|
4
6
|
utils = require("../utils"),
|
|
5
7
|
logger = require("../logger").syncCliLogger,
|
|
6
8
|
winstonLogger = require("../logger").winstonLogger,
|
|
@@ -9,6 +11,8 @@ const request = require("request"),
|
|
|
9
11
|
tableStream = require('table').createStream,
|
|
10
12
|
chalk = require('chalk');
|
|
11
13
|
|
|
14
|
+
const { setAxiosProxy } = require('../helper');
|
|
15
|
+
|
|
12
16
|
let whileLoop = true, whileTries = config.retries, options, timeout = 3000, n = 2, tableConfig, stream, endTime, startTime = Date.now(), buildStarted = false;
|
|
13
17
|
let specSummary = {
|
|
14
18
|
"buildError": null,
|
|
@@ -135,27 +139,23 @@ let printSpecsStatus = (bsConfig, buildDetails, rawArgs, buildReportData) => {
|
|
|
135
139
|
});
|
|
136
140
|
};
|
|
137
141
|
|
|
138
|
-
let whileProcess = (whilstCallback) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
n = 2
|
|
149
|
-
return setTimeout(whilstCallback, timeout * n, null);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
142
|
+
let whileProcess = async (whilstCallback) => {
|
|
143
|
+
try {
|
|
144
|
+
const axiosConfig = {
|
|
145
|
+
auth: {
|
|
146
|
+
username: options.auth.user,
|
|
147
|
+
password: options.auth.password
|
|
148
|
+
},
|
|
149
|
+
headers: options.headers
|
|
150
|
+
};
|
|
151
|
+
setAxiosProxy(axiosConfig);
|
|
152
152
|
|
|
153
|
+
const response = await axios.post(options.url, {}, axiosConfig);
|
|
153
154
|
whileTries = config.retries; // reset to default after every successful request
|
|
154
|
-
|
|
155
|
-
switch (response.statusCode) {
|
|
155
|
+
switch (response.status) {
|
|
156
156
|
case 202: // get data here and print it
|
|
157
157
|
n = 2
|
|
158
|
-
showSpecsStatus(
|
|
158
|
+
showSpecsStatus(response.data, 202);
|
|
159
159
|
return setTimeout(whilstCallback, timeout * n, null);
|
|
160
160
|
case 204: // No data available, wait for some time and ask again
|
|
161
161
|
n = 1
|
|
@@ -163,14 +163,27 @@ let whileProcess = (whilstCallback) => {
|
|
|
163
163
|
case 200: // Build is completed.
|
|
164
164
|
whileLoop = false;
|
|
165
165
|
endTime = Date.now();
|
|
166
|
-
showSpecsStatus(
|
|
166
|
+
showSpecsStatus(response.data, 200);
|
|
167
167
|
return specSummary.exitCode == Constants.BUILD_FAILED_EXIT_CODE ?
|
|
168
168
|
whilstCallback({ status: 204, message: "No specs ran in the build"} ) : whilstCallback(null, body);
|
|
169
169
|
default:
|
|
170
170
|
whileLoop = false;
|
|
171
|
-
return whilstCallback({ status: response.
|
|
171
|
+
return whilstCallback({ status: response.status, message: response.data });
|
|
172
172
|
}
|
|
173
|
-
})
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error) {
|
|
175
|
+
whileTries -= 1;
|
|
176
|
+
if (whileTries === 0) {
|
|
177
|
+
whileLoop = false;
|
|
178
|
+
endTime = Date.now();
|
|
179
|
+
specSummary.exitCode = config.networkErrorExitCode;
|
|
180
|
+
return whilstCallback({ status: 504, message: "Tries limit reached" }); //Gateway Timeout
|
|
181
|
+
} else {
|
|
182
|
+
n = 2
|
|
183
|
+
return setTimeout(whilstCallback, timeout * n, null);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
174
187
|
}
|
|
175
188
|
|
|
176
189
|
let getStackTraceUrl = () => {
|
|
@@ -178,7 +191,7 @@ let getStackTraceUrl = () => {
|
|
|
178
191
|
}
|
|
179
192
|
|
|
180
193
|
let showSpecsStatus = (data, statusCode) => {
|
|
181
|
-
let specData =
|
|
194
|
+
let specData = data;
|
|
182
195
|
specData["specData"].forEach(specDetails => {
|
|
183
196
|
if (specDetails.type === Constants.CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY) {
|
|
184
197
|
addCustomErrorToPrint(specDetails);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const cp = require("child_process"),
|
|
3
3
|
os = require("os"),
|
|
4
|
-
request = require("requestretry"),
|
|
5
4
|
fs = require('fs'),
|
|
6
5
|
path = require('path');
|
|
7
6
|
|
|
@@ -10,7 +9,11 @@ const config = require('./config'),
|
|
|
10
9
|
utils = require('./utils');
|
|
11
10
|
|
|
12
11
|
const { AUTH_REGEX, REDACTED_AUTH, REDACTED, CLI_ARGS_REGEX, RAW_ARGS_REGEX } = require("./constants");
|
|
13
|
-
const {
|
|
12
|
+
const { default: axios } = require("axios");
|
|
13
|
+
const axiosRetry = require("axios-retry");
|
|
14
|
+
const { isTurboScaleSession } = require("./atsHelper");
|
|
15
|
+
|
|
16
|
+
const { setAxiosProxy } = require('./helper');
|
|
14
17
|
|
|
15
18
|
function get_version(package_name) {
|
|
16
19
|
try {
|
|
@@ -217,31 +220,36 @@ function sendTurboscaleErrorLogs(args) {
|
|
|
217
220
|
password: bsConfig.auth.access_key,
|
|
218
221
|
},
|
|
219
222
|
url: `${config.turboScaleAPIUrl}/send-instrumentation`,
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
maxAttempts: 10, // (default) try 3 times
|
|
223
|
+
data: turboscaleErrorPayload,
|
|
224
|
+
maxAttempts: 10,
|
|
223
225
|
retryDelay: 2000, // (default) wait for 2s before trying again
|
|
224
|
-
retrySrategy: request.RetryStrategies.HTTPOrNetworkError, // (default) retry on 5xx or network errors
|
|
225
226
|
};
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return;
|
|
228
|
+
axiosRetry(axios, {
|
|
229
|
+
retries: options.maxAttempts,
|
|
230
|
+
retryDelay: (retryCount) => options.retryDelay,
|
|
231
|
+
retryCondition: (error) => {
|
|
232
|
+
return axiosRetry.isRetryableError(error) // (default) retry on 5xx or network errors
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
fileLogger.info(`Sending ${JSON.stringify(turboscaleErrorPayload)} to ${config.turboScaleAPIUrl}/send-instrumentation`);
|
|
237
|
+
|
|
238
|
+
axios(options)
|
|
239
|
+
.then((res) => {
|
|
235
240
|
let response = {
|
|
236
|
-
attempts: res.
|
|
237
|
-
statusCode: res.
|
|
238
|
-
body:
|
|
241
|
+
attempts: res.config['axios-retry'].retryCount + 1,
|
|
242
|
+
statusCode: res.status,
|
|
243
|
+
body: res.data
|
|
239
244
|
};
|
|
240
245
|
fileLogger.info(`${JSON.stringify(response)}`);
|
|
246
|
+
})
|
|
247
|
+
.catch((error) => {
|
|
248
|
+
fileLogger.error(JSON.stringify(error));
|
|
241
249
|
});
|
|
242
250
|
}
|
|
243
251
|
|
|
244
|
-
function send(args) {
|
|
252
|
+
async function send(args) {
|
|
245
253
|
let bsConfig = JSON.parse(JSON.stringify(args.bstack_config));
|
|
246
254
|
|
|
247
255
|
if (isTurboScaleSession(bsConfig) && args.message_type === 'error') {
|
|
@@ -307,10 +315,6 @@ function send(args) {
|
|
|
307
315
|
},
|
|
308
316
|
};
|
|
309
317
|
|
|
310
|
-
if (isTurboScaleSession(bsConfig)) {
|
|
311
|
-
payload.event_type = 'hst_cypress_cli_stats';
|
|
312
|
-
}
|
|
313
|
-
|
|
314
318
|
const options = {
|
|
315
319
|
headers: {
|
|
316
320
|
"Content-Type": "text/json",
|
|
@@ -321,24 +325,38 @@ function send(args) {
|
|
|
321
325
|
json: true,
|
|
322
326
|
maxAttempts: 10, // (default) try 3 times
|
|
323
327
|
retryDelay: 2000, // (default) wait for 2s before trying again
|
|
324
|
-
retrySrategy: request.RetryStrategies.HTTPOrNetworkError, // (default) retry on 5xx or network errors
|
|
325
328
|
};
|
|
326
329
|
|
|
330
|
+
const axiosConfig = {
|
|
331
|
+
headers: options.headers,
|
|
332
|
+
};
|
|
333
|
+
setAxiosProxy(axiosConfig);
|
|
334
|
+
|
|
327
335
|
fileLogger.info(`Sending ${JSON.stringify(payload)} to ${config.usageReportingUrl}`);
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
336
|
+
axiosRetry(axios,
|
|
337
|
+
{
|
|
338
|
+
retries: 3,
|
|
339
|
+
retryDelay: 2000,
|
|
340
|
+
retryCondition: (error) => {
|
|
341
|
+
return utils.isNotUndefined(error.response) && (error.response.status === 503 || error.response.status === 500)
|
|
333
342
|
}
|
|
334
|
-
// write response file
|
|
335
|
-
let response = {
|
|
336
|
-
attempts: res.attempts,
|
|
337
|
-
statusCode: res.statusCode,
|
|
338
|
-
body: body
|
|
339
|
-
};
|
|
340
|
-
fileLogger.info(`${JSON.stringify(response)}`);
|
|
341
343
|
});
|
|
344
|
+
try {
|
|
345
|
+
const response = await axios.post(options.url, options.body, axiosConfig);
|
|
346
|
+
let result = {
|
|
347
|
+
statusText: response.statusText,
|
|
348
|
+
statusCode: response.status,
|
|
349
|
+
body: response.data
|
|
350
|
+
};
|
|
351
|
+
fileLogger.info(`${JSON.stringify(result)}`);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
if (error.response) {
|
|
354
|
+
fileLogger.error(JSON.stringify(error.response.data));
|
|
355
|
+
} else {
|
|
356
|
+
fileLogger.error(`Error sending usage data: ${error.message}`);
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
342
360
|
}
|
|
343
361
|
|
|
344
362
|
module.exports = {
|
package/bin/helpers/utils.js
CHANGED
|
@@ -12,6 +12,7 @@ const { promisify } = require('util');
|
|
|
12
12
|
const readdir = promisify(fs.readdir);
|
|
13
13
|
const stat = promisify(fs.stat);
|
|
14
14
|
const TIMEZONE = require("../helpers/timezone.json");
|
|
15
|
+
const { setAxiosProxy } = require('./helper');
|
|
15
16
|
|
|
16
17
|
const usageReporting = require("./usageReporting"),
|
|
17
18
|
logger = require("./logger").winstonLogger,
|
|
@@ -25,7 +26,7 @@ const usageReporting = require("./usageReporting"),
|
|
|
25
26
|
o11yHelpers = require('../testObservability/helper/helper'),
|
|
26
27
|
{ OBSERVABILITY_ENV_VARS, TEST_OBSERVABILITY_REPORTER } = require('../testObservability/helper/constants');
|
|
27
28
|
|
|
28
|
-
const
|
|
29
|
+
const { default: axios } = require("axios");
|
|
29
30
|
|
|
30
31
|
exports.validateBstackJson = (bsConfigPath) => {
|
|
31
32
|
return new Promise(function (resolve, reject) {
|
|
@@ -491,6 +492,7 @@ exports.setNodeVersion = (bsConfig, args) => {
|
|
|
491
492
|
// specs can be passed via command line args as a string
|
|
492
493
|
// command line args takes precedence over config
|
|
493
494
|
exports.setUserSpecs = (bsConfig, args) => {
|
|
495
|
+
|
|
494
496
|
if(o11yHelpers.isBrowserstackInfra() && o11yHelpers.isTestObservabilitySession() && o11yHelpers.shouldReRunObservabilityTests()) {
|
|
495
497
|
bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS;
|
|
496
498
|
return;
|
|
@@ -591,7 +593,7 @@ exports.setSystemEnvs = (bsConfig) => {
|
|
|
591
593
|
OBSERVABILITY_ENV_VARS.forEach(key => {
|
|
592
594
|
envKeys[key] = process.env[key];
|
|
593
595
|
});
|
|
594
|
-
|
|
596
|
+
|
|
595
597
|
let gitConfigPath = o11yHelpers.findGitConfig(process.cwd());
|
|
596
598
|
if(!o11yHelpers.isBrowserstackInfra()) process.env.OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath;
|
|
597
599
|
if(gitConfigPath) {
|
|
@@ -1018,14 +1020,27 @@ exports.checkLocalBinaryRunning = (bsConfig, localIdentifier) => {
|
|
|
1018
1020
|
},
|
|
1019
1021
|
body: JSON.stringify({ localIdentifier: localIdentifier}),
|
|
1020
1022
|
};
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1023
|
+
|
|
1024
|
+
const axiosConfig = {
|
|
1025
|
+
auth: {
|
|
1026
|
+
username: options.auth.user,
|
|
1027
|
+
password: options.auth.password
|
|
1028
|
+
},
|
|
1029
|
+
headers: options.headers
|
|
1030
|
+
};
|
|
1031
|
+
setAxiosProxy(axiosConfig);
|
|
1032
|
+
|
|
1033
|
+
return new Promise (async function(resolve, reject) {
|
|
1034
|
+
try {
|
|
1035
|
+
const response = await axios.post(options.url, {
|
|
1036
|
+
localIdentifier: localIdentifier
|
|
1037
|
+
}, axiosConfig);
|
|
1038
|
+
resolve(response.data)
|
|
1039
|
+
} catch (error) {
|
|
1040
|
+
if(error.response) {
|
|
1041
|
+
reject(error.response.data.message);
|
|
1025
1042
|
}
|
|
1026
|
-
|
|
1027
|
-
resolve(response);
|
|
1028
|
-
});
|
|
1043
|
+
}
|
|
1029
1044
|
});
|
|
1030
1045
|
};
|
|
1031
1046
|
|
|
@@ -1475,6 +1490,7 @@ exports.splitStringByCharButIgnoreIfWithinARange = (str, splitChar, leftLimiter,
|
|
|
1475
1490
|
|
|
1476
1491
|
// blindly send other passed configs with run_settings and handle at backend
|
|
1477
1492
|
exports.setOtherConfigs = (bsConfig, args) => {
|
|
1493
|
+
|
|
1478
1494
|
if(o11yHelpers.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) {
|
|
1479
1495
|
bsConfig["run_settings"]["reporter"] = TEST_OBSERVABILITY_REPORTER;
|
|
1480
1496
|
return;
|
|
@@ -1537,7 +1553,7 @@ exports.setCLIMode = (bsConfig, args) => {
|
|
|
1537
1553
|
exports.formatRequest = (err, resp, body) => {
|
|
1538
1554
|
return {
|
|
1539
1555
|
err,
|
|
1540
|
-
status: resp ? resp.
|
|
1556
|
+
status: resp ? resp.status : null,
|
|
1541
1557
|
body: body ? util.format('%j', body) : null
|
|
1542
1558
|
}
|
|
1543
1559
|
}
|
|
@@ -1557,78 +1573,80 @@ exports.setDebugMode = (args) => {
|
|
|
1557
1573
|
|
|
1558
1574
|
exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs, buildReportData = null) => {
|
|
1559
1575
|
let that = this;
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1576
|
+
|
|
1577
|
+
let url = config.buildStopUrl + buildId;
|
|
1578
|
+
let options = {
|
|
1579
|
+
url: url,
|
|
1580
|
+
auth: {
|
|
1581
|
+
username: bsConfig["auth"]["username"],
|
|
1582
|
+
password: bsConfig["auth"]["access_key"],
|
|
1583
|
+
},
|
|
1584
|
+
headers: {
|
|
1585
|
+
'User-Agent': that.getUserAgent(),
|
|
1586
|
+
},
|
|
1587
|
+
};
|
|
1572
1588
|
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1589
|
+
const axiosConfig = {
|
|
1590
|
+
auth: options.auth,
|
|
1591
|
+
headers: options.headers
|
|
1592
|
+
};
|
|
1593
|
+
setAxiosProxy(axiosConfig);
|
|
1576
1594
|
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1595
|
+
if (Constants.turboScaleObj.enabled) {
|
|
1596
|
+
options.url = `${config.turboScaleBuildsUrl}/${buildId}/stop`;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
let message = null;
|
|
1600
|
+
let messageType = null;
|
|
1601
|
+
let errorCode = null;
|
|
1602
|
+
let build = null;
|
|
1603
|
+
|
|
1604
|
+
try {
|
|
1605
|
+
const response = await axios.post(options.url, {}, axiosConfig);
|
|
1606
|
+
|
|
1607
|
+
build = response.data;
|
|
1608
|
+
if (response.status == 299) {
|
|
1609
|
+
messageType = Constants.messageTypes.INFO;
|
|
1610
|
+
errorCode = 'api_deprecated';
|
|
1611
|
+
|
|
1612
|
+
if (build) {
|
|
1613
|
+
message = build.message;
|
|
1586
1614
|
logger.info(message);
|
|
1587
1615
|
} else {
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
if (resp.statusCode == 299) {
|
|
1591
|
-
messageType = Constants.messageTypes.INFO;
|
|
1592
|
-
errorCode = 'api_deprecated';
|
|
1593
|
-
|
|
1594
|
-
if (build) {
|
|
1595
|
-
message = build.message;
|
|
1596
|
-
logger.info(message);
|
|
1597
|
-
} else {
|
|
1598
|
-
message = Constants.userMessages.API_DEPRECATED;
|
|
1599
|
-
logger.info(message);
|
|
1600
|
-
}
|
|
1601
|
-
} else if (resp.statusCode != 200) {
|
|
1602
|
-
messageType = Constants.messageTypes.ERROR;
|
|
1603
|
-
errorCode = 'api_failed_build_stop';
|
|
1604
|
-
|
|
1605
|
-
if (build) {
|
|
1606
|
-
message = `${
|
|
1607
|
-
Constants.userMessages.BUILD_STOP_FAILED
|
|
1608
|
-
} with error: \n${JSON.stringify(build, null, 2)}`;
|
|
1609
|
-
logger.error(message);
|
|
1610
|
-
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
|
|
1611
|
-
} else {
|
|
1612
|
-
message = Constants.userMessages.BUILD_STOP_FAILED;
|
|
1613
|
-
logger.error(message);
|
|
1614
|
-
}
|
|
1615
|
-
} else {
|
|
1616
|
-
messageType = Constants.messageTypes.SUCCESS;
|
|
1617
|
-
message = `${JSON.stringify(build, null, 2)}`;
|
|
1618
|
-
logger.info(message);
|
|
1619
|
-
}
|
|
1620
|
-
} catch(err) {
|
|
1621
|
-
message = Constants.userMessages.BUILD_STOP_FAILED;
|
|
1622
|
-
messageType = Constants.messageTypes.ERROR;
|
|
1623
|
-
errorCode = 'api_failed_build_stop';
|
|
1624
|
-
logger.info(message);
|
|
1625
|
-
} finally {
|
|
1626
|
-
that.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
|
|
1627
|
-
}
|
|
1616
|
+
message = Constants.userMessages.API_DEPRECATED;
|
|
1617
|
+
logger.info(message);
|
|
1628
1618
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1619
|
+
} else if (response.status !== 200) {
|
|
1620
|
+
messageType = Constants.messageTypes.ERROR;
|
|
1621
|
+
errorCode = 'api_failed_build_stop';
|
|
1622
|
+
|
|
1623
|
+
if (build) {
|
|
1624
|
+
message = `${
|
|
1625
|
+
Constants.userMessages.BUILD_STOP_FAILED
|
|
1626
|
+
} with error: \n${JSON.stringify(build, null, 2)}`;
|
|
1627
|
+
logger.error(message);
|
|
1628
|
+
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
|
|
1629
|
+
} else {
|
|
1630
|
+
message = Constants.userMessages.BUILD_STOP_FAILED;
|
|
1631
|
+
logger.error(message);
|
|
1632
|
+
}
|
|
1633
|
+
} else {
|
|
1634
|
+
messageType = Constants.messageTypes.SUCCESS;
|
|
1635
|
+
message = `${JSON.stringify(build, null, 2)}`;
|
|
1636
|
+
logger.info(message);
|
|
1637
|
+
}
|
|
1638
|
+
} catch(err) {
|
|
1639
|
+
if(err.response) {
|
|
1640
|
+
message = `${
|
|
1641
|
+
Constants.userMessages.BUILD_STOP_FAILED
|
|
1642
|
+
} with error: ${err.response.data.message}`;
|
|
1643
|
+
messageType = Constants.messageTypes.ERROR;
|
|
1644
|
+
errorCode = 'api_failed_build_stop';
|
|
1645
|
+
logger.error(message);
|
|
1646
|
+
}
|
|
1647
|
+
} finally {
|
|
1648
|
+
that.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
|
|
1649
|
+
}
|
|
1632
1650
|
}
|
|
1633
1651
|
|
|
1634
1652
|
exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) => {
|
|
@@ -1645,6 +1663,7 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
|
|
|
1645
1663
|
process.on('uncaughtException', processExitHandler.bind(this, bindData));
|
|
1646
1664
|
}
|
|
1647
1665
|
|
|
1666
|
+
|
|
1648
1667
|
exports.setO11yProcessHooks = (() => {
|
|
1649
1668
|
let bindData = {};
|
|
1650
1669
|
let handlerAdded = false;
|
package/bin/helpers/zipUpload.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
fs = require("fs");
|
|
3
|
+
const fs = require("fs");
|
|
5
4
|
|
|
6
5
|
const cliProgress = require('cli-progress');
|
|
6
|
+
const { default: axios } = require("axios");
|
|
7
|
+
const FormData = require("form-data");
|
|
7
8
|
|
|
8
9
|
const config = require("./config"),
|
|
9
10
|
logger = require("./logger").winstonLogger,
|
|
10
11
|
Constants = require("./constants"),
|
|
11
12
|
utils = require("./utils");
|
|
12
13
|
|
|
14
|
+
const { setAxiosProxy } = require('./helper');
|
|
13
15
|
|
|
14
16
|
const purgeUploadBar = (obj) => {
|
|
15
17
|
obj.bar1.update(100, {
|
|
16
18
|
speed: ((obj.size / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
|
|
17
19
|
});
|
|
18
20
|
obj.bar1.stop();
|
|
19
|
-
clearInterval(obj.zipInterval);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
const uploadSuits = (bsConfig, filePath, opts, obj) => {
|
|
23
|
-
return new Promise(function (resolve, reject) {
|
|
24
|
+
return new Promise(async function (resolve, reject) {
|
|
24
25
|
let uploadProgressBarErrorFlags = {
|
|
25
26
|
noConnectionReportSent: false,
|
|
26
27
|
unknownErrorReportSent: false
|
|
@@ -54,94 +55,69 @@ const uploadSuits = (bsConfig, filePath, opts, obj) => {
|
|
|
54
55
|
|
|
55
56
|
let options = utils.generateUploadParams(bsConfig, filePath, opts.md5Data, opts.fileDetails)
|
|
56
57
|
let responseData = null;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
58
|
+
try {
|
|
59
|
+
const formData = new FormData();
|
|
60
|
+
formData.append("file", fs.createReadStream(filePath));
|
|
61
|
+
formData.append("filetype", opts.fileDetails.filetype);
|
|
62
|
+
formData.append("filename", opts.fileDetails.filename);
|
|
63
|
+
formData.append("zipMd5sum", opts.md5Data ? opts.md5Data : '');
|
|
64
|
+
|
|
65
|
+
const axiosConfig = {
|
|
66
|
+
auth: {
|
|
67
|
+
username: options.auth.user,
|
|
68
|
+
password: options.auth.password
|
|
69
|
+
},
|
|
70
|
+
headers: options.headers,
|
|
71
|
+
onUploadProgress: (progressEvent) => {
|
|
72
|
+
let percent = parseInt(Math.floor((progressEvent.loaded * 100) / progressEvent.total));
|
|
73
|
+
obj.bar1.update(percent, {
|
|
74
|
+
speed: ((progressEvent.bytes / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
setAxiosProxy(axiosConfig);
|
|
79
|
+
|
|
80
|
+
const response = await axios.post(options.url, formData, axiosConfig);
|
|
81
|
+
responseData = response.data;
|
|
82
|
+
purgeUploadBar(obj)
|
|
83
|
+
logger.info(`${opts.messages.uploadingSuccess} (${responseData[opts.md5ReturnKey]})`);
|
|
84
|
+
opts.cleanupMethod();
|
|
85
|
+
responseData["time"] = Date.now() - obj.startTime;
|
|
86
|
+
resolve(responseData);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
let responseData = null;
|
|
89
|
+
if(error.response){
|
|
90
|
+
responseData = error.response.data;
|
|
91
|
+
if (error.response.status === 401) {
|
|
92
|
+
if (responseData && responseData.error) {
|
|
93
|
+
responseData.time = Date.now() - obj.startTime;
|
|
94
|
+
return reject({message: responseData.error, stacktrace: utils.formatRequest(responseData.error, error.response, responseData)});
|
|
86
95
|
} else {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
96
|
+
return reject({message: Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS, stacktrace: utils.formatRequest(error.response.statusText, error.response, responseData)});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!opts.propogateError){
|
|
94
100
|
purgeUploadBar(obj);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
resolve(
|
|
101
|
+
if (error.response.status === 413) {
|
|
102
|
+
return resolve({warn: Constants.userMessages.NODE_MODULES_LIMIT_EXCEEDED.replace("%SIZE%", (size / 1000000).toFixed(2))});
|
|
103
|
+
}
|
|
104
|
+
return resolve({})
|
|
99
105
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
obj.zipInterval = setInterval(function () {
|
|
104
|
-
const errorCode = 'update_upload_progress_bar_failed';
|
|
105
|
-
try {
|
|
106
|
-
if (r && r.req && r.req.connection) {
|
|
107
|
-
let dispatched = r.req.connection._bytesDispatched;
|
|
108
|
-
let percent = dispatched * 100.0 / size;
|
|
109
|
-
obj.bar1.update(percent, {
|
|
110
|
-
speed: ((dispatched / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
|
|
111
|
-
});
|
|
106
|
+
if(responseData && responseData["error"]){
|
|
107
|
+
responseData["time"] = Date.now() - obj.startTime;
|
|
108
|
+
reject({message: responseData["error"], stacktrace: utils.formatRequest(error.response.statusText, error.response, responseData)});
|
|
112
109
|
} else {
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
null,
|
|
118
|
-
Constants.userMessages.NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR,
|
|
119
|
-
Constants.messageTypes.WARNING,
|
|
120
|
-
errorCode,
|
|
121
|
-
null,
|
|
122
|
-
null
|
|
123
|
-
);
|
|
124
|
-
uploadProgressBarErrorFlags.noConnectionReportSent = true;
|
|
110
|
+
if (error.response.status === 413) {
|
|
111
|
+
reject({message: Constants.userMessages.ZIP_UPLOAD_LIMIT_EXCEEDED, stacktrace: utils.formatRequest(error.response.statusText, error.response, responseData)});
|
|
112
|
+
} else {
|
|
113
|
+
reject({message: Constants.userMessages.ZIP_UPLOADER_NOT_REACHABLE, stacktrace: utils.formatRequest(error.response.statusText, error.response, responseData)});
|
|
125
114
|
}
|
|
126
115
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
logger.debug(error);
|
|
131
|
-
utils.sendUsageReport(
|
|
132
|
-
bsConfig,
|
|
133
|
-
null,
|
|
134
|
-
error.stack,
|
|
135
|
-
Constants.messageTypes.WARNING,
|
|
136
|
-
errorCode,
|
|
137
|
-
null,
|
|
138
|
-
null
|
|
139
|
-
);
|
|
140
|
-
uploadProgressBarErrorFlags.unknownErrorReportSent = true;
|
|
141
|
-
}
|
|
116
|
+
reject({message: error.response, stacktrace: utils.formatRequest(error.response.statusText, error.response, error.response.data)});
|
|
117
|
+
} else {
|
|
118
|
+
reject({})
|
|
142
119
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
120
|
+
}
|
|
145
121
|
});
|
|
146
122
|
}
|
|
147
123
|
|