2013-11-07 04:52:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
2017-08-29 22:33:49 +00:00
|
|
|
import argparse
|
2013-11-07 04:52:26 +00:00
|
|
|
|
2018-08-17 17:42:45 +00:00
|
|
|
from lib.util import execute, get_electron_version, parse_version, scoped_cwd, \
|
|
|
|
is_nightly, is_beta, is_stable, get_next_nightly, get_next_beta, \
|
|
|
|
get_next_stable_from_pre, get_next_stable_from_stable, clean_parse_version
|
2013-11-07 04:52:26 +00:00
|
|
|
|
2013-11-07 07:19:37 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
2013-11-07 04:52:26 +00:00
|
|
|
def main():
|
2017-08-29 22:33:49 +00:00
|
|
|
|
2017-08-29 23:55:34 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
2017-10-03 19:35:49 +00:00
|
|
|
description='Bump version numbers. Must specify at least one of the three'
|
|
|
|
+' options:\n'
|
2017-09-06 20:31:58 +00:00
|
|
|
+' --bump=patch to increment patch version, or\n'
|
|
|
|
+' --stable to promote current beta to stable, or\n'
|
|
|
|
+' --version={version} to set version number directly\n'
|
2017-10-03 19:35:49 +00:00
|
|
|
+'Note that you can use both --bump and --stable '
|
|
|
|
+'simultaneously.',
|
2017-09-06 20:31:58 +00:00
|
|
|
formatter_class=argparse.RawTextHelpFormatter
|
2017-08-29 23:55:34 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
2017-10-03 19:35:49 +00:00
|
|
|
'--version',
|
|
|
|
default=None,
|
|
|
|
dest='new_version',
|
2017-08-29 23:55:34 +00:00
|
|
|
help='new version number'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2017-10-03 19:35:49 +00:00
|
|
|
'--bump',
|
|
|
|
action='store',
|
|
|
|
default=None,
|
|
|
|
dest='bump',
|
2018-08-17 17:42:45 +00:00
|
|
|
help='increment [stable | beta | nightly]'
|
2017-08-29 23:55:34 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
2017-10-03 19:35:49 +00:00
|
|
|
'--dry-run',
|
|
|
|
action='store_true',
|
|
|
|
default= False,
|
|
|
|
dest='dry_run',
|
2017-08-29 23:55:34 +00:00
|
|
|
help='just to check that version number is correct'
|
|
|
|
)
|
2017-08-29 22:33:49 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
2018-08-17 17:42:45 +00:00
|
|
|
curr_version = get_electron_version()
|
|
|
|
|
|
|
|
if args.bump not in ['stable', 'beta', 'nightly']:
|
|
|
|
raise Exception('bump must be set to either stable, beta or nightly')
|
|
|
|
|
|
|
|
if is_nightly(curr_version):
|
|
|
|
if args.bump == 'nightly':
|
|
|
|
version = get_next_nightly(curr_version)
|
|
|
|
elif args.bump == 'beta':
|
|
|
|
version = get_next_beta(curr_version)
|
|
|
|
elif args.bump == 'stable':
|
|
|
|
version = get_next_stable_from_pre(curr_version)
|
|
|
|
else:
|
|
|
|
not_reached()
|
|
|
|
elif is_beta(curr_version):
|
|
|
|
if args.bump == 'nightly':
|
|
|
|
version = get_next_nightly(curr_version)
|
|
|
|
elif args.bump == 'beta':
|
|
|
|
version = get_next_beta(curr_version)
|
|
|
|
elif args.bump == 'stable':
|
|
|
|
version = get_next_stable_from_pre(curr_version)
|
|
|
|
else:
|
|
|
|
not_reached()
|
|
|
|
elif is_stable(curr_version):
|
|
|
|
if args.bump == 'nightly':
|
|
|
|
version = get_next_nightly(curr_version)
|
|
|
|
elif args.bump == 'beta':
|
|
|
|
raise Exception("You can\'t bump to a beta from stable")
|
|
|
|
elif args.bump == 'stable':
|
|
|
|
version = get_next_stable_from_stable(curr_version)
|
|
|
|
else:
|
|
|
|
not_reached()
|
|
|
|
else:
|
|
|
|
raise Exception("Invalid current version: " + curr_version)
|
2017-08-29 22:33:49 +00:00
|
|
|
|
2018-09-16 17:24:07 +00:00
|
|
|
if args.new_version is None and args.bump is None and not args.stable:
|
2017-08-29 22:33:49 +00:00
|
|
|
parser.print_help()
|
2013-11-07 04:52:26 +00:00
|
|
|
return 1
|
|
|
|
|
2018-08-17 17:42:45 +00:00
|
|
|
versions = clean_parse_version(version)
|
2018-08-16 15:57:12 +00:00
|
|
|
suffix = ''
|
2018-08-17 17:42:45 +00:00
|
|
|
if '-' in version:
|
|
|
|
suffix = '-' + version.split('-')[1]
|
2018-08-17 22:15:45 +00:00
|
|
|
versions[3] = parse_version(version)[3]
|
2018-08-17 17:42:45 +00:00
|
|
|
version = version.split('-')[0]
|
2017-08-29 22:33:49 +00:00
|
|
|
|
2017-08-29 22:56:16 +00:00
|
|
|
if args.dry_run:
|
|
|
|
print 'new version number would be: {0}\n'.format(version + suffix)
|
|
|
|
return 0
|
|
|
|
|
2014-01-27 10:37:39 +00:00
|
|
|
with scoped_cwd(SOURCE_ROOT):
|
2018-09-27 18:53:08 +00:00
|
|
|
update_version(version, suffix)
|
2014-01-27 10:37:39 +00:00
|
|
|
update_win_rc(version, versions)
|
2017-11-13 06:37:54 +00:00
|
|
|
update_version_h(versions, suffix)
|
2014-01-27 10:37:39 +00:00
|
|
|
update_info_plist(version)
|
2017-08-29 22:33:49 +00:00
|
|
|
update_package_json(version, suffix)
|
|
|
|
tag_version(version, suffix)
|
2013-11-07 04:52:26 +00:00
|
|
|
|
2017-10-23 15:02:50 +00:00
|
|
|
print 'Bumped to version: {0}'.format(version + suffix)
|
2013-11-07 04:52:26 +00:00
|
|
|
|
2018-08-17 17:42:45 +00:00
|
|
|
def not_reached():
|
|
|
|
raise Exception('Unreachable code was reached')
|
|
|
|
|
2014-01-27 10:37:39 +00:00
|
|
|
def increase_version(versions, index):
|
2014-03-16 11:02:59 +00:00
|
|
|
for i in range(index + 1, 4):
|
|
|
|
versions[i] = '0'
|
2014-01-27 10:37:39 +00:00
|
|
|
versions[index] = str(int(versions[index]) + 1)
|
|
|
|
return versions
|
2013-11-07 04:52:26 +00:00
|
|
|
|
|
|
|
|
2018-09-27 18:53:08 +00:00
|
|
|
def update_version(version, suffix):
|
|
|
|
with open('VERSION', 'w') as f:
|
|
|
|
f.write(version + suffix)
|
2013-11-07 04:52:26 +00:00
|
|
|
|
|
|
|
|
2013-11-07 07:19:37 +00:00
|
|
|
def update_win_rc(version, versions):
|
|
|
|
pattern_fv = re.compile(' FILEVERSION [0-9,]+')
|
|
|
|
pattern_pv = re.compile(' PRODUCTVERSION [0-9,]+')
|
|
|
|
pattern_fvs = re.compile(' *VALUE "FileVersion", "[0-9.]+"')
|
|
|
|
pattern_pvs = re.compile(' *VALUE "ProductVersion", "[0-9.]+"')
|
|
|
|
|
2014-03-16 07:49:12 +00:00
|
|
|
win_rc = os.path.join('atom', 'browser', 'resources', 'win', 'atom.rc')
|
2013-11-07 07:19:37 +00:00
|
|
|
with open(win_rc, 'r') as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
versions = [str(v) for v in versions]
|
|
|
|
for i in range(0, len(lines)):
|
|
|
|
line = lines[i]
|
|
|
|
if pattern_fv.match(line):
|
|
|
|
lines[i] = ' FILEVERSION {0}\r\n'.format(','.join(versions))
|
|
|
|
elif pattern_pv.match(line):
|
|
|
|
lines[i] = ' PRODUCTVERSION {0}\r\n'.format(','.join(versions))
|
|
|
|
elif pattern_fvs.match(line):
|
|
|
|
lines[i] = ' VALUE "FileVersion", "{0}"\r\n'.format(version)
|
|
|
|
elif pattern_pvs.match(line):
|
|
|
|
lines[i] = ' VALUE "ProductVersion", "{0}"\r\n'.format(version)
|
|
|
|
|
|
|
|
with open(win_rc, 'w') as f:
|
|
|
|
f.write(''.join(lines))
|
|
|
|
|
|
|
|
|
2017-11-13 06:37:54 +00:00
|
|
|
def update_version_h(versions, suffix):
|
2014-03-16 07:49:12 +00:00
|
|
|
version_h = os.path.join('atom', 'common', 'atom_version.h')
|
2013-11-07 07:19:37 +00:00
|
|
|
with open(version_h, 'r') as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
for i in range(0, len(lines)):
|
|
|
|
line = lines[i]
|
|
|
|
if 'ATOM_MAJOR_VERSION' in line:
|
|
|
|
lines[i] = '#define ATOM_MAJOR_VERSION {0}\n'.format(versions[0])
|
|
|
|
lines[i + 1] = '#define ATOM_MINOR_VERSION {0}\n'.format(versions[1])
|
2013-11-07 08:59:33 +00:00
|
|
|
lines[i + 2] = '#define ATOM_PATCH_VERSION {0}\n'.format(versions[2])
|
2017-11-13 17:27:02 +00:00
|
|
|
|
|
|
|
if (suffix):
|
|
|
|
lines[i + 3] = '#define ATOM_PRE_RELEASE_VERSION {0}\n'.format(suffix)
|
|
|
|
else:
|
|
|
|
lines[i + 3] = '// #define ATOM_PRE_RELEASE_VERSION\n'
|
2013-11-07 07:19:37 +00:00
|
|
|
|
|
|
|
with open(version_h, 'w') as f:
|
|
|
|
f.write(''.join(lines))
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2013-11-07 07:37:21 +00:00
|
|
|
def update_info_plist(version):
|
2014-03-16 07:49:12 +00:00
|
|
|
info_plist = os.path.join('atom', 'browser', 'resources', 'mac', 'Info.plist')
|
2013-11-07 07:37:21 +00:00
|
|
|
with open(info_plist, 'r') as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
for i in range(0, len(lines)):
|
|
|
|
line = lines[i]
|
|
|
|
if 'CFBundleVersion' in line:
|
|
|
|
lines[i + 1] = ' <string>{0}</string>\n'.format(version)
|
2015-09-29 05:25:51 +00:00
|
|
|
if 'CFBundleShortVersionString' in line:
|
|
|
|
lines[i + 1] = ' <string>{0}</string>\n'.format(version)
|
2013-11-07 07:37:21 +00:00
|
|
|
|
2015-09-29 05:25:51 +00:00
|
|
|
with open(info_plist, 'w') as f:
|
|
|
|
f.write(''.join(lines))
|
2013-11-07 07:37:21 +00:00
|
|
|
|
|
|
|
|
2017-08-29 22:33:49 +00:00
|
|
|
def update_package_json(version, suffix):
|
2018-09-13 07:04:39 +00:00
|
|
|
metadata_json_files = ['package.json', 'package-lock.json']
|
|
|
|
for json_file in metadata_json_files:
|
|
|
|
with open(json_file, 'r') as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
for i in range(0, len(lines)):
|
|
|
|
line = lines[i];
|
|
|
|
if 'version' in line:
|
|
|
|
lines[i] = ' "version": "{0}",\n'.format(version + suffix)
|
|
|
|
break
|
|
|
|
|
|
|
|
with open(json_file, 'w') as f:
|
|
|
|
f.write(''.join(lines))
|
2015-12-10 11:46:06 +00:00
|
|
|
|
|
|
|
|
2017-08-29 22:33:49 +00:00
|
|
|
def tag_version(version, suffix):
|
2018-08-16 15:57:12 +00:00
|
|
|
execute([
|
|
|
|
'git',
|
|
|
|
'commit',
|
|
|
|
'-a',
|
|
|
|
'-m',
|
|
|
|
'Bump v{0}'.format(version + suffix),
|
|
|
|
'-n'
|
|
|
|
])
|
2013-11-07 07:39:41 +00:00
|
|
|
|
|
|
|
|
2013-11-07 04:52:26 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|