Make bump-version accept major/minor/patch/build.

This commit is contained in:
Cheng Zhao 2014-01-27 18:37:39 +08:00
parent 75ec34884d
commit f05daa8bdc

View file

@ -5,34 +5,51 @@ import re
import subprocess
import sys
from lib.util import get_atom_shell_version, scoped_cwd
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
def main():
if len(sys.argv) != 2:
print 'Usage: bump-version.py version'
if len(sys.argv) != 2 or sys.argv[1] == '-h':
print 'Usage: bump-version.py [<version> | major | minor | patch]'
return 1
version = sys.argv[1]
if version[0] == 'v':
version = version[1:]
versions = parse_version(version)
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)
os.chdir(SOURCE_ROOT)
version = '.'.join(versions[:3])
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()
def parse_version(version):
if version[0] == 'v':
version = version[1:]
vs = version.split('.')
if len(vs) > 4:
return vs[0:4]
else:
return vs + [0] * (4 - len(vs))
return vs + ['0'] * (4 - len(vs))
def increase_version(versions, index):
versions[index] = str(int(versions[index]) + 1)
return versions
def update_package_json(version):
@ -112,5 +129,9 @@ def tag_version(version):
subprocess.check_call(['git', 'tag', 'v{0}'.format(version)])
def git_push():
subprocess.check_call(['git', 'push'])
if __name__ == '__main__':
sys.exit(main())