Skip to content

Commit af08c7e

Browse files
author
Alberto Iannaccone
committed
IDE updater assorted bugfix
- add linux AppImage target - fix hardcoded if condition that causes to always show the update dialog - fix redundant test build version - recalculate sha512 after notarization on macOS
1 parent 9b1f15d commit af08c7e

File tree

8 files changed

+107
-52
lines changed

8 files changed

+107
-52
lines changed

Diff for: .github/workflows/build.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ jobs:
9696
matrix:
9797
artifact:
9898
- path: '*Linux_64bit.zip'
99-
name: Linux_X86-64
99+
name: Linux_X86-64_zip
100+
- path: '*Linux_64bit.AppImage'
101+
name: Linux_X86-64_app_image
100102
- path: '*macOS_64bit.dmg'
101103
name: macOS_dmg
102104
- path: '*macOS_64bit.zip'

Diff for: arduino-ide-extension/src/node/ide-updater/ide-updater-impl.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ export class IDEUpdaterImpl implements IDEUpdater {
5858
} = await this.updater.checkForUpdates();
5959

6060
this.cancellationToken = cancellationToken;
61-
if (
62-
this.updater.currentVersion.compare(updateInfo.version) === -1 ||
63-
true
64-
) {
61+
if (this.updater.currentVersion.compare(updateInfo.version) === -1) {
6562
/*
6663
'latest.txt' points to the latest changelog that has been generated by the CI,
6764
so we need to make a first GET request to get the filename of the changelog

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

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fs = require('fs');
2+
const crypto = require('crypto');
3+
4+
async function hashFile(
5+
file,
6+
algorithm = 'sha512',
7+
encoding = 'base64',
8+
options
9+
) {
10+
return await new Promise((resolve, reject) => {
11+
const hash = crypto.createHash(algorithm);
12+
hash.on('error', reject).setEncoding(encoding);
13+
fs.createReadStream(
14+
file,
15+
Object.assign({}, options, {
16+
highWaterMark: 1024 * 1024,
17+
/* better to use more memory but hash faster */
18+
})
19+
)
20+
.on('error', reject)
21+
.on('end', () => {
22+
hash.end();
23+
resolve(hash.read());
24+
})
25+
.pipe(hash, {
26+
end: false,
27+
});
28+
});
29+
}
30+
31+
module.exports = { hashFile };

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

+58-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,65 @@
1+
const fs = require('fs');
12
const isCI = require('is-ci');
23
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');
38

49
exports.default = async function notarizing(context) {
5-
if (!isCI) {
6-
console.log('Skipping notarization: not on CI.');
7-
return;
8-
}
9-
if (process.env.IS_FORK === 'true') {
10-
console.log('Skipping the app notarization: building from a fork.');
11-
return;
12-
}
13-
const { electronPlatformName, appOutDir } = context;
14-
if (electronPlatformName !== 'darwin') {
15-
return;
16-
}
10+
if (!isCI) {
11+
console.log('Skipping notarization: not on CI.');
12+
return;
13+
}
14+
if (process.env.IS_FORK === 'true') {
15+
console.log('Skipping the app notarization: building from a fork.');
16+
return;
17+
}
18+
const { electronPlatformName, appOutDir } = context;
19+
if (electronPlatformName !== 'darwin') {
20+
return;
21+
}
1722

18-
const appName = context.packager.appInfo.productFilename;
19-
const appBundleId = context.packager.config.appId;
20-
console.log(`>>> Notarizing ${appBundleId} at ${appOutDir}/${appName}.app...`);
23+
const appName = context.packager.appInfo.productFilename;
24+
const appBundleId = context.packager.config.appId;
25+
console.log(
26+
`>>> Notarizing ${appBundleId} at ${appOutDir}/${appName}.app...`
27+
);
2128

22-
return await notarize({
23-
appBundleId,
24-
appPath: `${appOutDir}/${appName}.app`,
25-
appleId: process.env.AC_USERNAME,
26-
appleIdPassword: process.env.AC_PASSWORD,
27-
});
29+
await notarize({
30+
appBundleId,
31+
appPath: `${appOutDir}/${appName}.app`,
32+
appleId: process.env.AC_USERNAME,
33+
appleIdPassword: process.env.AC_PASSWORD,
34+
});
35+
return await recalculateHash();
2836
};
37+
38+
async function recalculateHash() {
39+
const { platform } = process;
40+
const cwd = join(__dirname, '..', 'build', 'dist');
41+
const channelFilePath = join(cwd, getChannelFile(platform));
42+
const yaml = require('yaml');
43+
44+
try {
45+
let fileContents = fs.readFileSync(channelFilePath, 'utf8');
46+
const newChannelFile = yaml.parse(fileContents);
47+
const { files, path } = newChannelFile;
48+
const newSha512 = await hashFile(join(cwd, path));
49+
newChannelFile.sha512 = newSha512;
50+
if (!!files) {
51+
const newFiles = [];
52+
for (let file of files) {
53+
const { url } = file;
54+
const { size } = fs.statSync(join(cwd, url));
55+
const newSha512 = await hashFile(join(cwd, url));
56+
newFiles.push({ ...file, sha512: newSha512, size });
57+
}
58+
newChannelFile.files = newFiles;
59+
}
60+
console.log(channelFilePath);
61+
fs.writeFileSync(channelFilePath, yaml.stringify(newChannelFile));
62+
} catch (e) {
63+
console.log(e);
64+
}
65+
}

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

