From 20c9c3ff2b135923563663b29adffb32f4cabcda Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Fri, 24 May 2024 17:59:44 +0700 Subject: [PATCH] Code sign retry 3 times (#2943) * Replace deprecated steps github action * Windows codesign retry 3 times --------- Co-authored-by: Hien To --- electron/sign.js | 63 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/electron/sign.js b/electron/sign.js index 73afedc4ef..9955e53e8f 100644 --- a/electron/sign.js +++ b/electron/sign.js @@ -1,5 +1,28 @@ const { exec } = require('child_process') +function execCommandWithRetry(command, retries = 3) { + return new Promise((resolve, reject) => { + const execute = (attempt) => { + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Error: ${error}`) + if (attempt < retries) { + console.log(`Retrying... Attempt ${attempt + 1}`) + execute(attempt + 1) + } else { + return reject(error) + } + } else { + console.log(`stdout: ${stdout}`) + console.error(`stderr: ${stderr}`) + resolve() + } + }) + } + execute(0) + }) +} + function sign({ path, name, @@ -13,16 +36,9 @@ function sign({ }) { return new Promise((resolve, reject) => { const command = `azuresigntool.exe sign -kvu "${certUrl}" -kvi "${clientId}" -kvt "${tenantId}" -kvs "${clientSecret}" -kvc "${certName}" -tr "${timestampServer}" -v "${path}"` - - exec(command, (error, stdout, stderr) => { - if (error) { - console.error(`Error: ${error}`) - return reject(error) - } - console.log(`stdout: ${stdout}`) - console.error(`stderr: ${stderr}`) - resolve() - }) + execCommandWithRetry(command) + .then(resolve) + .catch(reject) }) } @@ -34,15 +50,20 @@ exports.default = async function (options) { const certName = process.env.AZURE_CERT_NAME const timestampServer = 'http://timestamp.globalsign.com/tsa/r6advanced1' - await sign({ - path: options.path, - name: 'jan-win-x64', - certUrl, - clientId, - tenantId, - clientSecret, - certName, - timestampServer, - version: options.version, - }) + try { + await sign({ + path: options.path, + name: 'jan-win-x64', + certUrl, + clientId, + tenantId, + clientSecret, + certName, + timestampServer, + version: options.version, + }) + } catch (error) { + console.error('Failed to sign after 3 attempts:', error) + process.exit(1) + } }