Run notarization in afterPack script

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2022-02-24 11:59:40 -08:00 committed by GitHub
parent d637985796
commit f44972888f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 91 deletions

View File

@ -18,7 +18,7 @@
"generate": "npm-run-all build-protobuf transpile sass get-expire-time copy-and-concat",
"build-release": "yarn run build",
"sign-release": "node ts/updater/generateSignature.js",
"notarize": "node ts/build/notarize.js",
"notarize": "echo 'No longer necessary'",
"get-strings": "node ts/scripts/get-strings.js",
"get-expire-time": "node ts/scripts/get-expire-time.js",
"copy-and-concat": "node ts/scripts/copy-and-concat.js",

View File

@ -1,90 +0,0 @@
// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { join, resolve } from 'path';
import { readdir as readdirCallback } from 'fs';
import pify from 'pify';
import { notarize } from 'electron-notarize';
import * as packageJson from '../../package.json';
const readdir = pify(readdirCallback);
/* eslint-disable no-console */
go().catch(error => {
console.error(error.stack);
process.exit(1);
});
async function go() {
if (process.platform !== 'darwin') {
console.log('notarize: Skipping, not on macOS');
return;
}
const appPaths = await findDMGs();
const appBundleId = packageJson.build.appId;
if (!appBundleId) {
throw new Error(
'appBundleId must be provided in package.json: build.appId'
);
}
const appleId = process.env.APPLE_USERNAME;
if (!appleId) {
throw new Error(
'appleId must be provided in environment variable APPLE_USERNAME'
);
}
const appleIdPassword = process.env.APPLE_PASSWORD;
if (!appleIdPassword) {
throw new Error(
'appleIdPassword must be provided in environment variable APPLE_PASSWORD'
);
}
console.log('Notarizing with...');
console.log(` primaryBundleId: ${appBundleId}`);
console.log(` username: ${appleId}`);
for (const appPath of appPaths) {
console.log(` file: ${appPath}`);
// eslint-disable-next-line no-await-in-loop
await notarize({
appBundleId,
appPath,
appleId,
appleIdPassword,
});
}
}
const IS_DMG = /\.dmg$/;
async function findDMGs(): Promise<Array<string>> {
const releaseDir = resolve('release');
const files: Array<string> = await readdir(releaseDir);
const max = files.length;
const results = new Array<string>();
for (let i = 0; i < max; i += 1) {
const file = files[i];
const fullPath = join(releaseDir, file);
if (IS_DMG.test(file)) {
results.push(fullPath);
}
}
if (results.length === 0) {
throw new Error("No suitable files found in 'release' folder!");
}
return results;
}

View File

@ -6,10 +6,14 @@ import { afterPack as fuseElectron } from './fuse-electron';
import { afterPack as mergeASARs } from './merge-macos-asars';
import { afterPack as copyPacks } from './copy-language-packs';
import { afterPack as pruneMacOSRelease } from './prune-macos-release';
import { afterPack as notarize } from './notarize';
export async function afterPack(context: AfterPackContext): Promise<void> {
await pruneMacOSRelease(context);
await mergeASARs(context);
await fuseElectron(context);
await copyPacks(context);
// This must be the last step
await notarize(context);
}

62
ts/scripts/notarize.ts Normal file
View File

@ -0,0 +1,62 @@
// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import path from 'path';
import type { AfterPackContext } from 'electron-builder';
import { notarize } from 'electron-notarize';
import * as packageJson from '../../package.json';
/* eslint-disable no-console */
export async function afterPack({
appOutDir,
packager,
electronPlatformName,
}: AfterPackContext): Promise<void> {
if (electronPlatformName !== 'darwin') {
console.log('notarize: Skipping, not on macOS');
return;
}
const { productFilename } = packager.appInfo;
const appPath = path.join(appOutDir, `${productFilename}.app`);
const appBundleId = packageJson.build.appId;
if (!appBundleId) {
throw new Error(
'appBundleId must be provided in package.json: build.appId'
);
}
const appleId = process.env.APPLE_USERNAME;
if (!appleId) {
console.warn(
'appleId must be provided in environment variable APPLE_USERNAME'
);
return;
}
const appleIdPassword = process.env.APPLE_PASSWORD;
if (!appleIdPassword) {
console.warn(
'appleIdPassword must be provided in environment variable APPLE_PASSWORD'
);
return;
}
console.log('Notarizing with...');
console.log(` primaryBundleId: ${appBundleId}`);
console.log(` username: ${appleId}`);
console.log(` file: ${appPath}`);
// eslint-disable-next-line no-await-in-loop
await notarize({
appBundleId,
appPath,
appleId,
appleIdPassword,
});
}