Update bump-version.py to handle prerelease versions

This commit is contained in:
Vanessa Yuen 2017-08-29 18:33:49 -04:00
parent cc666c727f
commit 8fe675e56c

View file

@ -3,6 +3,7 @@
import os import os
import re import re
import sys import sys
import argparse
from lib.util import execute, get_electron_version, parse_version, scoped_cwd from lib.util import execute, get_electron_version, parse_version, scoped_cwd
@ -11,28 +12,46 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
def main(): def main():
if len(sys.argv) != 2 or sys.argv[1] == '-h':
print 'Usage: bump-version.py [<version> | major | minor | patch]' parser = argparse.ArgumentParser(description='Bump version numbers. Must specify at least one option.')
parser.add_argument('--version', default=None, dest='new_version', help='new version number')
parser.add_argument('--bump', action='store', dest='bump', default=None, help='increment [major | minor | patch | beta]')
parser.add_argument('--stable', action='store_true', default= False, dest='stable', help='promote to stable')
args = parser.parse_args()
if args.new_version == None and args.bump == None and args.stable == False:
parser.print_help()
return 1 return 1
option = sys.argv[1] increments = ['major', 'minor', 'patch', 'beta']
increments = ['major', 'minor', 'patch', 'build']
if option in increments: curr_version = get_electron_version()
version = get_electron_version() versions = parse_version(re.sub('-beta', '', curr_version))
versions = parse_version(version.split('-')[0])
versions = increase_version(versions, increments.index(option)) if args.bump in increments:
else: versions = increase_version(versions, increments.index(args.bump))
versions = parse_version(option) if versions[3] == '0':
# beta starts at 1
versions = increase_version(versions, increments.index('beta'))
if args.stable == True:
versions[3] = '0'
if args.new_version != None:
versions = parse_version(re.sub('-beta', '', args.new_version))
version = '.'.join(versions[:3]) version = '.'.join(versions[:3])
suffix = '' if versions[3] == '0' else '-beta.' + versions[3]
with scoped_cwd(SOURCE_ROOT): with scoped_cwd(SOURCE_ROOT):
update_electron_gyp(version) update_electron_gyp(version, suffix)
update_win_rc(version, versions) update_win_rc(version, versions)
update_version_h(versions) update_version_h(versions)
update_info_plist(version) update_info_plist(version)
update_package_json(version) update_package_json(version, suffix)
tag_version(version) tag_version(version, suffix)
def increase_version(versions, index): def increase_version(versions, index):
@ -42,14 +61,14 @@ def increase_version(versions, index):
return versions return versions
def update_electron_gyp(version): def update_electron_gyp(version, suffix):
pattern = re.compile(" *'version%' *: *'[0-9.]+'") pattern = re.compile(" *'version%' *: *'[0-9.]+(-beta[0-9.]*)?'")
with open('electron.gyp', 'r') as f: with open('electron.gyp', 'r') as f:
lines = f.readlines() lines = f.readlines()
for i in range(0, len(lines)): for i in range(0, len(lines)):
if pattern.match(lines[i]): if pattern.match(lines[i]):
lines[i] = " 'version%': '{0}',\n".format(version) lines[i] = " 'version%': '{0}',\n".format(version + suffix)
with open('electron.gyp', 'w') as f: with open('electron.gyp', 'w') as f:
f.write(''.join(lines)) f.write(''.join(lines))
return return
@ -114,7 +133,7 @@ def update_info_plist(version):
f.write(''.join(lines)) f.write(''.join(lines))
def update_package_json(version): def update_package_json(version, suffix):
package_json = 'package.json' package_json = 'package.json'
with open(package_json, 'r') as f: with open(package_json, 'r') as f:
lines = f.readlines() lines = f.readlines()
@ -122,15 +141,15 @@ def update_package_json(version):
for i in range(0, len(lines)): for i in range(0, len(lines)):
line = lines[i]; line = lines[i];
if 'version' in line: if 'version' in line:
lines[i] = ' "version": "{0}",\n'.format(version) lines[i] = ' "version": "{0}",\n'.format(version + suffix)
break break
with open(package_json, 'w') as f: with open(package_json, 'w') as f:
f.write(''.join(lines)) f.write(''.join(lines))
def tag_version(version): def tag_version(version, suffix):
execute(['git', 'commit', '-a', '-m', 'Bump v{0}'.format(version)]) execute(['git', 'commit', '-a', '-m', 'Bump v{0}'.format(version + suffix)])
if __name__ == '__main__': if __name__ == '__main__':