2013-06-24 09:56:51 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-08-31 02:48:47 +00:00
|
|
|
import argparse
|
2018-05-22 17:50:44 +00:00
|
|
|
import datetime
|
2013-06-24 09:56:51 +00:00
|
|
|
import errno
|
2016-08-01 12:03:55 +00:00
|
|
|
import hashlib
|
2018-07-09 22:46:31 +00:00
|
|
|
import json
|
2013-06-24 09:56:51 +00:00
|
|
|
import os
|
2018-09-27 20:14:13 +00:00
|
|
|
import shutil
|
2013-06-24 09:56:51 +00:00
|
|
|
import subprocess
|
2013-06-29 03:36:02 +00:00
|
|
|
import sys
|
2013-06-24 09:56:51 +00:00
|
|
|
import tempfile
|
|
|
|
|
2016-08-01 12:03:55 +00:00
|
|
|
from io import StringIO
|
2017-02-14 18:11:17 +00:00
|
|
|
from lib.config import PLATFORM, get_target_arch, get_env_var, s3_config, \
|
|
|
|
get_zip_name
|
2018-09-27 18:53:08 +00:00
|
|
|
from lib.util import get_electron_branding, execute, get_electron_version, \
|
2018-09-27 20:14:13 +00:00
|
|
|
parse_version, scoped_cwd, s3put, get_electron_exec, \
|
2018-09-27 21:26:49 +00:00
|
|
|
get_out_dir, GN_SRC_DIR
|
2013-06-29 03:36:02 +00:00
|
|
|
|
2013-06-24 09:56:51 +00:00
|
|
|
|
2016-05-24 17:27:46 +00:00
|
|
|
ELECTRON_REPO = 'electron/electron'
|
|
|
|
ELECTRON_VERSION = get_electron_version()
|
2013-08-31 02:48:47 +00:00
|
|
|
|
2018-09-27 18:53:08 +00:00
|
|
|
PROJECT_NAME = get_electron_branding()['project_name']
|
|
|
|
PRODUCT_NAME = get_electron_branding()['product_name']
|
2015-04-17 04:13:20 +00:00
|
|
|
|
2013-06-24 09:56:51 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
2018-09-27 20:14:13 +00:00
|
|
|
OUT_DIR = get_out_dir()
|
2016-08-26 00:50:12 +00: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')
|
|
|
|
PDB_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'pdb')
|
2013-06-24 09:56:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2013-08-31 02:48:47 +00:00
|
|
|
args = parse_args()
|
2018-05-22 17:50:44 +00:00
|
|
|
if args.upload_to_s3:
|
|
|
|
utcnow = datetime.datetime.utcnow()
|
2018-07-19 21:12:12 +00:00
|
|
|
args.upload_timestamp = utcnow.strftime('%Y%m%d')
|
2013-08-31 02:48:47 +00:00
|
|
|
|
2017-10-23 15:02:50 +00:00
|
|
|
build_version = get_electron_build_version()
|
|
|
|
if not ELECTRON_VERSION.startswith(build_version):
|
|
|
|
error = 'Tag name ({0}) should match build version ({1})\n'.format(
|
|
|
|
ELECTRON_VERSION, build_version)
|
|
|
|
sys.stderr.write(error)
|
|
|
|
sys.stderr.flush()
|
|
|
|
return 1
|
2013-10-03 03:48:13 +00:00
|
|
|
|
2015-07-03 05:43:20 +00:00
|
|
|
tag_exists = False
|
2018-07-09 22:46:31 +00:00
|
|
|
release = get_release(args.version)
|
|
|
|
if not release['draft']:
|
|
|
|
tag_exists = True
|
2015-07-03 05:43:20 +00:00
|
|
|
|
2017-11-02 08:06:28 +00:00
|
|
|
if not args.upload_to_s3:
|
2018-07-09 22:46:31 +00:00
|
|
|
assert release['exists'], 'Release does not exist; cannot upload to GitHub!'
|
2017-11-02 08:06:28 +00:00
|
|
|
assert tag_exists == args.overwrite, \
|
|
|
|
'You have to pass --overwrite to overwrite a published release'
|
2018-05-14 21:21:51 +00:00
|
|
|
|
2018-07-09 22:46:31 +00:00
|
|
|
# Upload Electron files.
|
2018-09-27 20:14:13 +00: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)
|
2017-11-23 00:19:01 +00:00
|
|
|
if get_target_arch() != 'mips64el':
|
2018-09-27 20:14:13 +00:00
|
|
|
symbols_zip = os.path.join(OUT_DIR, SYMBOLS_NAME)
|
|
|
|
shutil.copy2(os.path.join(OUT_DIR, 'symobls.zip'), symbols_zip)
|
|
|
|
upload_electron(release, symbols_zip, args)
|
2015-11-19 07:10:33 +00:00
|
|
|
if PLATFORM == 'darwin':
|
2018-09-27 20:14:13 +00:00
|
|
|
api_path = os.path.join(OUT_DIR, 'electron-api.json')
|
2018-09-25 01:48:49 +00:00
|
|
|
upload_electron(release, api_path, args)
|
|
|
|
|
2018-09-27 20:14:13 +00:00
|
|
|
ts_defs_path = os.path.join(OUT_DIR, 'electron.d.ts')
|
2018-09-25 01:48:49 +00:00
|
|
|
upload_electron(release, ts_defs_path, args)
|
2018-09-27 20:14:13 +00: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)
|
2016-06-24 12:26:05 +00:00
|
|
|
elif PLATFORM == 'win32':
|
2018-09-27 20:14:13 +00:00
|
|
|
upload_electron(release, os.path.join(OUT_DIR, PDB_NAME), args)
|
2014-09-20 14:39:52 +00:00
|
|
|
|
2016-02-19 02:26:18 +00:00
|
|
|
# Upload free version of ffmpeg.
|
2016-08-26 00:50:12 +00:00
|
|
|
ffmpeg = get_zip_name('ffmpeg', ELECTRON_VERSION)
|
2018-09-27 20:14:13 +00:00
|
|
|
ffmpeg_zip = os.path.join(OUT_DIR, ffmpeg)
|
|
|
|
shutil.copy2(os.path.join(OUT_DIR, 'ffmpeg.zip'), ffmpeg_zip)
|
|
|
|
upload_electron(release, ffmpeg_zip, args)
|
2016-02-19 02:26:18 +00:00
|
|
|
|
2018-04-02 20:54:39 +00:00
|
|
|
chromedriver = get_zip_name('chromedriver', ELECTRON_VERSION)
|
2018-09-27 20:14:13 +00: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 20:54:39 +00:00
|
|
|
|
2018-09-27 21:26:49 +00:00
|
|
|
mksnapshot = get_zip_name('mksnapshot', ELECTRON_VERSION)
|
|
|
|
mksnapshot_zip = os.path.join(OUT_DIR, mksnapshot)
|
2018-04-02 20:54:39 +00:00
|
|
|
if get_target_arch().startswith('arm'):
|
2018-09-27 21:26:49 +00:00
|
|
|
# Upload the native mksnapshot as mksnapshot.zip
|
|
|
|
shutil.copy2(os.path.join(GN_SRC_DIR, 'out', 'native_mksnapshot',
|
|
|
|
'native_mksnapshot.zip'), mksnapshot_zip)
|
|
|
|
upload_electron(release, mksnapshot_zip, args)
|
2018-04-02 20:54:39 +00:00
|
|
|
# Upload the x64 binary for arm/arm64 mksnapshot
|
|
|
|
mksnapshot = get_zip_name('mksnapshot', ELECTRON_VERSION, 'x64')
|
2018-09-27 21:26:49 +00: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 08:06:28 +00:00
|
|
|
|
2018-05-23 19:53:48 +00:00
|
|
|
if not tag_exists and not args.upload_to_s3:
|
|
|
|
# Upload symbols to symbol server.
|
|
|
|
run_python_script('upload-symbols.py')
|
|
|
|
if PLATFORM == 'win32':
|
|
|
|
run_python_script('upload-node-headers.py', '-v', args.version)
|
2015-01-23 02:03:15 +00:00
|
|
|
|
2013-08-31 02:48:47 +00:00
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description='upload distribution file')
|
2013-09-26 11:49:09 +00:00
|
|
|
parser.add_argument('-v', '--version', help='Specify the version',
|
2016-05-24 17:27:46 +00:00
|
|
|
default=ELECTRON_VERSION)
|
2017-09-26 01:43:43 +00:00
|
|
|
parser.add_argument('-o', '--overwrite',
|
|
|
|
help='Overwrite a published release',
|
|
|
|
action='store_true')
|
2014-03-01 01:36:48 +00:00
|
|
|
parser.add_argument('-p', '--publish-release',
|
|
|
|
help='Publish the release',
|
|
|
|
action='store_true')
|
2017-11-02 08:42:09 +00:00
|
|
|
parser.add_argument('-s', '--upload_to_s3',
|
|
|
|
help='Upload assets to s3 bucket',
|
|
|
|
dest='upload_to_s3',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
required=False)
|
2013-08-31 02:48:47 +00:00
|
|
|
return parser.parse_args()
|
2013-06-24 09:56:51 +00:00
|
|
|
|
|
|
|
|
2016-08-01 02:00:19 +00:00
|
|
|
def run_python_script(script, *args):
|
2016-08-01 12:41:55 +00:00
|
|
|
script_path = os.path.join(SOURCE_ROOT, 'script', script)
|
|
|
|
return execute([sys.executable, script_path] + list(args))
|
2016-08-01 02:00:19 +00:00
|
|
|
|
|
|
|
|
2016-05-24 17:27:46 +00:00
|
|
|
def get_electron_build_version():
|
2017-08-22 01:08:27 +00:00
|
|
|
if get_target_arch().startswith('arm') or os.environ.has_key('CI'):
|
2015-07-03 06:30:59 +00:00
|
|
|
# In CI we just build as told.
|
2016-05-24 17:27:46 +00:00
|
|
|
return ELECTRON_VERSION
|
2018-09-27 20:14:13 +00:00
|
|
|
electron = get_electron_exec()
|
2016-05-24 17:27:46 +00:00
|
|
|
return subprocess.check_output([electron, '--version']).strip()
|
2013-10-03 03:48:13 +00:00
|
|
|
|
|
|
|
|
2018-07-09 22:46:31 +00:00
|
|
|
def upload_electron(release, file_path, args):
|
2018-06-13 20:11:26 +00:00
|
|
|
filename = os.path.basename(file_path)
|
2017-11-02 08:06:28 +00:00
|
|
|
|
|
|
|
# if upload_to_s3 is set, skip github upload.
|
2018-05-22 17:50:44 +00:00
|
|
|
if args.upload_to_s3:
|
2017-11-02 08:06:28 +00:00
|
|
|
bucket, access_key, secret_key = s3_config()
|
2018-07-09 22:46:31 +00:00
|
|
|
key_prefix = 'electron-artifacts/{0}_{1}'.format(args.version,
|
2018-05-22 17:50:44 +00:00
|
|
|
args.upload_timestamp)
|
2017-11-02 08:06:28 +00:00
|
|
|
s3put(bucket, access_key, secret_key, os.path.dirname(file_path),
|
|
|
|
key_prefix, [file_path])
|
2018-07-09 22:46:31 +00:00
|
|
|
upload_sha256_checksum(args.version, file_path, key_prefix)
|
2018-06-13 20:11:26 +00:00
|
|
|
s3url = 'https://gh-contractor-zcbenz.s3.amazonaws.com'
|
|
|
|
print '{0} uploaded to {1}/{2}/{0}'.format(filename, s3url, key_prefix)
|
2017-11-02 08:06:28 +00:00
|
|
|
return
|
|
|
|
|
2015-07-03 07:31:55 +00:00
|
|
|
# Upload the file.
|
2018-08-16 15:57:12 +00:00
|
|
|
upload_io_to_github(release, filename, file_path, args.version)
|
2016-07-25 02:19:23 +00:00
|
|
|
|
2016-08-01 12:03:55 +00:00
|
|
|
# Upload the checksum file.
|
2018-07-09 22:46:31 +00:00
|
|
|
upload_sha256_checksum(args.version, file_path)
|
2016-08-01 12:03:55 +00:00
|
|
|
|
2016-07-25 02:19:23 +00:00
|
|
|
|
2018-08-16 15:57:12 +00:00
|
|
|
def upload_io_to_github(release, filename, filepath, version):
|
2017-09-23 21:26:04 +00:00
|
|
|
print 'Uploading %s to Github' % \
|
|
|
|
(filename)
|
|
|
|
script_path = os.path.join(SOURCE_ROOT, 'script', 'upload-to-github.js')
|
2018-08-16 15:57:12 +00:00
|
|
|
execute(['node', script_path, filepath, filename, str(release['id']),
|
|
|
|
version])
|
2013-09-26 12:32:11 +00:00
|
|
|
|
|
|
|
|
2017-11-02 08:06:28 +00:00
|
|
|
def upload_sha256_checksum(version, file_path, key_prefix=None):
|
2016-08-01 12:03:55 +00:00
|
|
|
bucket, access_key, secret_key = s3_config()
|
|
|
|
checksum_path = '{}.sha256sum'.format(file_path)
|
2017-11-02 08:06:28 +00:00
|
|
|
if key_prefix is None:
|
|
|
|
key_prefix = 'atom-shell/tmp/{0}'.format(version)
|
2016-08-01 12:03:55 +00:00
|
|
|
sha256 = hashlib.sha256()
|
|
|
|
with open(file_path, 'rb') as f:
|
|
|
|
sha256.update(f.read())
|
|
|
|
|
|
|
|
filename = os.path.basename(file_path)
|
|
|
|
with open(checksum_path, 'w') as checksum:
|
2016-08-18 15:35:54 +00:00
|
|
|
checksum.write('{} *{}'.format(sha256.hexdigest(), filename))
|
2016-08-01 12:03:55 +00:00
|
|
|
s3put(bucket, access_key, secret_key, os.path.dirname(checksum_path),
|
2017-11-02 08:06:28 +00:00
|
|
|
key_prefix, [checksum_path])
|
2016-08-01 12:03:55 +00:00
|
|
|
|
|
|
|
|
2013-09-26 11:49:09 +00:00
|
|
|
def auth_token():
|
2016-05-25 00:35:30 +00:00
|
|
|
token = get_env_var('GITHUB_TOKEN')
|
2016-05-24 17:27:46 +00:00
|
|
|
message = ('Error: Please set the $ELECTRON_GITHUB_TOKEN '
|
2013-09-26 11:49:09 +00:00
|
|
|
'environment variable, which is your personal token')
|
|
|
|
assert token, message
|
|
|
|
return token
|
2013-06-24 09:56:51 +00:00
|
|
|
|
|
|
|
|
2018-07-09 22:46:31 +00:00
|
|
|
def get_release(version):
|
|
|
|
script_path = os.path.join(SOURCE_ROOT, 'script', 'find-release.js')
|
|
|
|
release_info = execute(['node', script_path, version])
|
|
|
|
release = json.loads(release_info)
|
|
|
|
return release
|
|
|
|
|
2013-06-24 09:56:51 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|