Skip to content

Commit 1dc2d43

Browse files
authored
Merge pull request #1352 from session-foundation/ci/fix-mac-build
fix: notarizing macos legacy support got dropped
2 parents e68f070 + dd084ae commit 1dc2d43

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

build/notarize.js

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const { notarize } = require('@electron/notarize');
2-
31
/*
42
Pre-requisites: https://github.com/electron/electron-notarize#prerequisites
53
1. Generate an app specific password
@@ -8,35 +6,80 @@ const { notarize } = require('@electron/notarize');
86

97
/*
108
Notarizing: https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
9+
This script is heavily inspired by https://github.com/electron/notarize/issues/193#issuecomment-2466569367
10+
For up to date official mac information, see https://developer.apple.com/documentation/security/customizing-the-notarization-workflow
1111
*/
1212

1313
const log = msg => console.log(`\n${msg}`);
1414
const isEmpty = v => !v || v.length === 0;
1515

16+
const { execSync } = require('node:child_process');
17+
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+
1627
exports.default = async function notarizing(context) {
1728
const { electronPlatformName, appOutDir } = context;
1829
if (electronPlatformName !== 'darwin') {
1930
return;
2031
}
21-
log('Notarizing mac application');
2232

2333
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+
2454
const { SIGNING_APPLE_ID, SIGNING_APP_PASSWORD, SIGNING_TEAM_ID } = process.env;
2555

26-
if (isEmpty(SIGNING_APPLE_ID) || isEmpty(SIGNING_APP_PASSWORD)) {
27-
log('SIGNING_APPLE_ID or SIGNING_APP_PASSWORD not set.\nTerminating noratization.');
56+
if (isEmpty(SIGNING_APPLE_ID)) {
57+
log('SIGNING_APPLE_ID not set.\nTerminating notarization.');
2858
return;
2959
}
3060

31-
const options = {
32-
appBundleId: 'com.loki-project.messenger-desktop',
33-
appPath: `${appOutDir}/${appName}.app`,
34-
appleId: SIGNING_APPLE_ID,
35-
appleIdPassword: SIGNING_APP_PASSWORD,
36-
};
37-
if (!isEmpty(SIGNING_TEAM_ID)) {
38-
options.ascProvider = SIGNING_TEAM_ID;
39-
options.teamId = SIGNING_TEAM_ID;
61+
if (isEmpty(SIGNING_APP_PASSWORD)) {
62+
log('SIGNING_APP_PASSWORD not set.\nTerminating notarization.');
63+
return;
4064
}
41-
return notarize(options);
65+
66+
if (isEmpty(SIGNING_TEAM_ID)) {
67+
log(' SIGNING_TEAM_ID not set.\nTerminating notarization.');
68+
return;
69+
}
70+
71+
console.log(
72+
execSync(`ditto -c -k --sequesterRsrc --keepParent "${appPath}" "${zipPath}"`, {
73+
encoding: 'utf8',
74+
})
75+
);
76+
77+
console.log(
78+
execSync(
79+
`xcrun notarytool submit "${zipPath}" --team-id "${SIGNING_TEAM_ID}" --apple-id "${SIGNING_APPLE_ID}" --password "${SIGNING_APP_PASSWORD}" --verbose --wait`,
80+
{ encoding: 'utf8' }
81+
)
82+
);
83+
84+
console.log(execSync(`xcrun stapler staple "${appPath}"`, { encoding: 'utf8' }));
4285
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"devDependencies": {
121121
"@commitlint/cli": "^19.8.0",
122122
"@commitlint/config-conventional": "^19.8.0",
123-
"@electron/notarize": "^2.5.0",
124123
"@testing-library/jest-dom": "^6.4.6",
125124
"@testing-library/react": "^15.0.7",
126125
"@testing-library/user-event": "^14.6.1",
@@ -207,6 +206,7 @@
207206
"dmg",
208207
"zip"
209208
],
209+
"notarize": false,
210210
"bundleVersion": "1",
211211
"hardenedRuntime": true,
212212
"gatekeeperAssess": false,

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
tar "^6.2.1"
273273
which "^2.0.2"
274274

275-
"@electron/[email protected]", "@electron/notarize@^2.5.0":
275+
"@electron/[email protected]":
276276
version "2.5.0"
277277
resolved "https://registry.yarnpkg.com/@electron/notarize/-/notarize-2.5.0.tgz#d4d25356adfa29df4a76bd64a8bd347237cd251e"
278278
integrity sha512-jNT8nwH1f9X5GEITXaQ8IF/KdskvIkOFfB2CvwumsveVidzpSc+mvhhTMdAGSYF3O+Nq49lJ7y+ssODRXu06+A==

0 commit comments

Comments
 (0)