Update bump-version.py
to handle prerelease versions
This commit is contained in:
parent
cc666c727f
commit
8fe675e56c
1 changed files with 39 additions and 20 deletions
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
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():
|
||||
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
|
||||
|
||||
option = sys.argv[1]
|
||||
increments = ['major', 'minor', 'patch', 'build']
|
||||
if option in increments:
|
||||
version = get_electron_version()
|
||||
versions = parse_version(version.split('-')[0])
|
||||
versions = increase_version(versions, increments.index(option))
|
||||
else:
|
||||
versions = parse_version(option)
|
||||
increments = ['major', 'minor', 'patch', 'beta']
|
||||
|
||||
curr_version = get_electron_version()
|
||||
versions = parse_version(re.sub('-beta', '', curr_version))
|
||||
|
||||
if args.bump in increments:
|
||||
versions = increase_version(versions, increments.index(args.bump))
|
||||
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])
|
||||
suffix = '' if versions[3] == '0' else '-beta.' + versions[3]
|
||||
|
||||
|
||||
with scoped_cwd(SOURCE_ROOT):
|
||||
update_electron_gyp(version)
|
||||
update_electron_gyp(version, suffix)
|
||||
update_win_rc(version, versions)
|
||||
update_version_h(versions)
|
||||
update_info_plist(version)
|
||||
update_package_json(version)
|
||||
tag_version(version)
|
||||
update_package_json(version, suffix)
|
||||
tag_version(version, suffix)
|
||||
|
||||
|
||||
def increase_version(versions, index):
|
||||
|
@ -42,14 +61,14 @@ def increase_version(versions, index):
|
|||
return versions
|
||||
|
||||
|
||||
def update_electron_gyp(version):
|
||||
pattern = re.compile(" *'version%' *: *'[0-9.]+'")
|
||||
def update_electron_gyp(version, suffix):
|
||||
pattern = re.compile(" *'version%' *: *'[0-9.]+(-beta[0-9.]*)?'")
|
||||
with open('electron.gyp', '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)
|
||||
lines[i] = " 'version%': '{0}',\n".format(version + suffix)
|
||||
with open('electron.gyp', 'w') as f:
|
||||
f.write(''.join(lines))
|
||||
return
|
||||
|
@ -114,7 +133,7 @@ def update_info_plist(version):
|
|||
f.write(''.join(lines))
|
||||
|
||||
|
||||
def update_package_json(version):
|
||||
def update_package_json(version, suffix):
|
||||
package_json = 'package.json'
|
||||
with open(package_json, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
@ -122,15 +141,15 @@ def update_package_json(version):
|
|||
for i in range(0, len(lines)):
|
||||
line = lines[i];
|
||||
if 'version' in line:
|
||||
lines[i] = ' "version": "{0}",\n'.format(version)
|
||||
lines[i] = ' "version": "{0}",\n'.format(version + suffix)
|
||||
break
|
||||
|
||||
with open(package_json, 'w') as f:
|
||||
f.write(''.join(lines))
|
||||
|
||||
|
||||
def tag_version(version):
|
||||
execute(['git', 'commit', '-a', '-m', 'Bump v{0}'.format(version)])
|
||||
def tag_version(version, suffix):
|
||||
execute(['git', 'commit', '-a', '-m', 'Bump v{0}'.format(version + suffix)])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue