| 
									
										
										
										
											2022-04-05 16:13:11 -07:00
										 |  |  | // Copyright 2022 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import type { BuildResult } from 'electron-builder'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 14:57:49 -07:00
										 |  |  | import { notarize } from '@electron/notarize'; | 
					
						
							| 
									
										
										
										
											2022-04-05 16:13:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import * as packageJson from '../../package.json'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export async function afterAllArtifactBuild({ | 
					
						
							|  |  |  |   platformToTargets, | 
					
						
							|  |  |  |   artifactPaths, | 
					
						
							|  |  |  | }: BuildResult): Promise<void> { | 
					
						
							|  |  |  |   const platforms = Array.from(platformToTargets.keys()).map( | 
					
						
							|  |  |  |     platform => platform.name | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  |   if (platforms.length !== 1) { | 
					
						
							|  |  |  |     console.log(`notarize: Skipping, too many platforms ${platforms}`); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (platforms[0] !== 'mac') { | 
					
						
							|  |  |  |     console.log(`notarize: Skipping, platform is ${platforms[0]}`); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 15:26:30 -07:00
										 |  |  |   const teamId = process.env.APPLE_TEAM_ID; | 
					
						
							|  |  |  |   if (!teamId) { | 
					
						
							|  |  |  |     console.warn( | 
					
						
							|  |  |  |       'teamId must be provided in environment variable APPLE_TEAM_ID' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-05 16:13:11 -07:00
										 |  |  |   const artifactsToStaple = artifactPaths.filter(artifactPath => | 
					
						
							| 
									
										
										
										
											2022-04-05 17:56:53 -07:00
										 |  |  |     /^.*mac-universal.*\.dmg$/.test(artifactPath) | 
					
						
							| 
									
										
										
										
											2022-04-05 16:13:11 -07:00
										 |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-04-05 17:56:53 -07:00
										 |  |  |   if (artifactsToStaple.length !== 1) { | 
					
						
							|  |  |  |     console.log(`notarize: Skipping, too many dmgs ${artifactsToStaple}`); | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2022-04-05 16:13:11 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-04-05 17:56:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const [dmgPath] = artifactsToStaple; | 
					
						
							|  |  |  |   console.log(`Notarizing dmg: ${dmgPath}`); | 
					
						
							| 
									
										
										
										
											2023-10-30 15:26:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-05 17:56:53 -07:00
										 |  |  |   await notarize({ | 
					
						
							|  |  |  |     appBundleId, | 
					
						
							|  |  |  |     appPath: dmgPath, | 
					
						
							|  |  |  |     appleId, | 
					
						
							|  |  |  |     appleIdPassword, | 
					
						
							| 
									
										
										
										
											2023-10-30 15:26:30 -07:00
										 |  |  |     teamId, | 
					
						
							| 
									
										
										
										
											2022-04-05 17:56:53 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-04-05 16:13:11 -07:00
										 |  |  | } |