Skip to content

Commit ea1ba19

Browse files
author
Alberto Iannaccone
committed
recalculate artifacts hash
1 parent 1436d3b commit ea1ba19

File tree

7 files changed

+81
-79
lines changed

7 files changed

+81
-79
lines changed

Diff for: electron/build/scripts/hash.js

-31
This file was deleted.

Diff for: electron/build/scripts/notarize.js

-35
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
const fs = require('fs');
21
const isCI = require('is-ci');
32
const { notarize } = require('electron-notarize');
4-
const utils = require('../../packager/utils');
5-
const { getChannelFile } = utils;
6-
const join = require('path').join;
7-
const { hashFile } = require('./hash');
83

94
exports.default = async function notarizing(context) {
105
if (!isCI) {
@@ -34,34 +29,4 @@ exports.default = async function notarizing(context) {
3429
teamId: process.env.AC_TEAM_ID,
3530
tool: 'notarytool',
3631
});
37-
return await recalculateHash();
3832
};
39-
40-
async function recalculateHash() {
41-
const { platform } = process;
42-
const cwd = join(__dirname, '..', 'build', 'dist');
43-
const channelFilePath = join(cwd, getChannelFile(platform));
44-
const yaml = require('yaml');
45-
46-
try {
47-
let fileContents = fs.readFileSync(channelFilePath, 'utf8');
48-
const newChannelFile = yaml.parse(fileContents);
49-
const { files, path } = newChannelFile;
50-
const newSha512 = await hashFile(join(cwd, path));
51-
newChannelFile.sha512 = newSha512;
52-
if (!!files) {
53-
const newFiles = [];
54-
for (let file of files) {
55-
const { url } = file;
56-
const { size } = fs.statSync(join(cwd, url));
57-
const newSha512 = await hashFile(join(cwd, url));
58-
newFiles.push({ ...file, sha512: newSha512, size });
59-
}
60-
newChannelFile.files = newFiles;
61-
}
62-
console.log(channelFilePath);
63-
fs.writeFileSync(channelFilePath, yaml.stringify(newChannelFile));
64-
} catch (e) {
65-
console.log(e);
66-
}
67-
}

Diff for: electron/build/template-package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
"electron-notarize": "^1.1.1",
1818
"is-ci": "^2.0.0",
1919
"ncp": "^2.0.0",
20-
"shelljs": "^0.8.3",
21-
"crypto": "^1.0.1",
22-
"yaml": "^1.10.2"
20+
"shelljs": "^0.8.3"
2321
},
2422
"scripts": {
2523
"build": "yarn download:plugins && theia build --mode development && yarn patch",
@@ -94,7 +92,9 @@
9492
"gatekeeperAssess": false,
9593
"entitlements": "resources/entitlements.mac.plist",
9694
"entitlementsInherit": "resources/entitlements.mac.plist",
97-
"target": "default"
95+
"target": [
96+
"dmg"
97+
]
9898
},
9999
"linux": {
100100
"target": [

Diff for: electron/packager/index.js

+63-1
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,12 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
257257
);
258258

259259
//-----------------------------------------------------------------------------------------------------+
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]` |
261262
//-----------------------------------------------------------------------------------------------------+
262263
if (isCI) {
263264
try {
265+
await recalculateArtifactsHash();
264266
await copyFilesToBuildArtifacts();
265267
} catch (e) {
266268
echo(JSON.stringify(e));
@@ -400,6 +402,66 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
400402
}
401403
}
402404

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+
403465
/**
404466
* Joins tha path from `__dirname`.
405467
*/

Diff for: electron/packager/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/file-type": "^10.9.1",
1818
"@types/temp": "^0.8.32",
1919
"chai": "^4.2.0",
20+
"crypto": "^1.0.1",
2021
"dateformat": "^3.0.3",
2122
"deepmerge": "2.01",
2223
"depcheck": "^0.9.2",
@@ -28,6 +29,7 @@
2829
"shelljs": "^0.8.3",
2930
"sinon": "^9.0.1",
3031
"temp": "^0.9.1",
32+
"yaml": "^1.10.2",
3133
"yargs": "^12.0.5"
3234
},
3335
"engines": {

Diff for: electron/packager/utils.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,9 @@ function git(command) {
197197
// to work correctly.
198198
// For more information: https://www.electron.build/auto-update
199199
function getChannelFile(platform) {
200-
let currentChannel = '';
201-
if (isNightly) {
202-
currentChannel = 'beta';
203-
} else if (isRelease) {
200+
let currentChannel = 'beta';
201+
if (isRelease) {
204202
currentChannel = 'latest';
205-
} else {
206-
// We're not creating a nightly build nor releasing
207-
// a new version, no need for a channel file.
208-
return '';
209203
}
210204
return (
211205
currentChannel +

Diff for: electron/packager/yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ cross-spawn@^6.0.0:
437437
shebang-command "^1.2.0"
438438
which "^1.2.9"
439439

440+
crypto@^1.0.1:
441+
version "1.0.1"
442+
resolved "https://registry.yarnpkg.com/crypto/-/crypto-1.0.1.tgz#2af1b7cad8175d24c8a1b0778255794a21803037"
443+
integrity sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==
444+
440445
dateformat@^3.0.3:
441446
version "3.0.3"
442447
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
@@ -1597,6 +1602,11 @@ wrappy@1:
15971602
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"
15981603
integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==
15991604

1605+
yaml@^1.10.2:
1606+
version "1.10.2"
1607+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
1608+
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==
1609+
16001610
[email protected], yargs-parser@^13.1.2:
16011611
version "13.1.2"
16021612
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38"

0 commit comments

Comments
 (0)