mirror of
https://github.com/zadam/trilium.git
synced 2026-03-04 14:58:51 +01:00
feat(electron-forge): introduce basic expotential back-off for signing
This commit is contained in:
parent
4433d034db
commit
31d8287e1b
@ -1,8 +1,8 @@
|
||||
const child_process = require("child_process");
|
||||
const child_process = require("child_proces");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
module.exports = function (filePath) {
|
||||
module.exports = async function (filePath) {
|
||||
const { WINDOWS_SIGN_EXECUTABLE } = process.env;
|
||||
|
||||
if (!WINDOWS_SIGN_EXECUTABLE) {
|
||||
@ -13,18 +13,46 @@ module.exports = function (filePath) {
|
||||
const outputDir = path.join(__dirname, "sign");
|
||||
console.log("Output dir is ", path.resolve(outputDir));
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir);
|
||||
fs.mkdirSync(outputDir);
|
||||
}
|
||||
|
||||
const command = `${WINDOWS_SIGN_EXECUTABLE} --executable "${filePath}"`;
|
||||
console.log(`[Sign] Running ${command}`);
|
||||
|
||||
try {
|
||||
child_process.execSync(command);
|
||||
} catch (e) {
|
||||
console.warn(`[Sign] Unable to sign ${filePath} due to:\n${e.stdout.toString("utf-8")})}`)
|
||||
return;
|
||||
let remainingTries = 10;
|
||||
let sleepTime = 10_000;
|
||||
while (remainingTries > 0) {
|
||||
try {
|
||||
child_process.execSync(command);
|
||||
console.log(`[Sign] Signed ${filePath} successfully.`);
|
||||
break;
|
||||
} catch (e) {
|
||||
const output = e.stdout.toString("utf-8");
|
||||
console.warn(`[Sign] Unable to sign ${filePath} due to:\n${output}`);
|
||||
|
||||
// Check if the error is retryable.
|
||||
if (!output.includes("http://timestamp.digicert.com")) {
|
||||
console.warn("Cannot retry due to unknown error.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.info(`Waiting for ${sleepTime / 1000}s before retrying...`);
|
||||
}
|
||||
|
||||
await sleep(sleepTime);
|
||||
sleepTime *= 2;
|
||||
remainingTries--;
|
||||
}
|
||||
|
||||
console.log(`[Sign] Signed ${filePath} successfully.`);
|
||||
}
|
||||
if (remainingTries < 1) {
|
||||
console.error("Failed to sign.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sleep(time_ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, time_ms);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user