2013-06-24 09:56:51 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-08-31 02:48:47 +00:00
|
|
|
import argparse
|
2013-06-24 09:56:51 +00:00
|
|
|
import errno
|
2016-08-01 12:03:55 +00:00
|
|
|
import hashlib
|
2013-06-24 09:56:51 +00:00
|
|
|
import os
|
2016-09-13 17:06:09 +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
|
2016-05-26 01:06:25 +00:00
|
|
|
from lib.util import electron_gyp, execute, get_electron_version, \
|
2016-08-01 12:03:55 +00:00
|
|
|
parse_version, scoped_cwd, s3put
|
2013-09-26 11:49:09 +00:00
|
|
|
from lib.github import GitHub
|
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
|
|
|
|
2016-05-25 16:10:46 +00:00
|
|
|
PROJECT_NAME = electron_gyp()['project_name%']
|
|
|
|
PRODUCT_NAME = electron_gyp()['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__)))
|
2015-04-03 03:59:14 +00:00
|
|
|
OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R')
|
2013-08-21 03:57:35 +00:00
|
|
|
DIST_DIR = os.path.join(SOURCE_ROOT, 'dist')
|
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()
|
|
|
|
|
2015-07-03 09:28:36 +00:00
|
|
|
if not args.publish_release:
|
|
|
|
if not dist_newer_than_head():
|
2016-08-01 02:00:19 +00:00
|
|
|
run_python_script('create-dist.py')
|
2015-07-03 09:28:36 +00:00
|
|
|
|
2016-05-24 17:27:46 +00:00
|
|
|
build_version = get_electron_build_version()
|
|
|
|
if not ELECTRON_VERSION.startswith(build_version):
|
2015-07-03 09:28:36 +00:00
|
|
|
error = 'Tag name ({0}) should match build version ({1})\n'.format(
|
2016-05-24 17:27:46 +00:00
|
|
|
ELECTRON_VERSION, build_version)
|
2015-07-03 09:28:36 +00:00
|
|
|
sys.stderr.write(error)
|
|
|
|
sys.stderr.flush()
|
|
|
|
return 1
|
2013-10-03 03:48:13 +00:00
|
|
|
|
2013-09-26 11:49:09 +00:00
|
|
|
github = GitHub(auth_token())
|
2016-05-24 17:27:46 +00:00
|
|
|
releases = github.repos(ELECTRON_REPO).releases.get()
|
2015-07-03 05:43:20 +00:00
|
|
|
tag_exists = False
|
|
|
|
for release in releases:
|
2015-07-03 09:44:36 +00:00
|
|
|
if not release['draft'] and release['tag_name'] == args.version:
|
2015-07-03 05:43:20 +00:00
|
|
|
tag_exists = True
|
|
|
|
break
|
|
|
|
|
2015-07-03 13:21:19 +00:00
|
|
|
release = create_or_get_release_draft(github, releases, args.version,
|
|
|
|
tag_exists)
|
2015-04-11 16:01:10 +00:00
|
|
|
|
|
|
|
if args.publish_release:
|
2016-08-01 02:00:19 +00:00
|
|
|
# Upload the Node SHASUMS*.txt.
|
|
|
|
run_python_script('upload-node-checksums.py', '-v', ELECTRON_VERSION)
|
2015-04-11 16:01:10 +00:00
|
|
|
|
2015-04-12 03:36:55 +00:00
|
|
|
# Upload the index.json.
|
2016-08-01 02:00:19 +00:00
|
|
|
run_python_script('upload-index-json.py')
|
|
|
|
|
|
|
|
# Create and upload the Electron SHASUMS*.txt
|
|
|
|
release_electron_checksums(github, release)
|
2015-04-12 03:36:55 +00:00
|
|
|
|
2015-04-11 16:01:10 +00:00
|
|
|
# Press the publish button.
|
2015-07-03 07:26:54 +00:00
|
|
|
publish_release(github, release['id'])
|
2015-04-11 16:01:10 +00:00
|
|
|
|
2017-08-01 20:08:30 +00:00
|
|
|
# TODO: run publish-to-npm script here
|
|
|
|
|
2015-04-11 16:01:10 +00:00
|
|
|
# Do not upload other files when passed "-p".
|
|
|
|
return
|
|
|
|
|
2016-05-25 16:10:46 +00:00
|
|
|
# Upload Electron with GitHub Releases API.
|
2016-05-24 17:27:46 +00:00
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, DIST_NAME))
|
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, SYMBOLS_NAME))
|
2015-11-19 07:10:33 +00:00
|
|
|
if PLATFORM == 'darwin':
|
2016-09-12 17:47:36 +00:00
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR,
|
|
|
|
'electron-api.json'))
|
2017-04-01 04:01:55 +00:00
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, 'electron.d.ts'))
|
2016-05-24 17:27:46 +00:00
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, DSYM_NAME))
|
2016-06-24 12:26:05 +00:00
|
|
|
elif PLATFORM == 'win32':
|
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, PDB_NAME))
|
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)
|
2016-05-24 17:27:46 +00:00
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, ffmpeg))
|
2016-02-19 02:26:18 +00:00
|
|
|
|
2015-05-06 01:17:40 +00:00
|
|
|
# Upload chromedriver and mksnapshot for minor version update.
|
2015-07-08 04:32:47 +00:00
|
|
|
if parse_version(args.version)[2] == '0':
|
2017-02-14 18:11:17 +00:00
|
|
|
chromedriver = get_zip_name('chromedriver', ELECTRON_VERSION)
|
2016-05-24 17:27:46 +00:00
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, chromedriver))
|
2016-08-26 00:50:12 +00:00
|
|
|
mksnapshot = get_zip_name('mksnapshot', ELECTRON_VERSION)
|
2016-05-24 17:27:46 +00:00
|
|
|
upload_electron(github, release, os.path.join(DIST_DIR, mksnapshot))
|
2013-09-26 13:20:38 +00:00
|
|
|
|
2015-07-03 05:43:20 +00:00
|
|
|
if PLATFORM == 'win32' and not tag_exists:
|
2016-04-30 12:43:33 +00:00
|
|
|
# Upload PDBs to Windows symbol server.
|
2016-08-01 02:00:19 +00:00
|
|
|
run_python_script('upload-windows-pdb.py')
|
2016-04-30 12:43:33 +00:00
|
|
|
|
2015-04-11 15:40:10 +00:00
|
|
|
# Upload node headers.
|
2017-05-02 17:14:49 +00:00
|
|
|
run_python_script('create-node-headers.py', '-v', args.version)
|
2016-08-01 02:00:19 +00:00
|
|
|
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)
|
2014-03-01 01:36:48 +00:00
|
|
|
parser.add_argument('-p', '--publish-release',
|
|
|
|
help='Publish the release',
|
|
|
|
action='store_true')
|
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():
|
2015-07-03 09:01:16 +00:00
|
|
|
if get_target_arch() == '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
|
2015-04-11 09:30:52 +00:00
|
|
|
if PLATFORM == 'darwin':
|
2016-05-24 17:27:46 +00:00
|
|
|
electron = os.path.join(SOURCE_ROOT, 'out', 'R',
|
2015-04-17 07:53:46 +00:00
|
|
|
'{0}.app'.format(PRODUCT_NAME), 'Contents',
|
|
|
|
'MacOS', PRODUCT_NAME)
|
2015-04-11 09:30:52 +00:00
|
|
|
elif PLATFORM == 'win32':
|
2016-05-24 17:27:46 +00:00
|
|
|
electron = os.path.join(SOURCE_ROOT, 'out', 'R',
|
2015-04-17 07:53:46 +00:00
|
|
|
'{0}.exe'.format(PROJECT_NAME))
|
2014-02-24 05:41:16 +00:00
|
|
|
else:
|
2016-05-24 17:27:46 +00:00
|
|
|
electron = os.path.join(SOURCE_ROOT, 'out', 'R', PROJECT_NAME)
|
2013-10-03 03:48:13 +00:00
|
|
|
|
2016-05-24 17:27:46 +00:00
|
|
|
return subprocess.check_output([electron, '--version']).strip()
|
2013-10-03 03:48:13 +00:00
|
|
|
|
|
|
|
|
2013-06-29 03:36:02 +00:00
|
|
|
def dist_newer_than_head():
|
|
|
|
with scoped_cwd(SOURCE_ROOT):
|
|
|
|
try:
|
|
|
|
head_time = subprocess.check_output(['git', 'log', '--pretty=format:%at',
|
|
|
|
'-n', '1']).strip()
|
2013-08-31 02:35:01 +00:00
|
|
|
dist_time = os.path.getmtime(os.path.join(DIST_DIR, DIST_NAME))
|
2013-06-29 03:36:02 +00:00
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
return False
|
|
|
|
|
|
|
|
return dist_time > int(head_time)
|
|
|
|
|
|
|
|
|
2013-09-27 07:55:46 +00:00
|
|
|
def get_text_with_editor(name):
|
|
|
|
editor = os.environ.get('EDITOR', 'nano')
|
|
|
|
initial_message = '\n# Please enter the body of your release note for %s.' \
|
|
|
|
% name
|
2013-09-27 01:10:22 +00:00
|
|
|
|
|
|
|
t = tempfile.NamedTemporaryFile(suffix='.tmp', delete=False)
|
|
|
|
t.write(initial_message)
|
|
|
|
t.close()
|
|
|
|
subprocess.call([editor, t.name])
|
|
|
|
|
|
|
|
text = ''
|
|
|
|
for line in open(t.name, 'r'):
|
|
|
|
if len(line) == 0 or line[0] != '#':
|
|
|
|
text += line
|
|
|
|
|
|
|
|
os.unlink(t.name)
|
|
|
|
return text
|
|
|
|
|
2015-07-03 13:21:19 +00:00
|
|
|
def create_or_get_release_draft(github, releases, tag, tag_exists):
|
2015-07-03 05:43:20 +00:00
|
|
|
# Search for existing draft.
|
2013-09-26 11:49:09 +00:00
|
|
|
for release in releases:
|
2015-07-03 05:43:20 +00:00
|
|
|
if release['draft']:
|
2015-07-03 07:26:54 +00:00
|
|
|
return release
|
2013-09-26 11:49:09 +00:00
|
|
|
|
2015-07-03 05:43:20 +00:00
|
|
|
if tag_exists:
|
2015-07-03 13:21:19 +00:00
|
|
|
tag = 'do-not-publish-me'
|
|
|
|
return create_release_draft(github, tag)
|
2013-09-26 11:49:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_release_draft(github, tag):
|
2017-05-26 16:10:26 +00:00
|
|
|
name = '{0} {1} beta'.format(PROJECT_NAME, tag)
|
2015-07-03 05:43:20 +00:00
|
|
|
if os.environ.has_key('CI'):
|
|
|
|
body = '(placeholder)'
|
|
|
|
else:
|
|
|
|
body = get_text_with_editor(name)
|
2013-09-27 07:55:46 +00:00
|
|
|
if body == '':
|
|
|
|
sys.stderr.write('Quit due to empty release note.\n')
|
|
|
|
sys.exit(0)
|
2013-09-26 11:49:09 +00:00
|
|
|
|
2017-05-26 16:10:26 +00:00
|
|
|
data = dict(tag_name=tag, name=name, body=body, draft=True, prerelease=True)
|
2016-05-24 17:27:46 +00:00
|
|
|
r = github.repos(ELECTRON_REPO).releases.post(data=data)
|
2015-07-03 07:26:54 +00:00
|
|
|
return r
|
2013-09-26 11:49:09 +00:00
|
|
|
|
|
|
|
|
2016-08-01 02:00:19 +00:00
|
|
|
def release_electron_checksums(github, release):
|
2016-08-01 13:08:29 +00:00
|
|
|
checksums = run_python_script('merge-electron-checksums.py',
|
|
|
|
'-v', ELECTRON_VERSION)
|
|
|
|
upload_io_to_github(github, release, 'SHASUMS256.txt',
|
|
|
|
StringIO(checksums.decode('utf-8')), 'text/plain')
|
2016-08-01 02:00:19 +00:00
|
|
|
|
|
|
|
|
2016-05-24 17:27:46 +00:00
|
|
|
def upload_electron(github, release, file_path):
|
2016-08-01 02:00:19 +00:00
|
|
|
# Delete the original file before uploading in CI.
|
2016-07-25 02:19:23 +00:00
|
|
|
filename = os.path.basename(file_path)
|
2015-07-03 07:26:54 +00:00
|
|
|
if os.environ.has_key('CI'):
|
|
|
|
try:
|
|
|
|
for asset in release['assets']:
|
2016-08-01 02:00:19 +00:00
|
|
|
if asset['name'] == filename:
|
2016-05-24 17:27:46 +00:00
|
|
|
github.repos(ELECTRON_REPO).releases.assets(asset['id']).delete()
|
2015-07-03 07:26:54 +00:00
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
2015-07-03 07:31:55 +00:00
|
|
|
# Upload the file.
|
2016-08-01 02:00:19 +00:00
|
|
|
with open(file_path, 'rb') as f:
|
2016-08-01 12:59:25 +00:00
|
|
|
upload_io_to_github(github, release, filename, f, 'application/zip')
|
2016-07-25 02:19:23 +00:00
|
|
|
|
2016-08-01 12:03:55 +00:00
|
|
|
# Upload the checksum file.
|
2016-08-01 12:59:25 +00:00
|
|
|
upload_sha256_checksum(release['tag_name'], file_path)
|
2016-08-01 12:03:55 +00:00
|
|
|
|
2016-09-13 17:06:09 +00:00
|
|
|
# Upload ARM assets without the v7l suffix for backwards compatibility
|
|
|
|
# TODO Remove for 2.0
|
|
|
|
if 'armv7l' in filename:
|
|
|
|
arm_filename = filename.replace('armv7l', 'arm')
|
|
|
|
arm_file_path = os.path.join(os.path.dirname(file_path), arm_filename)
|
|
|
|
shutil.copy2(file_path, arm_file_path)
|
|
|
|
upload_electron(github, release, arm_file_path)
|
|
|
|
|
2016-07-25 02:19:23 +00:00
|
|
|
|
2016-08-01 02:00:19 +00:00
|
|
|
def upload_io_to_github(github, release, name, io, content_type):
|
|
|
|
params = {'name': name}
|
2016-07-25 02:19:23 +00:00
|
|
|
headers = {'Content-Type': content_type}
|
2016-08-01 02:00:19 +00:00
|
|
|
github.repos(ELECTRON_REPO).releases(release['id']).assets.post(
|
|
|
|
params=params, headers=headers, data=io, verify=False)
|
2013-09-26 12:32:11 +00:00
|
|
|
|
|
|
|
|
2016-08-01 12:03:55 +00:00
|
|
|
def upload_sha256_checksum(version, file_path):
|
|
|
|
bucket, access_key, secret_key = s3_config()
|
|
|
|
checksum_path = '{}.sha256sum'.format(file_path)
|
|
|
|
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),
|
|
|
|
'atom-shell/tmp/{0}'.format(version), [checksum_path])
|
|
|
|
|
|
|
|
|
2013-09-26 14:02:09 +00:00
|
|
|
def publish_release(github, release_id):
|
|
|
|
data = dict(draft=False)
|
2016-05-24 17:27:46 +00:00
|
|
|
github.repos(ELECTRON_REPO).releases(release_id).patch(data=data)
|
2013-09-26 14:02:09 +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
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
sys.exit(main())
|