@@ -16,8 +16,10 @@ const archiver = require("../helpers/archiver"),
16
16
reportGenerator = require ( '../helpers/reporterHTML' ) . reportGenerator ,
17
17
{ initTimeComponents, instrumentEventTime, markBlockStart, markBlockEnd, getTimeComponents} = require ( '../helpers/timeComponents' ) ,
18
18
downloadBuildArtifacts = require ( '../helpers/buildArtifacts' ) . downloadBuildArtifacts ,
19
+ downloadBuildStacktrace = require ( '../helpers/downloadBuildStacktrace' ) . downloadBuildStacktrace ,
19
20
updateNotifier = require ( 'update-notifier' ) ,
20
21
pkg = require ( '../../package.json' ) ;
22
+ const { getStackTraceUrl } = require ( '../helpers/sync/syncSpecsLogs' ) ;
21
23
22
24
module . exports = function run ( args , rawArgs ) {
23
25
let bsConfigPath = utils . getConfigPath ( args . cf ) ;
@@ -110,16 +112,16 @@ module.exports = function run(args, rawArgs) {
110
112
// warn if specFiles cross our limit
111
113
utils . warnSpecLimit ( bsConfig , args , specFiles , rawArgs ) ;
112
114
markBlockEnd ( 'preArchiveSteps' ) ;
113
- markBlockStart ( 'checkAlreadyUploaded' ) ;
115
+ markBlockStart ( 'zip' ) ;
116
+ markBlockStart ( 'zip.checkAlreadyUploaded' ) ;
114
117
return checkUploaded . checkUploadedMd5 ( bsConfig , args , { markBlockStart, markBlockEnd} ) . then ( function ( md5data ) {
115
- markBlockEnd ( 'checkAlreadyUploaded' ) ;
118
+ markBlockEnd ( 'zip. checkAlreadyUploaded' ) ;
116
119
117
- markBlockStart ( 'packageInstaller' ) ;
120
+ markBlockStart ( 'zip. packageInstaller' ) ;
118
121
return packageInstaller . packageWrapper ( bsConfig , config . packageDirName , config . packageFileName , md5data , { markBlockStart, markBlockEnd} ) . then ( function ( packageData ) {
119
- markBlockEnd ( 'packageInstaller' ) ;
122
+ markBlockEnd ( 'zip. packageInstaller' ) ;
120
123
121
124
// Archive the spec files
122
- markBlockStart ( 'zip' ) ;
123
125
markBlockStart ( 'zip.archive' ) ;
124
126
return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude , md5data ) . then ( function ( data ) {
125
127
markBlockEnd ( 'zip.archive' ) ;
@@ -181,15 +183,32 @@ module.exports = function run(args, rawArgs) {
181
183
await new Promise ( resolve => setTimeout ( resolve , 5000 ) ) ;
182
184
183
185
// download build artifacts
184
- if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
185
- await downloadBuildArtifacts ( bsConfig , data . build_id , args , rawArgs ) ;
186
+ if ( exitCode != Constants . BUILD_FAILED_EXIT_CODE ) {
187
+ if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
188
+ await downloadBuildArtifacts ( bsConfig , data . build_id , args , rawArgs ) ;
189
+ }
190
+
191
+ // Generate custom report!
192
+ reportGenerator ( bsConfig , data . build_id , args , rawArgs , function ( ) {
193
+ utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null , buildReportData , rawArgs ) ;
194
+ utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
195
+ } ) ;
196
+ } else {
197
+ let stacktraceUrl = getStackTraceUrl ( ) ;
198
+ downloadBuildStacktrace ( stacktraceUrl ) . then ( ( message ) => {
199
+ utils . sendUsageReport ( bsConfig , args , message , Constants . messageTypes . SUCCESS , null , buildReportData , rawArgs ) ;
200
+ } ) . catch ( ( err ) => {
201
+ let message = `Downloading build stacktrace failed with statuscode: ${ err } . Please visit ${ data . dashboard_url } for additional details.` ;
202
+ logger . error ( message ) ;
203
+ utils . sendUsageReport ( bsConfig , args , message , Constants . messageTypes . ERROR , null , buildReportData , rawArgs ) ;
204
+ } ) . finally ( ( ) => {
205
+ let terminalWidth = ( process . stdout . columns ) * 0.9 ;
206
+ let lineSeparator = "\n" + "-" . repeat ( terminalWidth ) ;
207
+ console . log ( lineSeparator )
208
+ logger . info ( Constants . userMessages . BUILD_FAILED_ERROR )
209
+ process . exitCode = Constants . BUILD_FAILED_EXIT_CODE ;
210
+ } ) ;
186
211
}
187
-
188
- // Generate custom report!
189
- reportGenerator ( bsConfig , data . build_id , args , rawArgs , function ( ) {
190
- utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null , buildReportData , rawArgs ) ;
191
- utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
192
- } ) ;
193
212
} ) ;
194
213
} else if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
195
214
logger . info ( Constants . userMessages . ASYNC_DOWNLOADS . replace ( '<build-id>' , data . build_id ) ) ;
@@ -324,9 +343,23 @@ module.exports = function run(args, rawArgs) {
324
343
utils . sendUsageReport ( bsJsonData , args , err . message , Constants . messageTypes . ERROR , utils . getErrorCodeFromErr ( err ) , null , rawArgs ) ;
325
344
process . exitCode = Constants . ERROR_EXIT_CODE ;
326
345
} ) . finally ( function ( ) {
327
- updateNotifier ( {
346
+ const notifier = updateNotifier ( {
328
347
pkg,
329
348
updateCheckInterval : 1000 * 60 * 60 * 24 * 7 ,
330
- } ) . notify ( { isGlobal : true } ) ;
349
+ } ) ;
350
+
351
+ // Checks for update on first run.
352
+ // Set lastUpdateCheck to 0 to spawn the check update process as notifier sets this to Date.now() for preventing
353
+ // the check untill one interval period. It runs once.
354
+ if ( ! notifier . disabled && Date . now ( ) - notifier . config . get ( 'lastUpdateCheck' ) < 50 ) {
355
+ notifier . config . set ( 'lastUpdateCheck' , 0 ) ;
356
+ notifier . check ( ) ;
357
+ }
358
+
359
+ // Set the config update as notifier clears this after reading.
360
+ if ( notifier . update && notifier . update . current !== notifier . update . latest ) {
361
+ notifier . config . set ( 'update' , notifier . update ) ;
362
+ notifier . notify ( { isGlobal : true } ) ;
363
+ }
331
364
} ) ;
332
365
}
0 commit comments