Skip to content

Commit

Permalink
Tools: Add repeat mechanism when electron-builder randomly fails to b…
Browse files Browse the repository at this point in the history
…uild
  • Loading branch information
laurent22 committed Feb 5, 2023
1 parent 1e2aa4e commit 89eb012
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 38 deletions.
3 changes: 3 additions & 0 deletions packages/app-desktop/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const tasks = {
electronRebuild: {
fn: require('./tools/electronRebuild.js'),
},
electronBuilder: {
fn: require('./tools/electronBuilder.js'),
},
tsc: require('@joplin/tools/gulp/tasks/tsc'),
updateIgnoredTypeScriptBuild: require('@joplin/tools/gulp/tasks/updateIgnoredTypeScriptBuild'),
buildCommandIndex: require('@joplin/tools/gulp/tasks/buildCommandIndex'),
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"main": "main.js",
"private": true,
"scripts": {
"dist": "yarn run electronRebuild && npx electron-builder",
"dist": "yarn run electronRebuild && yarn run electronBuilder",
"build": "gulp build",
"postinstall": "yarn run build",
"electronBuilder": "gulp electronBuilder",
"electronRebuild": "gulp electronRebuild",
"tsc": "tsc --project tsconfig.json",
"watch": "tsc --watch --preserveWatchOutput --project tsconfig.json",
Expand Down
27 changes: 27 additions & 0 deletions packages/app-desktop/tools/electronBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const execCommand = require('./execCommand');

async function main() {
process.chdir(`${__dirname}/..`);

const maxTries = 3;

for (let i = 0; i < maxTries; i++) {
try {
console.info(await execCommand(['yarn', 'run', 'electron-builder'].join(' ')));
console.info('electronBuilder: electron-builder completed successfully');
break;
} catch (error) {
console.info(error.stdout);
console.error(error);

if (error.stdout.includes('cannot resolve') && i !== maxTries - 1) {
console.info(`electronBuilder: electron-builder could not download an asset - trying again (${i + 1})`);
continue;
} else {
throw error;
}
}
}
}

module.exports = main;
20 changes: 1 addition & 19 deletions packages/app-desktop/tools/electronRebuild.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
const execCommand = function(command) {
const exec = require('child_process').exec;

console.info(`Running: ${command}`);

return new Promise((resolve, reject) => {
exec(command, (error, stdout) => {
if (error) {
if (error.signal === 'SIGTERM') {
resolve('Process was killed');
} else {
reject(error);
}
} else {
resolve(stdout.trim());
}
});
});
};
const execCommand = require('./execCommand');

const isWindows = () => {
return process && process.platform === 'win32';
Expand Down
22 changes: 22 additions & 0 deletions packages/app-desktop/tools/execCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const execCommand = (command) => {
const exec = require('child_process').exec;

console.info(`Running: ${command}`);

return new Promise((resolve, reject) => {
exec(command, (error, stdout) => {
if (error) {
if (error.signal === 'SIGTERM') {
resolve('Process was killed');
} else {
error.stdout = stdout;
reject(error);
}
} else {
resolve(stdout.trim());
}
});
});
};

module.exports = execCommand;
19 changes: 1 addition & 18 deletions packages/app-desktop/tools/notarizeMacApp.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
const fs = require('fs');
const path = require('path');
const electron_notarize = require('electron-notarize');

function execCommand(command) {
const exec = require('child_process').exec;

return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
if (error.signal === 'SIGTERM') {
resolve('Process was killed');
} else {
reject(new Error([stdout.trim(), stderr.trim()].join('\n')));
}
} else {
resolve([stdout.trim(), stderr.trim()].join('\n'));
}
});
});
}
const execCommand = require('./execCommand');

function isDesktopAppTag(tagName) {
if (!tagName) return false;
Expand Down

0 comments on commit 89eb012

Please sign in to comment.