Skip to content

Commit 9bcede8

Browse files
authored
fix(mac): add retry in mac code sign (#8101)
1 parent 27953bb commit 9bcede8

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

.changeset/wild-buttons-pretend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
fix(mac): add retry mechanism in mac code signing for `electron/osx-sign`.

packages/app-builder-lib/src/codeSign/macCodeSign.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import BluebirdPromise from "bluebird-lst"
2-
import { exec, InvalidConfigurationError, isEmptyOrSpaces, isEnvTrue, isPullRequest, log, TmpDir } from "builder-util/out/util"
2+
import { exec, InvalidConfigurationError, isEmptyOrSpaces, isEnvTrue, isPullRequest, log, TmpDir, retry } from "builder-util/out/util"
33
import { copyFile, unlinkIfExists } from "builder-util/out/fs"
44
import { Fields, Logger } from "builder-util/out/log"
55
import { randomBytes, createHash } from "crypto"
@@ -11,6 +11,8 @@ import { getTempName } from "temp-file"
1111
import { isAutoDiscoveryCodeSignIdentity } from "../util/flags"
1212
import { importCertificate } from "./codesign"
1313
import { Identity as _Identity } from "@electron/osx-sign/dist/cjs/util-identities"
14+
import { SignOptions } from "@electron/osx-sign/dist/cjs/types"
15+
import { signAsync } from "@electron/osx-sign"
1416

1517
export const appleCertificatePrefixes = ["Developer ID Application:", "Developer ID Installer:", "3rd Party Mac Developer Application:", "3rd Party Mac Developer Installer:"]
1618

@@ -213,13 +215,8 @@ async function importCerts(keychainFile: string, paths: Array<string>, keyPasswo
213215
}
214216
}
215217

216-
/** @private */
217-
export function sign(path: string, name: string, keychain: string): Promise<any> {
218-
const args = ["--deep", "--force", "--sign", name, path]
219-
if (keychain != null) {
220-
args.push("--keychain", keychain)
221-
}
222-
return exec("/usr/bin/codesign", args)
218+
export async function sign(opts: SignOptions): Promise<void> {
219+
return retry(() => signAsync(opts), 3, 5000, 5000)
223220
}
224221

225222
export let findIdentityRawResult: Promise<Array<string>> | null = null

packages/app-builder-lib/src/macPackager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import BluebirdPromise from "bluebird-lst"
22
import { deepAssign, Arch, AsyncTaskManager, exec, InvalidConfigurationError, log, use, getArchSuffix } from "builder-util"
3-
import { signAsync } from "@electron/osx-sign"
43
import { PerFileSignOptions, SignOptions } from "@electron/osx-sign/dist/cjs/types"
54
import { mkdir, readdir } from "fs/promises"
65
import { Lazy } from "lazy-val"
76
import * as path from "path"
87
import { copyFile, statOrNull, unlinkIfExists } from "builder-util/out/fs"
98
import { orIfFileNotExist } from "builder-util/out/promise"
109
import { AppInfo } from "./appInfo"
11-
import { CertType, CodeSigningInfo, createKeychain, findIdentity, Identity, isSignAllowed, removeKeychain, reportError } from "./codeSign/macCodeSign"
10+
import { CertType, CodeSigningInfo, createKeychain, findIdentity, Identity, isSignAllowed, removeKeychain, reportError, sign } from "./codeSign/macCodeSign"
1211
import { DIR_TARGET, Platform, Target } from "./core"
1312
import { AfterPackContext, ElectronPlatformName } from "./index"
1413
import { MacConfiguration, MasConfiguration, NotarizeLegacyOptions, NotarizeNotaryOptions } from "./options/macOptions"
@@ -408,7 +407,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
408407
customSign ? "executing custom sign" : "signing"
409408
)
410409

411-
return customSign ? Promise.resolve(customSign(opts, this)) : signAsync(opts)
410+
return customSign ? Promise.resolve(customSign(opts, this)) : sign(opts)
412411
}
413412

414413
//noinspection JSMethodCanBeStatic

0 commit comments

Comments
 (0)