Skip to content

Commit fbfb8c6

Browse files
committed
fix(mac): Exits with status=0 when signing fails
Close #2538
1 parent 3c7ef2d commit fbfb8c6

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

packages/electron-builder-lib/src/codeSign.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async function createCustomCertKeychain() {
141141
// copy to temp and then atomic rename to final path
142142
const tmpKeychainPath = path.join(getCacheDirectory(), getTempName("electron-builder-root-certs"))
143143
const keychainPath = path.join(getCacheDirectory(), "electron-builder-root-certs.keychain")
144-
const results = await BluebirdPromise.all<any>([
144+
const results = await Promise.all<any>([
145145
listUserKeychains(),
146146
copyFile(path.join(__dirname, "..", "certs", "root_certs.keychain"), tmpKeychainPath)
147147
.then(() => rename(tmpKeychainPath, keychainPath)),
@@ -210,7 +210,7 @@ export async function createKeychain({tmpDir, cscLink, cscKeyPassword, cscILink,
210210
securityCommands.push(["list-keychains", "-d", "user", "-s", keychainFile].concat(list))
211211
}
212212

213-
await BluebirdPromise.all([
213+
await Promise.all([
214214
// we do not clear downloaded files - will be removed on tmpDir cleanup automatically. not a security issue since in any case data is available as env variables and protected by password.
215215
BluebirdPromise.map(certLinks, (link, i) => downloadCertificate(link, tmpDir, currentDir).then(it => certPaths[i] = it)),
216216
BluebirdPromise.mapSeries(securityCommands, it => exec("security", it))

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,25 @@ import { createCommonTarget, NoOpTarget } from "./targets/targetFactory"
2222
import { CONCURRENCY } from "builder-util/out/fs"
2323

2424
export default class MacPackager extends PlatformPackager<MacConfiguration> {
25-
readonly codeSigningInfo: Promise<CodeSigningInfo>
25+
readonly codeSigningInfo = new Lazy<CodeSigningInfo>(() => {
26+
if (this.packagerOptions.cscLink == null || process.platform !== "darwin") {
27+
return Promise.resolve({keychainName: process.env.CSC_KEYCHAIN || null})
28+
}
29+
30+
return createKeychain({
31+
tmpDir: this.info.tempDirManager,
32+
cscLink: this.packagerOptions.cscLink!,
33+
cscKeyPassword: this.getCscPassword(),
34+
cscILink: this.packagerOptions.cscInstallerLink,
35+
cscIKeyPassword: this.packagerOptions.cscInstallerKeyPassword,
36+
currentDir: this.projectDir
37+
})
38+
})
2639

2740
private _iconPath = new Lazy(() => this.getOrConvertIcon("icns"))
2841

2942
constructor(info: Packager) {
3043
super(info, Platform.MAC)
31-
32-
if (this.packagerOptions.cscLink == null || process.platform !== "darwin") {
33-
this.codeSigningInfo = BluebirdPromise.resolve({keychainName: process.env.CSC_KEYCHAIN || null})
34-
}
35-
else {
36-
this.codeSigningInfo = createKeychain({
37-
tmpDir: info.tempDirManager,
38-
cscLink: this.packagerOptions.cscLink!,
39-
cscKeyPassword: this.getCscPassword(),
40-
cscILink: this.packagerOptions.cscInstallerLink,
41-
cscIKeyPassword: this.packagerOptions.cscInstallerKeyPassword,
42-
currentDir: this.projectDir
43-
})
44-
}
4544
}
4645

4746
get defaultTarget(): Array<string> {
@@ -141,7 +140,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
141140
return
142141
}
143142

144-
const keychainName = (await this.codeSigningInfo).keychainName
143+
const keychainName = (await this.codeSigningInfo.value).keychainName
145144
const explicitType = isMas ? masOptions!.type : macOptions.type
146145
const type = explicitType || "distribution"
147146
const isDevelopment = type === "development"
@@ -264,7 +263,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
264263
await createMacApp(this, appOutDir, asarIntegrity)
265264

266265
const wantedLanguages = asArray(this.platformSpecificBuildOptions.electronLanguages)
267-
if (wantedLanguages == null) {
266+
if (wantedLanguages.length === 0) {
268267
return
269268
}
270269

packages/electron-builder-lib/src/targets/dmg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class DmgTarget extends Target {
9494
return
9595
}
9696

97-
const keychainName = (await packager.codeSigningInfo).keychainName
97+
const keychainName = (await packager.codeSigningInfo.value).keychainName
9898
const certificateType = "Developer ID Application"
9999
let identity = await findIdentity(certificateType, qualifier, keychainName)
100100
if (identity == null) {

packages/electron-builder-lib/src/targets/pkg.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import BluebirdPromise from "bluebird-lst"
21
import { Arch, debug, exec, use } from "builder-util"
32
import { statOrNull } from "builder-util/out/fs"
43
import { getNotLocalizedLicenseFiles } from "builder-util/out/license"
@@ -38,14 +37,14 @@ export class PkgTarget extends Target {
3837

3938
this.logBuilding("pkg", artifactPath, arch)
4039

41-
const keychainName = (await packager.codeSigningInfo).keychainName
40+
const keychainName = (await packager.codeSigningInfo.value).keychainName
4241

4342
const appOutDir = this.outDir
4443
// https://developer.apple.com/library/content/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html
4544
const distInfoFile = path.join(appOutDir, "distribution.xml")
4645

4746
const innerPackageFile = path.join(appOutDir, `${filterCFBundleIdentifier(appInfo.id)}.pkg`)
48-
const identity = (await BluebirdPromise.all([
47+
const identity = (await Promise.all([
4948
findIdentity(certType, options.identity || packager.platformSpecificBuildOptions.identity, keychainName),
5049
this.customizeDistributionConfiguration(distInfoFile, appPath),
5150
this.buildComponentPackage(appPath, innerPackageFile),
@@ -62,7 +61,7 @@ export class PkgTarget extends Target {
6261
await exec("productbuild", args, {
6362
cwd: appOutDir,
6463
})
65-
await BluebirdPromise.all([unlink(innerPackageFile), unlink(distInfoFile)])
64+
await Promise.all([unlink(innerPackageFile), unlink(distInfoFile)])
6665

6766
packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, "pkg", arch))
6867
}

test/src/helpers/runTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ async function runTests() {
6262
testPatterns.push("mainEntryTest")
6363
testPatterns.push("PublishManagerTest", "ArtifactPublisherTest", "httpRequestTest", "RepoSlugTest")
6464
testPatterns.push("macPackagerTest")
65-
testPatterns.push("portableTest")
6665
testPatterns.push("linuxPackagerTest")
6766
testPatterns.push("ignoreTest")
6867
}
6968
else {
69+
testPatterns.push("portableTest")
7070
testPatterns.push("BuildTest")
7171
testPatterns.push("assistedInstallerTest")
7272
testPatterns.push("linuxArchiveTest")

test/src/mac/macPackagerTest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ test.ifMac.ifAll("two-package", () => assertPack("test-app", {
2121
}, {
2222
signed: true,
2323
checkMacApp: async appDir => {
24-
expect((await readdir(path.join(appDir, "Contents", "Resources"))).filter(it => !it.startsWith("."))).toMatchSnapshot()
24+
expect((await readdir(path.join(appDir, "Contents", "Resources")))
25+
.filter(it => !it.startsWith("."))
26+
.sort()).toMatchSnapshot()
2527
},
2628
}))
2729

0 commit comments

Comments
 (0)