Skip to content

Commit dd084ae

Browse files
committed
fix: skip notarize when electron-builder skipped signing
1 parent b30f6c7 commit dd084ae

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

build/notarize.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,42 @@ const isEmpty = v => !v || v.length === 0;
1515

1616
const { execSync } = require('node:child_process');
1717

18+
function runCommandWithExitCode(command) {
19+
try {
20+
const output = execSync(command, { stdio: 'pipe' });
21+
return { success: true, output: output.toString().trim() };
22+
} catch (error) {
23+
return { success: false, code: error.status, message: error.stderr.toString().trim() };
24+
}
25+
}
26+
1827
exports.default = async function notarizing(context) {
1928
const { electronPlatformName, appOutDir } = context;
2029
if (electronPlatformName !== 'darwin') {
2130
return;
2231
}
23-
log('Notarizing mac application');
2432

2533
const appName = context.packager.appInfo.productFilename;
34+
35+
const appPath = `${appOutDir}/${appName}.app`;
36+
const zipPath = `${appOutDir}/${appName}.zip`;
37+
38+
const verifyCheck = runCommandWithExitCode(`codesign --verify --deep --strict "${appPath}"`);
39+
if (!verifyCheck.success) {
40+
if (verifyCheck.code === 1) {
41+
console.error(`Signature is invalid for app "${appPath}".`);
42+
} else if (verifyCheck.code === 2) {
43+
console.error(`"${appPath}" is not signed.`);
44+
} else {
45+
console.error(`Error (${verifyCheck.code}): ${verifyCheck.message} for app: "${appPath}"`);
46+
}
47+
console.warn('skipping notarization step');
48+
return;
49+
}
50+
51+
log(`"${appPath}" signature is valid.`);
52+
log('Notarizing mac application');
53+
2654
const { SIGNING_APPLE_ID, SIGNING_APP_PASSWORD, SIGNING_TEAM_ID } = process.env;
2755

2856
if (isEmpty(SIGNING_APPLE_ID)) {
@@ -40,9 +68,6 @@ exports.default = async function notarizing(context) {
4068
return;
4169
}
4270

43-
const appPath = `${appOutDir}/${appName}.app`;
44-
const zipPath = `${appOutDir}/${appName}.zip`;
45-
4671
console.log(
4772
execSync(`ditto -c -k --sequesterRsrc --keepParent "${appPath}" "${zipPath}"`, {
4873
encoding: 'utf8',

0 commit comments

Comments
 (0)