@@ -257,10 +257,12 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
257
257
) ;
258
258
259
259
//-----------------------------------------------------------------------------------------------------+
260
- // Copy to another folder. Azure does not support wildcard for `[email protected] ` |
260
+ // Recalculate artifacts hash and copy to another folder (because they can change after signing them).
261
+ // Azure does not support wildcard for `[email protected] ` |
261
262
//-----------------------------------------------------------------------------------------------------+
262
263
if ( isCI ) {
263
264
try {
265
+ await recalculateArtifactsHash ( ) ;
264
266
await copyFilesToBuildArtifacts ( ) ;
265
267
} catch ( e ) {
266
268
echo ( JSON . stringify ( e ) ) ;
@@ -400,6 +402,66 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
400
402
}
401
403
}
402
404
405
+ async function recalculateArtifactsHash ( ) {
406
+ echo ( `🚢 Detected CI, recalculating artifacts hash...` ) ;
407
+ const { platform } = process ;
408
+ const cwd = path ( '..' , 'build' , 'dist' ) ;
409
+ const channelFilePath = join ( cwd , getChannelFile ( platform ) ) ;
410
+ const yaml = require ( 'yaml' ) ;
411
+
412
+ try {
413
+ let fileContents = fs . readFileSync ( channelFilePath , 'utf8' ) ;
414
+ const newChannelFile = yaml . parse ( fileContents ) ;
415
+ const { files, path } = newChannelFile ;
416
+ const newSha512 = await hashFile ( join ( cwd , path ) ) ;
417
+ newChannelFile . sha512 = newSha512 ;
418
+ if ( ! ! files ) {
419
+ const newFiles = [ ] ;
420
+ for ( let file of files ) {
421
+ const { url } = file ;
422
+ const { size } = fs . statSync ( join ( cwd , url ) ) ;
423
+ const newSha512 = await hashFile ( join ( cwd , url ) ) ;
424
+ newFiles . push ( { ...file , sha512 : newSha512 , size } ) ;
425
+ }
426
+ newChannelFile . files = newFiles ;
427
+ }
428
+ console . log ( '=======================' ) ;
429
+ console . log ( 'Printing channel file' ) ;
430
+ console . log ( yaml . stringify ( newChannelFile ) ) ;
431
+ fs . writeFileSync ( channelFilePath , yaml . stringify ( newChannelFile ) ) ;
432
+ } catch ( e ) {
433
+ console . log ( e ) ;
434
+ }
435
+ }
436
+
437
+ async function hashFile (
438
+ file ,
439
+ algorithm = 'sha512' ,
440
+ encoding = 'base64' ,
441
+ options
442
+ ) {
443
+ const crypto = require ( 'crypto' ) ;
444
+ return await new Promise ( ( resolve , reject ) => {
445
+ const hash = crypto . createHash ( algorithm ) ;
446
+ hash . on ( 'error' , reject ) . setEncoding ( encoding ) ;
447
+ fs . createReadStream (
448
+ file ,
449
+ Object . assign ( { } , options , {
450
+ highWaterMark : 1024 * 1024 ,
451
+ /* better to use more memory but hash faster */
452
+ } )
453
+ )
454
+ . on ( 'error' , reject )
455
+ . on ( 'end' , ( ) => {
456
+ hash . end ( ) ;
457
+ resolve ( hash . read ( ) ) ;
458
+ } )
459
+ . pipe ( hash , {
460
+ end : false ,
461
+ } ) ;
462
+ } ) ;
463
+ }
464
+
403
465
/**
404
466
* Joins tha path from `__dirname`.
405
467
*/
0 commit comments