| 
									
										
										
										
											2023-11-03 11:35:16 -07:00
										 |  |  | // Copyright 2019 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { execSync } from 'child_process'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { realpath } from 'fs-extra'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import type { CustomWindowsSignTaskConfiguration } from 'electron-builder'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export async function sign( | 
					
						
							|  |  |  |   configuration: CustomWindowsSignTaskConfiguration | 
					
						
							|  |  |  | ): Promise<void> { | 
					
						
							|  |  |  |   // In CI, we remove certificate information from package.json to disable signing
 | 
					
						
							|  |  |  |   if (!configuration.options.certificateSha1) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const scriptPath = process.env.SIGN_WINDOWS_SCRIPT; | 
					
						
							|  |  |  |   if (!scriptPath) { | 
					
						
							|  |  |  |     throw new Error( | 
					
						
							|  |  |  |       'path to windows sign script must be provided in environment variable SIGN_WINDOWS_SCRIPT' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-03 14:01:43 -07:00
										 |  |  |   const target = await realpath(configuration.path); | 
					
						
							| 
									
										
										
										
											2023-11-03 11:35:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // The script will update the file in-place
 | 
					
						
							| 
									
										
										
										
											2023-11-03 16:28:39 -07:00
										 |  |  |   const returnCode = execSync(`bash "${scriptPath}" "${target}"`, { | 
					
						
							| 
									
										
										
										
											2023-11-03 11:35:16 -07:00
										 |  |  |     stdio: [null, process.stdout, process.stderr], | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2023-11-03 15:44:34 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (returnCode) { | 
					
						
							|  |  |  |     throw new Error(`sign-windows: Script returned code ${returnCode}`); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-11-03 11:35:16 -07:00
										 |  |  | } |