2013-11-07 04:52:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2014-04-02 01:58:56 +00:00
|
|
|
from lib.util import execute, get_atom_shell_version, scoped_cwd
|
2014-01-27 10:37:39 +00:00
|
|
|
|
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():
|
2014-01-27 10:37:39 +00:00
|
|
|
if len(sys.argv) != 2 or sys.argv[1] == '-h':
|
|
|
|
print 'Usage: bump-version.py [<version> | major | minor | patch]'
|
2013-11-07 04:52:26 +00:00
|
|
|
return 1
|
|
|
|
|
2014-01-27 10:37:39 +00:00
|
|
|
option = sys.argv[1]
|
|
|
|
increments = ['major', 'minor', 'patch', 'build']
|
|
|
|
if option in increments:
|
|
|
|
version = get_atom_shell_version()
|
|
|
|
versions = parse_version(version.split('-')[0])
|
|
|
|
versions = increase_version(versions, increments.index(option))
|
|
|
|
else:
|
|
|
|
versions = parse_version(option)
|
|
|
|
|
|
|
|
version = '.'.join(versions[:3])
|
2013-11-07 04:52:26 +00:00
|
|
|
|
2014-01-27 10:37:39 +00:00
|
|
|
with scoped_cwd(SOURCE_ROOT):
|
|
|
|
update_package_json(version)
|
|
|
|
update_win_rc(version, versions)
|
|
|
|
update_version_h(versions)
|
|
|
|
update_info_plist(version)
|
|
|
|
tag_version(version)
|
|
|
|
git_push()
|
2013-11-07 04:52:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def parse_version(version):
|
2014-01-27 10:37:39 +00:00
|
|
|
if version[0] == 'v':
|
|
|
|
version = version[1:]
|
|
|
|
|
2013-11-07 04:52:26 +00:00
|
|
|
vs = version.split('.')
|
|
|
|
if len(vs) > 4:
|
|
|
|
return vs[0:4]
|
|
|
|
else:
|
2014-01-27 10:37:39 +00:00
|
|
|
return vs + ['0'] * (4 - len(vs))
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
def update_package_json(version):
|
|
|
|
pattern = re.compile(' *"version" *: *"[0-9.]+"')
|
|
|
|
with open('package.json', 'r') as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
for i in range(0, len(lines)):
|
|
|
|
if pattern.match(lines[i]):
|
|
|
|
lines[i] = ' "version": "{0}",\n'.format(version)
|
|
|
|
with open('package.json', 'w') as f:
|
|
|
|
f.write(''.join(lines))
|
|
|
|
return
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
|
|
def update_version_h(versions):
|
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])
|
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)
|
|
|
|
|
|
|
|
with open(info_plist, 'w') as f:
|
|
|
|
f.write(''.join(lines))
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2013-11-07 07:39:41 +00:00
|
|
|
def tag_version(version):
|
2014-04-02 01:58:56 +00:00
|
|
|
execute(['git', 'commit', '-a', '-m', 'Bump v{0}.'.format(version)])
|
|
|
|
execute(['git', 'tag', 'v{0}'.format(version)])
|
2013-11-07 07:39:41 +00:00
|
|
|
|
|
|
|
|
2014-01-27 10:37:39 +00:00
|
|
|
def git_push():
|
2014-04-02 01:58:56 +00:00
|
|
|
execute(['git', 'push'])
|
|
|
|
execute(['git', 'push', '--tags'])
|
2014-01-27 10:37:39 +00:00
|
|
|
|
|
|
|
|
2013-11-07 04:52:26 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|