Skip to content

Commit

Permalink
Code sign retry 3 times (#2943)
Browse files Browse the repository at this point in the history
* Replace deprecated steps github action

* Windows codesign retry 3 times

---------

Co-authored-by: Hien To <[email protected]>
  • Loading branch information
hiento09 and hientominh committed May 24, 2024
1 parent 9cf9fa0 commit 20c9c3f
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions electron/sign.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
})
}

Expand All @@ -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)
}
}

0 comments on commit 20c9c3f

Please sign in to comment.