@@ -9,6 +9,7 @@ const archiver = require("../helpers/archiver"),
9
9
utils = require ( "../helpers/utils" ) ,
10
10
fileHelpers = require ( "../helpers/fileHelpers" ) ,
11
11
syncRunner = require ( "../helpers/syncRunner" ) ,
12
+ checkUploaded = require ( "../helpers/checkUploaded" ) ,
12
13
reportGenerator = require ( '../helpers/reporterHTML' ) . reportGenerator ,
13
14
{ initTimeComponents, markBlockStart, markBlockEnd, getTimeComponents} = require ( '../helpers/timeComponents' ) ,
14
15
downloadBuildArtifacts = require ( '../helpers/buildArtifacts' ) . downloadBuildArtifacts ;
@@ -85,117 +86,125 @@ module.exports = function run(args) {
85
86
86
87
// warn if specFiles cross our limit
87
88
utils . warnSpecLimit ( bsConfig , args , specFiles ) ;
88
-
89
89
markBlockEnd ( 'preArchiveSteps' ) ;
90
- // Archive the spec files
91
- markBlockStart ( 'zip' ) ;
92
- markBlockStart ( 'zip.archive' ) ;
93
- return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude ) . then ( function ( data ) {
94
-
95
- markBlockEnd ( 'zip.archive' ) ;
96
- // Uploaded zip file
97
- markBlockStart ( 'zip.zipUpload' ) ;
98
- return zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( async function ( zip ) {
99
-
100
- markBlockEnd ( 'zip.zipUpload' ) ;
101
- markBlockEnd ( 'zip' ) ;
102
- // Create build
103
-
104
- //setup Local Testing
105
- markBlockStart ( 'localSetup' ) ;
106
- let bs_local = await utils . setupLocalTesting ( bsConfig , args ) ;
107
- markBlockEnd ( 'localSetup' ) ;
108
- markBlockStart ( 'createBuild' ) ;
109
- return build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
110
- markBlockEnd ( 'createBuild' ) ;
111
- markBlockEnd ( 'total' ) ;
112
- let message = `${ data . message } ! ${ Constants . userMessages . BUILD_CREATED } with build id: ${ data . build_id } ` ;
113
- let dashboardLink = `${ Constants . userMessages . VISIT_DASHBOARD } ${ data . dashboard_url } ` ;
114
- utils . exportResults ( data . build_id , `${ config . dashboardUrl } ${ data . build_id } ` ) ;
115
- if ( ( utils . isUndefined ( bsConfig . run_settings . parallels ) && utils . isUndefined ( args . parallels ) ) || ( ! utils . isUndefined ( bsConfig . run_settings . parallels ) && bsConfig . run_settings . parallels == Constants . cliMessages . RUN . DEFAULT_PARALLEL_MESSAGE ) ) {
116
- logger . warn ( Constants . userMessages . NO_PARALLELS ) ;
117
- }
90
+ markBlockStart ( 'checkAlreadyUploaded' ) ;
91
+ return checkUploaded . checkUploadedMd5 ( bsConfig , args ) . then ( function ( md5data ) {
92
+ markBlockEnd ( 'checkAlreadyUploaded' ) ;
93
+
94
+ // Archive the spec files
95
+ markBlockStart ( 'zip' ) ;
96
+ markBlockStart ( 'zip.archive' ) ;
97
+ return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude , md5data ) . then ( function ( data ) {
98
+ markBlockEnd ( 'zip.archive' ) ;
99
+
100
+ // Uploaded zip file
101
+ markBlockStart ( 'zip.zipUpload' ) ;
102
+ return zipUploader . zipUpload ( bsConfig , config . fileName , md5data ) . then ( async function ( zip ) {
103
+ markBlockEnd ( 'zip.zipUpload' ) ;
104
+ markBlockEnd ( 'zip' ) ;
105
+ // Create build
106
+
107
+ //setup Local Testing
108
+ markBlockStart ( 'localSetup' ) ;
109
+ let bs_local = await utils . setupLocalTesting ( bsConfig , args ) ;
110
+ markBlockEnd ( 'localSetup' ) ;
111
+ markBlockStart ( 'createBuild' ) ;
112
+ return build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
113
+ markBlockEnd ( 'createBuild' ) ;
114
+ markBlockEnd ( 'total' ) ;
115
+ let message = `${ data . message } ! ${ Constants . userMessages . BUILD_CREATED } with build id: ${ data . build_id } ` ;
116
+ let dashboardLink = `${ Constants . userMessages . VISIT_DASHBOARD } ${ data . dashboard_url } ` ;
117
+ utils . exportResults ( data . build_id , `${ config . dashboardUrl } ${ data . build_id } ` ) ;
118
+ if ( ( utils . isUndefined ( bsConfig . run_settings . parallels ) && utils . isUndefined ( args . parallels ) ) || ( ! utils . isUndefined ( bsConfig . run_settings . parallels ) && bsConfig . run_settings . parallels == Constants . cliMessages . RUN . DEFAULT_PARALLEL_MESSAGE ) ) {
119
+ logger . warn ( Constants . userMessages . NO_PARALLELS ) ;
120
+ }
118
121
119
- if ( bsConfig . run_settings . cypress_version && bsConfig . run_settings . cypress_version !== data . cypress_version ) {
120
- let versionMessage = utils . versionChangedMessage ( bsConfig . run_settings . cypress_version , data . cypress_version )
121
- logger . warn ( versionMessage ) ;
122
- }
122
+ if ( bsConfig . run_settings . cypress_version && bsConfig . run_settings . cypress_version !== data . cypress_version ) {
123
+ let versionMessage = utils . versionChangedMessage ( bsConfig . run_settings . cypress_version , data . cypress_version )
124
+ logger . warn ( versionMessage ) ;
125
+ }
123
126
124
- if ( ! args . disableNpmWarning && bsConfig . run_settings . npm_dependencies && Object . keys ( bsConfig . run_settings . npm_dependencies ) . length <= 0 ) {
125
- logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES ) ;
126
- logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES_READ_MORE ) ;
127
- }
127
+ if ( ! args . disableNpmWarning && bsConfig . run_settings . npm_dependencies && Object . keys ( bsConfig . run_settings . npm_dependencies ) . length <= 0 ) {
128
+ logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES ) ;
129
+ logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES_READ_MORE ) ;
130
+ }
128
131
129
- if ( args . sync ) {
130
- syncRunner . pollBuildStatus ( bsConfig , data ) . then ( async ( exitCode ) => {
132
+ if ( args . sync ) {
133
+ syncRunner . pollBuildStatus ( bsConfig , data ) . then ( async ( exitCode ) => {
131
134
132
- // stop the Local instance
133
- await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
135
+ // stop the Local instance
136
+ await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
134
137
135
- // waiting for 5 secs for upload to complete (as a safety measure)
136
- await new Promise ( resolve => setTimeout ( resolve , 5000 ) ) ;
138
+ // waiting for 5 secs for upload to complete (as a safety measure)
139
+ await new Promise ( resolve => setTimeout ( resolve , 5000 ) ) ;
137
140
138
- // download build artifacts
139
- if ( ! utils . isUndefined ( bsConfig . run_settings . downloads ) && bsConfig . run_settings . downloads . length ) {
140
- await downloadBuildArtifacts ( bsConfig , data . build_id , args ) ;
141
- }
141
+ // download build artifacts
142
+ if ( ! utils . isUndefined ( bsConfig . run_settings . downloads ) && bsConfig . run_settings . downloads . length ) {
143
+ await downloadBuildArtifacts ( bsConfig , data . build_id , args ) ;
144
+ }
142
145
143
- // Generate custom report!
144
- reportGenerator ( bsConfig , data . build_id , args , function ( ) {
145
- utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null ) ;
146
- utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
146
+ // Generate custom report!
147
+ reportGenerator ( bsConfig , data . build_id , args , function ( ) {
148
+ utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null ) ;
149
+ utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
150
+ } ) ;
147
151
} ) ;
148
- } ) ;
149
- } else {
150
- logger . info ( Constants . userMessages . ASYNC_DOWNLOADS . replace ( '<build-id>' , data . build_id ) ) ;
151
- }
152
-
153
- logger . info ( message ) ;
154
- logger . info ( dashboardLink ) ;
155
- if ( ! args . sync ) logger . info ( Constants . userMessages . EXIT_SYNC_CLI_MESSAGE . replace ( "<build-id>" , data . build_id ) ) ;
156
- let dataToSend = {
157
- time_components : getTimeComponents ( ) ,
158
- build_id : data . build_id ,
159
- } ;
160
- if ( bsConfig && bsConfig . connection_settings ) {
161
- if ( bsConfig . connection_settings . local_mode ) {
162
- dataToSend . local_mode = bsConfig . connection_settings . local_mode ;
152
+ } else {
153
+ logger . info ( Constants . userMessages . ASYNC_DOWNLOADS . replace ( '<build-id>' , data . build_id ) ) ;
163
154
}
164
- if ( bsConfig . connection_settings . usedAutoLocal ) {
165
- dataToSend . used_auto_local = bsConfig . connection_settings . usedAutoLocal ;
155
+
156
+ logger . info ( message ) ;
157
+ logger . info ( dashboardLink ) ;
158
+ if ( ! args . sync ) logger . info ( Constants . userMessages . EXIT_SYNC_CLI_MESSAGE . replace ( "<build-id>" , data . build_id ) ) ;
159
+ let dataToSend = {
160
+ time_components : getTimeComponents ( ) ,
161
+ build_id : data . build_id ,
162
+ } ;
163
+ if ( bsConfig && bsConfig . connection_settings ) {
164
+ if ( bsConfig . connection_settings . local_mode ) {
165
+ dataToSend . local_mode = bsConfig . connection_settings . local_mode ;
166
+ }
167
+ if ( bsConfig . connection_settings . usedAutoLocal ) {
168
+ dataToSend . used_auto_local = bsConfig . connection_settings . usedAutoLocal ;
169
+ }
166
170
}
167
- }
168
- utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null , dataToSend ) ;
169
- return ;
170
- } ) . catch ( async function ( err ) {
171
- // Build creation failed
171
+ utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null , dataToSend ) ;
172
+ return ;
173
+ } ) . catch ( async function ( err ) {
174
+ // Build creation failed
175
+ logger . error ( err ) ;
176
+ // stop the Local instance
177
+ await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
178
+
179
+ utils . sendUsageReport ( bsConfig , args , err , Constants . messageTypes . ERROR , 'build_failed' ) ;
180
+ } ) ;
181
+ } ) . catch ( function ( err ) {
182
+ // Zip Upload failed | Local Start failed
172
183
logger . error ( err ) ;
173
- // stop the Local instance
174
- await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
175
-
176
- utils . sendUsageReport ( bsConfig , args , err , Constants . messageTypes . ERROR , 'build_failed' ) ;
184
+ if ( err === Constants . userMessages . LOCAL_START_FAILED ) {
185
+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . LOCAL_START_FAILED } ` , Constants . messageTypes . ERROR , 'local_start_failed' ) ;
186
+ } else {
187
+ logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED ) ;
188
+ fileHelpers . deleteZip ( ) ;
189
+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
190
+ }
177
191
} ) ;
178
192
} ) . catch ( function ( err ) {
179
- // Zip Upload failed | Local Start failed
193
+ // Zipping failed
180
194
logger . error ( err ) ;
181
- if ( err === Constants . userMessages . LOCAL_START_FAILED ) {
182
- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . LOCAL_START_FAILED } ` , Constants . messageTypes . ERROR , 'local_start_failed' ) ;
183
- } else {
184
- logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED ) ;
195
+ logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
196
+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed' ) ;
197
+ try {
185
198
fileHelpers . deleteZip ( ) ;
186
- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
199
+ } catch ( err ) {
200
+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed' ) ;
187
201
}
188
202
} ) ;
189
203
} ) . catch ( function ( err ) {
190
- // Zipping failed
204
+ // md5 check failed
191
205
logger . error ( err ) ;
192
- logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
193
- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed' ) ;
194
- try {
195
- fileHelpers . deleteZip ( ) ;
196
- } catch ( err ) {
197
- utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed' ) ;
198
- }
206
+ logger . error ( Constants . userMessages . FAILED_MD5_CHECK ) ;
207
+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . MD5_CHECK_FAILED , Constants . messageTypes . ERROR , 'zip_already_uploaded_failed' ) ;
199
208
} ) ;
200
209
} ) . catch ( function ( err ) {
201
210
// browerstack.json is not valid
0 commit comments