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
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import subprocess
|
2013-06-29 03:36:02 +00:00
|
|
|
import sys
|
2013-06-24 09:56:51 +00:00
|
|
|
import tempfile
|
|
|
|
|
2014-09-01 14:54:20 +00:00
|
|
|
from lib.config import DIST_ARCH, TARGET_PLATFORM
|
2014-09-20 14:39:52 +00:00
|
|
|
from lib.util import execute, get_atom_shell_version, parse_version, \
|
2015-01-23 01:18:31 +00:00
|
|
|
get_chromedriver_version, scoped_cwd
|
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
|
|
|
|
2013-09-26 11:49:09 +00:00
|
|
|
ATOM_SHELL_REPO = 'atom/atom-shell'
|
2014-05-07 06:34:53 +00:00
|
|
|
ATOM_SHELL_VERSION = get_atom_shell_version()
|
2014-09-20 15:09:49 +00:00
|
|
|
CHROMEDRIVER_VERSION = get_chromedriver_version()
|
2013-08-31 02:48:47 +00:00
|
|
|
|
2013-06-24 09:56:51 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
2013-09-02 05:27:26 +00:00
|
|
|
OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'Release')
|
2013-08-21 03:57:35 +00:00
|
|
|
DIST_DIR = os.path.join(SOURCE_ROOT, 'dist')
|
2014-06-04 15:24:38 +00:00
|
|
|
DIST_NAME = 'atom-shell-{0}-{1}-{2}.zip'.format(ATOM_SHELL_VERSION,
|
|
|
|
TARGET_PLATFORM,
|
|
|
|
DIST_ARCH)
|
|
|
|
SYMBOLS_NAME = 'atom-shell-{0}-{1}-{2}-symbols.zip'.format(ATOM_SHELL_VERSION,
|
|
|
|
TARGET_PLATFORM,
|
|
|
|
DIST_ARCH)
|
2014-09-20 15:09:49 +00:00
|
|
|
CHROMEDRIVER_NAME = 'chromedriver-{0}-{1}-{2}.zip'.format(CHROMEDRIVER_VERSION,
|
2014-09-12 14:10:06 +00:00
|
|
|
TARGET_PLATFORM,
|
|
|
|
DIST_ARCH)
|
2013-06-24 09:56:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2013-08-31 02:48:47 +00:00
|
|
|
args = parse_args()
|
|
|
|
|
2013-08-31 02:36:13 +00:00
|
|
|
if not dist_newer_than_head():
|
|
|
|
create_dist = os.path.join(SOURCE_ROOT, 'script', 'create-dist.py')
|
2014-02-26 14:08:01 +00:00
|
|
|
execute([sys.executable, create_dist])
|
2013-08-31 02:48:47 +00:00
|
|
|
|
2013-10-03 03:48:13 +00:00
|
|
|
build_version = get_atom_shell_build_version()
|
2014-05-07 06:34:53 +00:00
|
|
|
if not ATOM_SHELL_VERSION.startswith(build_version):
|
2013-10-03 03:48:13 +00:00
|
|
|
error = 'Tag name ({0}) should match build version ({1})\n'.format(
|
2014-05-07 06:34:53 +00:00
|
|
|
ATOM_SHELL_VERSION, build_version)
|
2013-10-03 03:48:13 +00:00
|
|
|
sys.stderr.write(error)
|
|
|
|
sys.stderr.flush()
|
|
|
|
return 1
|
|
|
|
|
2013-09-26 13:20:38 +00:00
|
|
|
# Upload atom-shell with GitHub Releases API.
|
2013-09-26 11:49:09 +00:00
|
|
|
github = GitHub(auth_token())
|
2013-09-26 12:32:11 +00:00
|
|
|
release_id = create_or_get_release_draft(github, args.version)
|
2013-09-26 13:20:38 +00:00
|
|
|
upload_atom_shell(github, release_id, os.path.join(DIST_DIR, DIST_NAME))
|
2013-11-18 10:02:38 +00:00
|
|
|
upload_atom_shell(github, release_id, os.path.join(DIST_DIR, SYMBOLS_NAME))
|
2014-09-20 14:39:52 +00:00
|
|
|
|
|
|
|
# Upload chromedriver for minor version update.
|
|
|
|
if parse_version(args.version)[2] == '0':
|
|
|
|
upload_atom_shell(github, release_id,
|
|
|
|
os.path.join(DIST_DIR, CHROMEDRIVER_NAME))
|
2013-09-26 13:20:38 +00:00
|
|
|
|
2014-07-24 15:34:50 +00:00
|
|
|
if args.publish_release:
|
2014-11-07 14:52:00 +00:00
|
|
|
# Upload PDBs to Windows symbol server.
|
|
|
|
if TARGET_PLATFORM == 'win32':
|
|
|
|
execute([sys.executable,
|
|
|
|
os.path.join(SOURCE_ROOT, 'script', 'upload-windows-pdb.py')])
|
|
|
|
|
2014-11-07 13:45:40 +00:00
|
|
|
# Press the publish button.
|
|
|
|
publish_release(github, release_id)
|
|
|
|
|
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',
|
2014-05-07 06:34:53 +00:00
|
|
|
default=ATOM_SHELL_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
|
|
|
|
|
|
|
|
2013-10-03 03:48:13 +00:00
|
|
|
def get_atom_shell_build_version():
|
2014-02-25 11:05:38 +00:00
|
|
|
if TARGET_PLATFORM == 'darwin':
|
2013-10-10 06:39:54 +00:00
|
|
|
atom_shell = os.path.join(SOURCE_ROOT, 'out', 'Release', 'Atom.app',
|
2013-10-03 03:48:13 +00:00
|
|
|
'Contents', 'MacOS', 'Atom')
|
2014-02-25 11:05:38 +00:00
|
|
|
elif TARGET_PLATFORM == 'win32':
|
2013-10-10 06:39:54 +00:00
|
|
|
atom_shell = os.path.join(SOURCE_ROOT, 'out', 'Release', 'atom.exe')
|
2014-02-24 05:41:16 +00:00
|
|
|
else:
|
|
|
|
atom_shell = os.path.join(SOURCE_ROOT, 'out', 'Release', 'atom')
|
2013-10-03 03:48:13 +00:00
|
|
|
|
|
|
|
return subprocess.check_output([atom_shell, '--version']).strip()
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-09-26 11:49:09 +00:00
|
|
|
def create_or_get_release_draft(github, tag):
|
2013-09-26 11:54:28 +00:00
|
|
|
name = 'atom-shell %s' % tag
|
2013-09-26 11:49:09 +00:00
|
|
|
releases = github.repos(ATOM_SHELL_REPO).releases.get()
|
|
|
|
for release in releases:
|
2013-09-26 11:54:28 +00:00
|
|
|
# The untagged commit doesn't have a matching tag_name, so also check name.
|
|
|
|
if release['tag_name'] == tag or release['name'] == name:
|
2013-09-26 11:49:09 +00:00
|
|
|
return release['id']
|
|
|
|
|
|
|
|
return create_release_draft(github, tag)
|
|
|
|
|
|
|
|
|
|
|
|
def create_release_draft(github, tag):
|
|
|
|
name = 'atom-shell %s' % tag
|
2013-09-27 07:55:46 +00:00
|
|
|
body = get_text_with_editor(name)
|
|
|
|
if body == '':
|
|
|
|
sys.stderr.write('Quit due to empty release note.\n')
|
|
|
|
sys.exit(0)
|
2013-09-26 11:49:09 +00:00
|
|
|
|
2013-09-29 07:31:20 +00:00
|
|
|
data = dict(tag_name=tag, name=name, body=body, draft=True)
|
2013-09-26 11:49:09 +00:00
|
|
|
r = github.repos(ATOM_SHELL_REPO).releases.post(data=data)
|
|
|
|
return r['id']
|
|
|
|
|
|
|
|
|
2013-09-26 13:20:38 +00:00
|
|
|
def upload_atom_shell(github, release_id, file_path):
|
2013-09-26 12:32:11 +00:00
|
|
|
params = {'name': os.path.basename(file_path)}
|
|
|
|
headers = {'Content-Type': 'application/zip'}
|
2013-10-10 10:05:01 +00:00
|
|
|
with open(file_path, 'rb') as f:
|
|
|
|
github.repos(ATOM_SHELL_REPO).releases(release_id).assets.post(
|
2013-10-15 01:04:05 +00:00
|
|
|
params=params, headers=headers, data=f, verify=False)
|
2013-09-26 12:32:11 +00:00
|
|
|
|
|
|
|
|
2013-09-26 14:02:09 +00:00
|
|
|
def publish_release(github, release_id):
|
|
|
|
data = dict(draft=False)
|
|
|
|
github.repos(ATOM_SHELL_REPO).releases(release_id).patch(data=data)
|
|
|
|
|
|
|
|
|
2013-09-26 11:49:09 +00:00
|
|
|
def auth_token():
|
|
|
|
token = os.environ.get('ATOM_SHELL_GITHUB_TOKEN')
|
|
|
|
message = ('Error: Please set the $ATOM_SHELL_GITHUB_TOKEN '
|
|
|
|
'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())
|