Code sign retry 3 times (#2943)

* Replace deprecated steps github action

* Windows codesign retry 3 times

---------

Co-authored-by: Hien To <tominhhien97@gmail.com>
This commit is contained in:
hiento09 2024-05-24 17:59:44 +07:00 committed by GitHub
parent 9cf9fa0dd3
commit 20c9c3ff2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,28 @@
const { exec } = require('child_process') 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({ function sign({
path, path,
name, name,
@ -13,16 +36,9 @@ function sign({
}) { }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const command = `azuresigntool.exe sign -kvu "${certUrl}" -kvi "${clientId}" -kvt "${tenantId}" -kvs "${clientSecret}" -kvc "${certName}" -tr "${timestampServer}" -v "${path}"` const command = `azuresigntool.exe sign -kvu "${certUrl}" -kvi "${clientId}" -kvt "${tenantId}" -kvs "${clientSecret}" -kvc "${certName}" -tr "${timestampServer}" -v "${path}"`
execCommandWithRetry(command)
exec(command, (error, stdout, stderr) => { .then(resolve)
if (error) { .catch(reject)
console.error(`Error: ${error}`)
return reject(error)
}
console.log(`stdout: ${stdout}`)
console.error(`stderr: ${stderr}`)
resolve()
})
}) })
} }
@ -34,15 +50,20 @@ exports.default = async function (options) {
const certName = process.env.AZURE_CERT_NAME const certName = process.env.AZURE_CERT_NAME
const timestampServer = 'http://timestamp.globalsign.com/tsa/r6advanced1' const timestampServer = 'http://timestamp.globalsign.com/tsa/r6advanced1'
await sign({ try {
path: options.path, await sign({
name: 'jan-win-x64', path: options.path,
certUrl, name: 'jan-win-x64',
clientId, certUrl,
tenantId, clientId,
clientSecret, tenantId,
certName, clientSecret,
timestampServer, certName,
version: options.version, timestampServer,
}) version: options.version,
})
} catch (error) {
console.error('Failed to sign after 3 attempts:', error)
process.exit(1)
}
} }