+6-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"electron-notarize": "^0.3.0",
1818
"is-ci": "^2.0.0",
1919
"ncp": "^2.0.0",
20-
"shelljs": "^0.8.3"
20+
"shelljs": "^0.8.3",
21+
"crypto": "^1.0.1",
22+
"yaml": "^1.10.2"
2123
},
2224
"scripts": {
2325
"build": "yarn download:plugins && theia build --mode development && yarn patch",
@@ -92,19 +94,12 @@
9294
"gatekeeperAssess": false,
9395
"entitlements": "resources/entitlements.mac.plist",
9496
"entitlementsInherit": "resources/entitlements.mac.plist",
95-
"target": [
96-
"dmg",
97-
"zip"
98-
]
97+
"target": "default"
9998
},
10099
"linux": {
101100
"target": [
102-
{
103-
"target": "zip"
104-
},
105-
{
106-
"target": "AppImage"
107-
}
101+
"zip",
102+
"AppImage"
108103
],
109104
"category": "Development",
110105
"icon": "resources/icons"

Diff for: electron/packager/config.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,12 @@ function getVersion() {
8080
}
8181
if (!isRelease) {
8282
if (isNightly) {
83-
version = `${version}-nightly.${timestamp()}`;
83+
version = `${version}-nightly-${timestamp()}`;
8484
} else {
85-
version = `${version}-snapshot.${currentCommitish()}`;
85+
version = `${version}-snapshot-${currentCommitish()}`;
8686
}
87-
if (!isRelease) {
88-
if (isNightly) {
89-
version = `${version}-nightly-${timestamp()}`;
90-
} else {
91-
version = `${version}-snapshot-${currentCommitish()}`;
92-
}
93-
if (!semver.valid(version)) {
94-
throw new Error(`Invalid patched version: '${version}'.`);
95-
}
87+
if (!semver.valid(version)) {
88+
throw new Error(`Invalid patched version: '${version}'.`);
9689
}
9790
}
9891
return version;

Diff for: electron/packager/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"author": "Arduino SA",
1414
"license": "AGPL-3.0-or-later",
1515
"dependencies": {
16+
"7zip-min": "^1.1.1",
1617
"@types/file-type": "^10.9.1",
1718
"@types/temp": "^0.8.32",
18-
"7zip-min": "^1.1.1",
1919
"chai": "^4.2.0",
2020
"dateformat": "^3.0.3",
2121
"deepmerge": "2.01",
@@ -25,8 +25,8 @@
2525
"is-ci": "^2.0.0",
2626
"mocha": "^7.1.1",
2727
"semver": "^7.3.2",
28-
"sinon": "^9.0.1",
2928
"shelljs": "^0.8.3",
29+
"sinon": "^9.0.1",
3030
"temp": "^0.9.1",
3131
"yargs": "^12.0.5"
3232
},
@@ -39,4 +39,4 @@
3939
"watch-extensions": "js",
4040
"timeout": 10000
4141
}
42-
}
42+
}

Diff for: electron/packager/yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1679,4 +1679,4 @@ yargs@^15.0.2:
16791679
string-width "^4.2.0"
16801680
which-module "^2.0.0"
16811681
y18n "^4.0.0"
1682-
yargs-parser "^18.1.1"
1682+
yargs-parser "^18.1.1"

0 commit comments

Comments
 (0)