@@ -16,8 +16,10 @@ const archiver = require("../helpers/archiver"),
1616 reportGenerator = require ( '../helpers/reporterHTML' ) . reportGenerator ,
1717 { initTimeComponents, instrumentEventTime, markBlockStart, markBlockEnd, getTimeComponents} = require ( '../helpers/timeComponents' ) ,
1818 downloadBuildArtifacts = require ( '../helpers/buildArtifacts' ) . downloadBuildArtifacts ,
19+ downloadBuildStacktrace = require ( '../helpers/downloadBuildStacktrace' ) . downloadBuildStacktrace ,
1920 updateNotifier = require ( 'update-notifier' ) ,
2021 pkg = require ( '../../package.json' ) ;
22+ const { getStackTraceUrl } = require ( '../helpers/sync/syncSpecsLogs' ) ;
2123
2224module . exports = function run ( args , rawArgs ) {
2325 let bsConfigPath = utils . getConfigPath ( args . cf ) ;
@@ -110,16 +112,16 @@ module.exports = function run(args, rawArgs) {
110112 // warn if specFiles cross our limit
111113 utils . warnSpecLimit ( bsConfig , args , specFiles , rawArgs ) ;
112114 markBlockEnd ( 'preArchiveSteps' ) ;
113- markBlockStart ( 'checkAlreadyUploaded' ) ;
115+ markBlockStart ( 'zip' ) ;
116+ markBlockStart ( 'zip.checkAlreadyUploaded' ) ;
114117 return checkUploaded . checkUploadedMd5 ( bsConfig , args , { markBlockStart, markBlockEnd} ) . then ( function ( md5data ) {
115- markBlockEnd ( 'checkAlreadyUploaded' ) ;
118+ markBlockEnd ( 'zip. checkAlreadyUploaded' ) ;
116119
117- markBlockStart ( 'packageInstaller' ) ;
120+ markBlockStart ( 'zip. packageInstaller' ) ;
118121 return packageInstaller . packageWrapper ( bsConfig , config . packageDirName , config . packageFileName , md5data , { markBlockStart, markBlockEnd} ) . then ( function ( packageData ) {
119- markBlockEnd ( 'packageInstaller' ) ;
122+ markBlockEnd ( 'zip. packageInstaller' ) ;
120123
121124 // Archive the spec files
122- markBlockStart ( 'zip' ) ;
123125 markBlockStart ( 'zip.archive' ) ;
124126 return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude , md5data ) . then ( function ( data ) {
125127 markBlockEnd ( 'zip.archive' ) ;
@@ -181,15 +183,32 @@ module.exports = function run(args, rawArgs) {
181183 await new Promise ( resolve => setTimeout ( resolve , 5000 ) ) ;
182184
183185 // 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+ } ) ;
186211 }
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- } ) ;
193212 } ) ;
194213 } else if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
195214 logger . info ( Constants . userMessages . ASYNC_DOWNLOADS . replace ( '<build-id>' , data . build_id ) ) ;
@@ -324,9 +343,23 @@ module.exports = function run(args, rawArgs) {
324343 utils . sendUsageReport ( bsJsonData , args , err . message , Constants . messageTypes . ERROR , utils . getErrorCodeFromErr ( err ) , null , rawArgs ) ;
325344 process . exitCode = Constants . ERROR_EXIT_CODE ;
326345 } ) . finally ( function ( ) {
327- updateNotifier ( {
346+ const notifier = updateNotifier ( {
328347 pkg,
329348 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+ }
331364 } ) ;
332365}
0 commit comments