| 
									
										
										
										
											2022-04-12 04:21:55 -07:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-31 10:48:47 +08:00
										 |  |  | import argparse | 
					
						
							| 
									
										
										
										
											2018-05-22 13:50:44 -04:00
										 |  |  | import datetime | 
					
						
							| 
									
										
										
										
											2016-08-01 21:03:55 +09:00
										 |  |  | import hashlib | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  | import mmap | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  | import shutil | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | import subprocess | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  | from struct import Struct | 
					
						
							| 
									
										
										
										
											2013-06-29 11:36:02 +08:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-26 11:32:42 -07:00
										 |  |  | sys.path.append( | 
					
						
							|  |  |  |   os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../..")) | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-13 20:40:13 +00:00
										 |  |  | from zipfile import ZipFile | 
					
						
							| 
									
										
										
										
											2022-04-04 02:32:57 -07:00
										 |  |  | from lib.config import PLATFORM, get_target_arch, \ | 
					
						
							| 
									
										
										
										
											2024-10-29 21:41:19 +01:00
										 |  |  |                        get_zip_name, set_verbose_mode, \ | 
					
						
							|  |  |  |                        is_verbose_mode, get_platform_key, \ | 
					
						
							|  |  |  |                        verbose_mode_print | 
					
						
							| 
									
										
										
										
											2018-09-27 13:53:08 -05:00
										 |  |  | from lib.util import get_electron_branding, execute, get_electron_version, \ | 
					
						
							| 
									
										
										
										
											2022-04-04 02:32:57 -07:00
										 |  |  |                      store_artifact, get_electron_exec, get_out_dir, \ | 
					
						
							| 
									
										
										
										
											2020-11-09 13:57:53 -08:00
										 |  |  |                      SRC_DIR, ELECTRON_DIR, TS_NODE | 
					
						
							| 
									
										
										
										
											2013-06-29 11:36:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-27 12:02:18 -07:00
										 |  |  | ELECTRON_VERSION = 'v' + get_electron_version() | 
					
						
							| 
									
										
										
										
											2013-08-31 10:48:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:53:08 -05:00
										 |  |  | PROJECT_NAME = get_electron_branding()['project_name'] | 
					
						
							|  |  |  | PRODUCT_NAME = get_electron_branding()['product_name'] | 
					
						
							| 
									
										
										
										
											2015-04-17 12:13:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  | OUT_DIR = get_out_dir() | 
					
						
							| 
									
										
										
										
											2016-08-25 17:50:12 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | DIST_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION) | 
					
						
							|  |  |  | SYMBOLS_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'symbols') | 
					
						
							|  |  |  | DSYM_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'dsym') | 
					
						
							| 
									
										
										
										
											2022-03-07 15:47:58 -08:00
										 |  |  | DSYM_SNAPSHOT_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, | 
					
						
							|  |  |  |                                   'dsym-snapshot') | 
					
						
							| 
									
										
										
										
											2016-08-25 17:50:12 -07:00
										 |  |  | PDB_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'pdb') | 
					
						
							| 
									
										
										
										
											2019-11-20 17:21:44 -08:00
										 |  |  | DEBUG_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'debug') | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  | TOOLCHAIN_PROFILE_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, | 
					
						
							|  |  |  |                                       'toolchain-profile') | 
					
						
							| 
									
										
										
										
											2021-05-22 11:48:38 -07:00
										 |  |  | CXX_OBJECTS_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, | 
					
						
							|  |  |  |                                       'libcxx_objects') | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											2013-08-31 10:48:47 +08:00
										 |  |  |   args = parse_args() | 
					
						
							| 
									
										
										
										
											2024-10-29 21:41:19 +01:00
										 |  |  |   set_verbose_mode(args.verbose) | 
					
						
							| 
									
										
										
										
											2022-05-09 06:34:17 -07:00
										 |  |  |   if args.upload_to_storage: | 
					
						
							| 
									
										
										
										
											2024-06-13 16:36:45 -05:00
										 |  |  |     utcnow = datetime.datetime.utcnow() | 
					
						
							| 
									
										
										
										
											2018-07-19 14:12:12 -07:00
										 |  |  |     args.upload_timestamp = utcnow.strftime('%Y%m%d') | 
					
						
							| 
									
										
										
										
											2013-08-31 10:48:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   build_version = get_electron_build_version() | 
					
						
							|  |  |  |   if not ELECTRON_VERSION.startswith(build_version): | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |     errmsg = f"Tag ({ELECTRON_VERSION}) should match build ({build_version})\n" | 
					
						
							|  |  |  |     sys.stderr.write(errmsg) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     sys.stderr.flush() | 
					
						
							|  |  |  |     return 1 | 
					
						
							| 
									
										
										
										
											2013-10-03 11:48:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 13:43:20 +08:00
										 |  |  |   tag_exists = False | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  |   release = get_release(args.version) | 
					
						
							|  |  |  |   if not release['draft']: | 
					
						
							|  |  |  |     tag_exists = True | 
					
						
							| 
									
										
										
										
											2015-07-03 13:43:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 06:34:17 -07:00
										 |  |  |   if not args.upload_to_storage: | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |     assert release['exists'], \ | 
					
						
							|  |  |  |           'Release does not exist; cannot upload to GitHub!' | 
					
						
							| 
									
										
										
										
											2017-11-02 16:06:28 +08:00
										 |  |  |     assert tag_exists == args.overwrite, \ | 
					
						
							|  |  |  |           'You have to pass --overwrite to overwrite a published release' | 
					
						
							| 
									
										
										
										
											2018-05-14 17:21:51 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  |   # Upload Electron files. | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  |   # Rename dist.zip to  get_zip_name('electron', version, suffix='') | 
					
						
							|  |  |  |   electron_zip = os.path.join(OUT_DIR, DIST_NAME) | 
					
						
							|  |  |  |   shutil.copy2(os.path.join(OUT_DIR, 'dist.zip'), electron_zip) | 
					
						
							|  |  |  |   upload_electron(release, electron_zip, args) | 
					
						
							| 
									
										
										
										
											2023-02-02 17:39:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   symbols_zip = os.path.join(OUT_DIR, SYMBOLS_NAME) | 
					
						
							|  |  |  |   shutil.copy2(os.path.join(OUT_DIR, 'symbols.zip'), symbols_zip) | 
					
						
							|  |  |  |   upload_electron(release, symbols_zip, args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 14:12:41 -05:00
										 |  |  |   if PLATFORM == 'darwin': | 
					
						
							|  |  |  |     if get_platform_key() == 'darwin' and get_target_arch() == 'x64': | 
					
						
							| 
									
										
										
										
											2020-11-09 12:30:43 -08:00
										 |  |  |       api_path = os.path.join(ELECTRON_DIR, 'electron-api.json') | 
					
						
							|  |  |  |       upload_electron(release, api_path, args) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ts_defs_path = os.path.join(ELECTRON_DIR, 'electron.d.ts') | 
					
						
							|  |  |  |       upload_electron(release, ts_defs_path, args) | 
					
						
							| 
									
										
										
										
											2018-09-24 18:48:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  |     dsym_zip = os.path.join(OUT_DIR, DSYM_NAME) | 
					
						
							|  |  |  |     shutil.copy2(os.path.join(OUT_DIR, 'dsym.zip'), dsym_zip) | 
					
						
							|  |  |  |     upload_electron(release, dsym_zip, args) | 
					
						
							| 
									
										
										
										
											2022-03-07 15:47:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-16 03:46:11 -04:00
										 |  |  |     dsym_snapshot_zip = os.path.join(OUT_DIR, DSYM_SNAPSHOT_NAME) | 
					
						
							|  |  |  |     shutil.copy2(os.path.join(OUT_DIR, 'dsym-snapshot.zip'), dsym_snapshot_zip) | 
					
						
							| 
									
										
										
										
											2023-02-01 12:59:16 +01:00
										 |  |  |     upload_electron(release, dsym_snapshot_zip, args) | 
					
						
							| 
									
										
										
										
											2016-06-24 14:26:05 +02:00
										 |  |  |   elif PLATFORM == 'win32': | 
					
						
							| 
									
										
										
										
											2022-07-26 21:33:07 -07:00
										 |  |  |     pdb_zip = os.path.join(OUT_DIR, PDB_NAME) | 
					
						
							|  |  |  |     shutil.copy2(os.path.join(OUT_DIR, 'pdb.zip'), pdb_zip) | 
					
						
							|  |  |  |     upload_electron(release, pdb_zip, args) | 
					
						
							| 
									
										
										
										
											2019-11-20 17:21:44 -08:00
										 |  |  |   elif PLATFORM == 'linux': | 
					
						
							|  |  |  |     debug_zip = os.path.join(OUT_DIR, DEBUG_NAME) | 
					
						
							|  |  |  |     shutil.copy2(os.path.join(OUT_DIR, 'debug.zip'), debug_zip) | 
					
						
							|  |  |  |     upload_electron(release, debug_zip, args) | 
					
						
							| 
									
										
										
										
											2014-09-20 22:39:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-21 09:06:50 -07:00
										 |  |  |     # Upload libcxx_objects.zip for linux only | 
					
						
							| 
									
										
										
										
											2021-05-22 11:48:38 -07:00
										 |  |  |     libcxx_objects = get_zip_name('libcxx-objects', ELECTRON_VERSION) | 
					
						
							|  |  |  |     libcxx_objects_zip = os.path.join(OUT_DIR, libcxx_objects) | 
					
						
							| 
									
										
										
										
											2021-09-29 20:10:13 +03:00
										 |  |  |     shutil.copy2(os.path.join(OUT_DIR, 'libcxx_objects.zip'), | 
					
						
							|  |  |  |         libcxx_objects_zip) | 
					
						
							| 
									
										
										
										
											2021-05-22 11:48:38 -07:00
										 |  |  |     upload_electron(release, libcxx_objects_zip, args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 17:11:21 -07:00
										 |  |  |     # Upload headers.zip and abi_headers.zip as non-platform specific | 
					
						
							|  |  |  |     if get_target_arch() == "x64": | 
					
						
							|  |  |  |       cxx_headers_zip = os.path.join(OUT_DIR, 'libcxx_headers.zip') | 
					
						
							|  |  |  |       upload_electron(release, cxx_headers_zip, args) | 
					
						
							| 
									
										
										
										
											2021-05-22 11:48:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 17:11:21 -07:00
										 |  |  |       abi_headers_zip = os.path.join(OUT_DIR, 'libcxxabi_headers.zip') | 
					
						
							|  |  |  |       upload_electron(release, abi_headers_zip, args) | 
					
						
							| 
									
										
										
										
											2021-05-22 11:48:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-19 10:26:18 +08:00
										 |  |  |   # Upload free version of ffmpeg. | 
					
						
							| 
									
										
										
										
											2016-08-25 17:50:12 -07:00
										 |  |  |   ffmpeg = get_zip_name('ffmpeg', ELECTRON_VERSION) | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  |   ffmpeg_zip = os.path.join(OUT_DIR, ffmpeg) | 
					
						
							| 
									
										
										
										
											2018-10-08 22:19:40 +02:00
										 |  |  |   ffmpeg_build_path = os.path.join(SRC_DIR, 'out', 'ffmpeg', 'ffmpeg.zip') | 
					
						
							| 
									
										
										
										
											2018-09-29 12:27:29 +10:00
										 |  |  |   shutil.copy2(ffmpeg_build_path, ffmpeg_zip) | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  |   upload_electron(release, ffmpeg_zip, args) | 
					
						
							| 
									
										
										
										
											2016-02-19 10:26:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-02 16:54:39 -04:00
										 |  |  |   chromedriver = get_zip_name('chromedriver', ELECTRON_VERSION) | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  |   chromedriver_zip = os.path.join(OUT_DIR, chromedriver) | 
					
						
							|  |  |  |   shutil.copy2(os.path.join(OUT_DIR, 'chromedriver.zip'), chromedriver_zip) | 
					
						
							|  |  |  |   upload_electron(release, chromedriver_zip, args) | 
					
						
							| 
									
										
										
										
											2018-04-02 16:54:39 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 17:26:49 -04:00
										 |  |  |   mksnapshot = get_zip_name('mksnapshot', ELECTRON_VERSION) | 
					
						
							|  |  |  |   mksnapshot_zip = os.path.join(OUT_DIR, mksnapshot) | 
					
						
							| 
									
										
										
										
											2020-07-22 01:45:18 -07:00
										 |  |  |   if get_target_arch().startswith('arm') and PLATFORM != 'darwin': | 
					
						
							| 
									
										
										
										
											2018-04-02 16:54:39 -04:00
										 |  |  |     # Upload the x64 binary for arm/arm64 mksnapshot | 
					
						
							|  |  |  |     mksnapshot = get_zip_name('mksnapshot', ELECTRON_VERSION, 'x64') | 
					
						
							| 
									
										
										
										
											2018-09-27 17:26:49 -04:00
										 |  |  |     mksnapshot_zip = os.path.join(OUT_DIR, mksnapshot) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   shutil.copy2(os.path.join(OUT_DIR, 'mksnapshot.zip'), mksnapshot_zip) | 
					
						
							|  |  |  |   upload_electron(release, mksnapshot_zip, args) | 
					
						
							| 
									
										
										
										
											2017-11-02 16:06:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 13:11:51 -07:00
										 |  |  |   if PLATFORM == 'linux' and get_target_arch() == 'x64': | 
					
						
							|  |  |  |     # Upload the hunspell dictionaries only from the linux x64 build | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |     hunspell_dictionaries_zip = os.path.join( | 
					
						
							|  |  |  |       OUT_DIR, 'hunspell_dictionaries.zip') | 
					
						
							| 
									
										
										
										
											2019-10-31 13:11:51 -07:00
										 |  |  |     upload_electron(release, hunspell_dictionaries_zip, args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 06:34:17 -07:00
										 |  |  |   if not tag_exists and not args.upload_to_storage: | 
					
						
							| 
									
										
										
										
											2018-05-23 12:53:48 -07:00
										 |  |  |     # Upload symbols to symbol server. | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |     run_python_upload_script('upload-symbols.py') | 
					
						
							| 
									
										
										
										
											2018-05-23 12:53:48 -07:00
										 |  |  |     if PLATFORM == 'win32': | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |       run_python_upload_script('upload-node-headers.py', '-v', args.version) | 
					
						
							| 
									
										
										
										
											2015-01-22 18:03:15 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-13 20:40:13 +00:00
										 |  |  |   if PLATFORM == 'win32': | 
					
						
							|  |  |  |     toolchain_profile_zip = os.path.join(OUT_DIR, TOOLCHAIN_PROFILE_NAME) | 
					
						
							|  |  |  |     with ZipFile(toolchain_profile_zip, 'w') as myzip: | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |       myzip.write( | 
					
						
							|  |  |  |         os.path.join(OUT_DIR, 'windows_toolchain_profile.json'), | 
					
						
							|  |  |  |         'toolchain_profile.json') | 
					
						
							| 
									
										
										
										
											2020-01-13 20:40:13 +00:00
										 |  |  |     upload_electron(release, toolchain_profile_zip, args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 19:11:21 -07:00
										 |  |  |   return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-31 10:48:47 +08:00
										 |  |  | def parse_args(): | 
					
						
							|  |  |  |   parser = argparse.ArgumentParser(description='upload distribution file') | 
					
						
							| 
									
										
										
										
											2013-09-26 19:49:09 +08:00
										 |  |  |   parser.add_argument('-v', '--version', help='Specify the version', | 
					
						
							| 
									
										
										
										
											2016-05-24 10:27:46 -07:00
										 |  |  |                       default=ELECTRON_VERSION) | 
					
						
							| 
									
										
										
										
											2017-09-26 10:43:43 +09:00
										 |  |  |   parser.add_argument('-o', '--overwrite', | 
					
						
							|  |  |  |                       help='Overwrite a published release', | 
					
						
							|  |  |  |                       action='store_true') | 
					
						
							| 
									
										
										
										
											2014-03-01 09:36:48 +08:00
										 |  |  |   parser.add_argument('-p', '--publish-release', | 
					
						
							|  |  |  |                       help='Publish the release', | 
					
						
							|  |  |  |                       action='store_true') | 
					
						
							| 
									
										
										
										
											2022-05-09 06:34:17 -07:00
										 |  |  |   parser.add_argument('-s', '--upload_to_storage', | 
					
						
							|  |  |  |                       help='Upload assets to azure bucket', | 
					
						
							|  |  |  |                       dest='upload_to_storage', | 
					
						
							| 
									
										
										
										
											2017-11-02 16:42:09 +08:00
										 |  |  |                       action='store_true', | 
					
						
							|  |  |  |                       default=False, | 
					
						
							|  |  |  |                       required=False) | 
					
						
							| 
									
										
										
										
											2020-11-09 15:08:27 -08:00
										 |  |  |   parser.add_argument('--verbose', | 
					
						
							|  |  |  |                       action='store_true', | 
					
						
							|  |  |  |                       help='Mooooorreee logs') | 
					
						
							| 
									
										
										
										
											2013-08-31 10:48:47 +08:00
										 |  |  |   return parser.parse_args() | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  | def run_python_upload_script(script, *args): | 
					
						
							|  |  |  |   script_path = os.path.join( | 
					
						
							|  |  |  |     ELECTRON_DIR, 'script', 'release', 'uploaders', script) | 
					
						
							| 
									
										
										
										
											2020-10-07 17:13:06 -07:00
										 |  |  |   print(execute([sys.executable, script_path] + list(args))) | 
					
						
							| 
									
										
										
										
											2016-07-31 19:00:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-24 10:27:46 -07:00
										 |  |  | def get_electron_build_version(): | 
					
						
							| 
									
										
										
										
											2020-10-30 03:05:38 -07:00
										 |  |  |   if get_target_arch().startswith('arm') or 'CI' in os.environ: | 
					
						
							| 
									
										
										
										
											2015-07-03 14:30:59 +08:00
										 |  |  |     # In CI we just build as told. | 
					
						
							| 
									
										
										
										
											2016-05-24 10:27:46 -07:00
										 |  |  |     return ELECTRON_VERSION | 
					
						
							| 
									
										
										
										
											2018-09-27 13:14:13 -07:00
										 |  |  |   electron = get_electron_exec() | 
					
						
							| 
									
										
										
										
											2016-05-24 10:27:46 -07:00
										 |  |  |   return subprocess.check_output([electron, '--version']).strip() | 
					
						
							| 
									
										
										
										
											2013-10-03 11:48:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  | class NonZipFileError(ValueError): | 
					
						
							|  |  |  |   """Raised when a given file does not appear to be a zip""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def zero_zip_date_time(fname): | 
					
						
							|  |  |  |   """ Wrap strip-zip zero_zip_date_time within a file opening operation """ | 
					
						
							|  |  |  |   try: | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |     with open(fname, 'r+b') as f: | 
					
						
							|  |  |  |       _zero_zip_date_time(f) | 
					
						
							| 
									
										
										
										
											2022-03-20 19:11:21 -07:00
										 |  |  |   except Exception: | 
					
						
							| 
									
										
										
										
											2022-03-22 17:17:35 -07:00
										 |  |  |     # pylint: disable=W0707 | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |     raise NonZipFileError(fname) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _zero_zip_date_time(zip_): | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |   def purify_extra_data(mm, offset, length, compressed_size=0): | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     extra_header_struct = Struct("<HH") | 
					
						
							|  |  |  |     # 0. id | 
					
						
							|  |  |  |     # 1. length | 
					
						
							|  |  |  |     STRIPZIP_OPTION_HEADER = 0xFFFF | 
					
						
							|  |  |  |     EXTENDED_TIME_DATA = 0x5455 | 
					
						
							|  |  |  |     # Some sort of extended time data, see | 
					
						
							|  |  |  |     # ftp://ftp.info-zip.org/pub/infozip/src/zip30.zip ./proginfo/extrafld.txt | 
					
						
							|  |  |  |     # fallthrough | 
					
						
							|  |  |  |     UNIX_EXTRA_DATA = 0x7875 | 
					
						
							|  |  |  |     # Unix extra data; UID / GID stuff, see | 
					
						
							|  |  |  |     # ftp://ftp.info-zip.org/pub/infozip/src/zip30.zip ./proginfo/extrafld.txt | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |     ZIP64_EXTRA_HEADER = 0x0001 | 
					
						
							|  |  |  |     zip64_extra_struct = Struct("<HHQQ") | 
					
						
							|  |  |  |     # ZIP64. | 
					
						
							| 
									
										
										
										
											2022-04-06 17:19:32 -04:00
										 |  |  |     # When a ZIP64 extra field is present this 8byte length | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |     # will override the 4byte length defined in canonical zips. | 
					
						
							|  |  |  |     # This is in the form: | 
					
						
							|  |  |  |     # - 0x0001 (header_id) | 
					
						
							|  |  |  |     # - 0x0010 [16] (header_length) | 
					
						
							|  |  |  |     # - ... (8byte uncompressed_length) | 
					
						
							|  |  |  |     # - ... (8byte compressed_length) | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     mlen = offset + length | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while offset < mlen: | 
					
						
							|  |  |  |       values = list(extra_header_struct.unpack_from(mm, offset)) | 
					
						
							|  |  |  |       _, header_length = values | 
					
						
							|  |  |  |       extra_struct = Struct("<HH" + "B" * header_length) | 
					
						
							|  |  |  |       values = list(extra_struct.unpack_from(mm, offset)) | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |       header_id, header_length = values[:2] | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if header_id in (EXTENDED_TIME_DATA, UNIX_EXTRA_DATA): | 
					
						
							|  |  |  |         values[0] = STRIPZIP_OPTION_HEADER | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |         for i in range(2, len(values)): | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |           values[i] = 0xff | 
					
						
							|  |  |  |         extra_struct.pack_into(mm, offset, *values) | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |       if header_id == ZIP64_EXTRA_HEADER: | 
					
						
							|  |  |  |         assert header_length == 16 | 
					
						
							|  |  |  |         values = list(zip64_extra_struct.unpack_from(mm, offset)) | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |         header_id, header_length, _, compressed_size = values | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       offset += extra_header_struct.size + header_length | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |     return compressed_size | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   FILE_HEADER_SIGNATURE = 0x04034b50 | 
					
						
							|  |  |  |   CENDIR_HEADER_SIGNATURE = 0x02014b50 | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |   archive_size = os.fstat(zip_.fileno()).st_size | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |   signature_struct = Struct("<L") | 
					
						
							|  |  |  |   local_file_header_struct = Struct("<LHHHHHLLLHH") | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |   # 0. L signature | 
					
						
							|  |  |  |   # 1. H version_needed | 
					
						
							|  |  |  |   # 2. H gp_bits | 
					
						
							|  |  |  |   # 3. H compression_method | 
					
						
							|  |  |  |   # 4. H last_mod_time | 
					
						
							|  |  |  |   # 5. H last_mod_date | 
					
						
							|  |  |  |   # 6. L crc32 | 
					
						
							|  |  |  |   # 7. L compressed_size | 
					
						
							|  |  |  |   # 8. L uncompressed_size | 
					
						
							|  |  |  |   # 9. H name_length | 
					
						
							|  |  |  |   # 10. H extra_field_length | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |   central_directory_header_struct = Struct("<LHHHHHHLLLHHHHHLL") | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |   # 0. L signature | 
					
						
							|  |  |  |   # 1. H version_made_by | 
					
						
							|  |  |  |   # 2. H version_needed | 
					
						
							|  |  |  |   # 3. H gp_bits | 
					
						
							|  |  |  |   # 4. H compression_method | 
					
						
							|  |  |  |   # 5. H last_mod_time | 
					
						
							|  |  |  |   # 6. H last_mod_date | 
					
						
							|  |  |  |   # 7. L crc32 | 
					
						
							|  |  |  |   # 8. L compressed_size | 
					
						
							|  |  |  |   # 9. L uncompressed_size | 
					
						
							|  |  |  |   # 10. H file_name_length | 
					
						
							|  |  |  |   # 11. H extra_field_length | 
					
						
							|  |  |  |   # 12. H file_comment_length | 
					
						
							|  |  |  |   # 13. H disk_number_start | 
					
						
							|  |  |  |   # 14. H internal_attr | 
					
						
							|  |  |  |   # 15. L external_attr | 
					
						
							|  |  |  |   # 16. L rel_offset_local_header | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |   offset = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mm = mmap.mmap(zip_.fileno(), 0) | 
					
						
							|  |  |  |   while offset < archive_size: | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     if signature_struct.unpack_from(mm, offset) != (FILE_HEADER_SIGNATURE,): | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |       break | 
					
						
							|  |  |  |     values = list(local_file_header_struct.unpack_from(mm, offset)) | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |     compressed_size, _, name_length, extra_field_length = values[7:11] | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     # reset last_mod_time | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |     values[4] = 0 | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     # reset last_mod_date | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |     values[5] = 0x21 | 
					
						
							|  |  |  |     local_file_header_struct.pack_into(mm, offset, *values) | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |     offset += local_file_header_struct.size + name_length | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     if extra_field_length != 0: | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |       compressed_size = purify_extra_data(mm, offset, extra_field_length, | 
					
						
							|  |  |  |                                           compressed_size) | 
					
						
							| 
									
										
										
										
											2020-04-09 19:39:46 +02:00
										 |  |  |     offset += compressed_size + extra_field_length | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   while offset < archive_size: | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     if signature_struct.unpack_from(mm, offset) != (CENDIR_HEADER_SIGNATURE,): | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |       break | 
					
						
							|  |  |  |     values = list(central_directory_header_struct.unpack_from(mm, offset)) | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |     file_name_length, extra_field_length, file_comment_length = values[10:13] | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     # reset last_mod_time | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |     values[5] = 0 | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     # reset last_mod_date | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |     values[6] = 0x21 | 
					
						
							|  |  |  |     central_directory_header_struct.pack_into(mm, offset, *values) | 
					
						
							| 
									
										
										
										
											2020-10-19 04:55:27 -07:00
										 |  |  |     offset += central_directory_header_struct.size | 
					
						
							|  |  |  |     offset += file_name_length + extra_field_length + file_comment_length | 
					
						
							| 
									
										
										
										
											2020-04-01 16:14:41 +02:00
										 |  |  |     if extra_field_length != 0: | 
					
						
							|  |  |  |       purify_extra_data(mm, offset - extra_field_length, extra_field_length) | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if offset == 0: | 
					
						
							|  |  |  |     raise NonZipFileError(zip_.name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  | def upload_electron(release, file_path, args): | 
					
						
							| 
									
										
										
										
											2018-06-13 16:11:26 -04:00
										 |  |  |   filename = os.path.basename(file_path) | 
					
						
							| 
									
										
										
										
											2017-11-02 16:06:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 12:22:04 +00:00
										 |  |  |   # Strip zip non determinism before upload, in-place operation | 
					
						
							|  |  |  |   try: | 
					
						
							|  |  |  |     zero_zip_date_time(file_path) | 
					
						
							|  |  |  |   except NonZipFileError: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 06:34:17 -07:00
										 |  |  |   # if upload_to_storage is set, skip github upload. | 
					
						
							|  |  |  |   # todo (vertedinde): migrate this variable to upload_to_storage | 
					
						
							|  |  |  |   if args.upload_to_storage: | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |     key_prefix = f'release-builds/{args.version}_{args.upload_timestamp}' | 
					
						
							| 
									
										
										
										
											2022-04-04 02:32:57 -07:00
										 |  |  |     store_artifact(os.path.dirname(file_path), key_prefix, [file_path]) | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  |     upload_sha256_checksum(args.version, file_path, key_prefix) | 
					
						
							| 
									
										
										
										
											2017-11-02 16:06:28 +08:00
										 |  |  |     return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 15:31:55 +08:00
										 |  |  |   # Upload the file. | 
					
						
							| 
									
										
										
										
											2018-08-16 08:57:12 -07:00
										 |  |  |   upload_io_to_github(release, filename, file_path, args.version) | 
					
						
							| 
									
										
										
										
											2016-07-24 19:19:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-01 21:03:55 +09:00
										 |  |  |   # Upload the checksum file. | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  |   upload_sha256_checksum(args.version, file_path) | 
					
						
							| 
									
										
										
										
											2016-08-01 21:03:55 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-24 19:19:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 08:57:12 -07:00
										 |  |  | def upload_io_to_github(release, filename, filepath, version): | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |   print(f'Uploading {filename} to GitHub') | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |   script_path = os.path.join( | 
					
						
							| 
									
										
										
										
											2020-11-09 13:57:53 -08:00
										 |  |  |     ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-to-github.ts') | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |   with subprocess.Popen([TS_NODE, script_path, filepath, | 
					
						
							|  |  |  |                          filename, str(release['id']), version], | 
					
						
							|  |  |  |                         stdout=subprocess.PIPE,  | 
					
						
							|  |  |  |                         stderr=subprocess.STDOUT) as upload_process: | 
					
						
							|  |  |  |     if is_verbose_mode(): | 
					
						
							|  |  |  |       for c in iter(lambda: upload_process.stdout.read(1), b""): | 
					
						
							|  |  |  |         sys.stdout.buffer.write(c) | 
					
						
							|  |  |  |         sys.stdout.flush() | 
					
						
							| 
									
										
										
										
											2013-09-26 20:32:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 16:06:28 +08:00
										 |  |  | def upload_sha256_checksum(version, file_path, key_prefix=None): | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |   checksum_path = f'{file_path}.sha256sum' | 
					
						
							| 
									
										
										
										
											2017-11-02 16:06:28 +08:00
										 |  |  |   if key_prefix is None: | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |     key_prefix = f'checksums-scratchpad/{version}' | 
					
						
							| 
									
										
										
										
											2016-08-01 21:03:55 +09:00
										 |  |  |   sha256 = hashlib.sha256() | 
					
						
							|  |  |  |   with open(file_path, 'rb') as f: | 
					
						
							|  |  |  |     sha256.update(f.read()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   filename = os.path.basename(file_path) | 
					
						
							| 
									
										
										
										
											2024-03-21 08:48:23 -05:00
										 |  |  |   with open(checksum_path, 'w', encoding='utf-8') as checksum: | 
					
						
							|  |  |  |     checksum.write(f'{sha256.hexdigest()} *{filename}') | 
					
						
							| 
									
										
										
										
											2022-04-04 02:32:57 -07:00
										 |  |  |   store_artifact(os.path.dirname(checksum_path), key_prefix, [checksum_path]) | 
					
						
							| 
									
										
										
										
											2016-08-01 21:03:55 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  | def get_release(version): | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |   script_path = os.path.join( | 
					
						
							| 
									
										
										
										
											2024-10-01 03:04:22 -07:00
										 |  |  |     ELECTRON_DIR, 'script', 'release', 'find-github-release.ts') | 
					
						
							| 
									
										
										
										
											2023-02-16 15:20:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Strip warnings from stdout to ensure the only output is the desired object | 
					
						
							|  |  |  |   release_env = os.environ.copy() | 
					
						
							|  |  |  |   release_env['NODE_NO_WARNINGS'] = '1' | 
					
						
							| 
									
										
										
										
											2024-10-01 03:04:22 -07:00
										 |  |  |   release_info = execute([TS_NODE, script_path, version], release_env) | 
					
						
							| 
									
										
										
										
											2024-10-29 21:41:19 +01:00
										 |  |  |   verbose_mode_print(f'Release info for version: {version}:\n') | 
					
						
							|  |  |  |   verbose_mode_print(release_info) | 
					
						
							| 
									
										
										
										
											2018-07-09 18:46:31 -04:00
										 |  |  |   release = json.loads(release_info) | 
					
						
							|  |  |  |   return release | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-24 17:56:51 +08:00
										 |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |   sys.exit(main()) |