File size: 1,420 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env node

const path = require( 'path' );
const { notarize } = require( '@electron/notarize' );

const APP_ID = 'com.automattic.wordpress';
const NOTARIZATION_ID = process.env.WPDESKTOP_NOTARIZATION_ID;
const NOTARIZATION_PWD = process.env.WPDESKTOP_NOTARIZATION_PWD;
const NOTARIZATION_ASC_PROVIDER = process.env.APPLE_DEVELOPER_SHORT_NAME;

const circleTag = process.env.CIRCLE_TAG;
const shouldNotarize =
	process.platform === 'darwin' && !! circleTag && circleTag.startsWith( 'desktop-v' );

function elapsed( start ) {
	const now = new Date();

	const ms = Math.abs( now.getTime() - start.getTime() );
	const diff = new Date( ms );

	return `${ diff.getMinutes() } minutes, ${ diff.getSeconds() } seconds`;
}

module.exports = async function ( context ) {
	if ( ! shouldNotarize ) {
		return;
	}

	const arch = context.appOutDir.includes( 'arm64' ) ? 'arm64' : 'x64';
	const app = path.join( context.appOutDir, `${ context.packager.appInfo.productFilename }.app` );
	const appName = path.basename( app );

	const start = new Date();
	console.log( `  • notarizing ${ appName } (${ arch })...` );
	await notarize( {
		appBundleId: APP_ID,
		appPath: app,
		appleId: NOTARIZATION_ID,
		appleIdPassword: NOTARIZATION_PWD,
		ascProvider: NOTARIZATION_ASC_PROVIDER,
		teamId: NOTARIZATION_ASC_PROVIDER,
	} );
	console.log( `  • done notarizing ${ appName } ( ${ arch } ), took ${ elapsed( start ) }` );
};