From 8fe675e56cb069d899b3431b778b02344c346616 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Tue, 29 Aug 2017 18:33:49 -0400 Subject: [PATCH 1/7] Update `bump-version.py` to handle prerelease versions --- script/bump-version.py | 59 ++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/script/bump-version.py b/script/bump-version.py index 4db30b71fca9..642002954c5d 100755 --- a/script/bump-version.py +++ b/script/bump-version.py @@ -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 [ | 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__': From 74c970c25f5a202e5f88838d0930a090aafbb10f Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Tue, 29 Aug 2017 18:56:16 -0400 Subject: [PATCH 2/7] add dry run option --- script/bump-version.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script/bump-version.py b/script/bump-version.py index 642002954c5d..e6faa90cc872 100755 --- a/script/bump-version.py +++ b/script/bump-version.py @@ -16,7 +16,8 @@ def main(): 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') + parser.add_argument('--stable', action='store_true', default= False, dest='stable', help='promote to stable (i.e. remove `-beta.x` suffix)') + parser.add_argument('--dry-run', action='store_true', default= False, dest='dry_run', help='just to check that version number is correct') args = parser.parse_args() @@ -44,6 +45,10 @@ def main(): version = '.'.join(versions[:3]) suffix = '' if versions[3] == '0' else '-beta.' + versions[3] + if args.dry_run: + print 'new version number would be: {0}\n'.format(version + suffix) + return 0 + with scoped_cwd(SOURCE_ROOT): update_electron_gyp(version, suffix) From b54804d449b002521f049e50e9f34a412be3e8f6 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Tue, 29 Aug 2017 19:37:49 -0400 Subject: [PATCH 3/7] change `process.versions.electron` to reflect suffixes in version name. --- npm/install.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/npm/install.js b/npm/install.js index 3a93295f35db..0419196de2a9 100755 --- a/npm/install.js +++ b/npm/install.js @@ -1,7 +1,6 @@ #!/usr/bin/env node -// maintainer note - x.y.z-ab version in package.json -> x.y.z -var version = require('./package').version.replace(/-.*/, '') +var version = require('./package').version var fs = require('fs') var os = require('os') From a936430fd5b4954bae0146e969505979ae5a3321 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Tue, 29 Aug 2017 19:55:34 -0400 Subject: [PATCH 4/7] fix lint errors --- script/bump-version.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/script/bump-version.py b/script/bump-version.py index e6faa90cc872..40dd75962895 100755 --- a/script/bump-version.py +++ b/script/bump-version.py @@ -13,11 +13,36 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def main(): - 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 (i.e. remove `-beta.x` suffix)') - parser.add_argument('--dry-run', action='store_true', default= False, dest='dry_run', help='just to check that version number is correct') + 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', + default=None, + dest='bump', + help='increment [major | minor | patch | beta]' + ) + parser.add_argument( + '--stable', + action='store_true', + default= False, + dest='stable', + help='promote to stable (i.e. remove `-beta.x` suffix)' + ) + parser.add_argument( + '--dry-run', + action='store_true', + default= False, + dest='dry_run', + help='just to check that version number is correct' + ) args = parser.parse_args() From c56d8b4fe94594935a8ff8cbcdfb979122241034 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Wed, 6 Sep 2017 16:31:58 -0400 Subject: [PATCH 5/7] Add examples to make usage description clearer. --- script/bump-version.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script/bump-version.py b/script/bump-version.py index 40dd75962895..653473cd2786 100755 --- a/script/bump-version.py +++ b/script/bump-version.py @@ -14,7 +14,12 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def main(): parser = argparse.ArgumentParser( - description='Bump version numbers. Must specify at least one option.' + description='Bump version numbers. Must specify at least one of the three options:\n' + +' --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' + +'Note that you can use both --bump and --stable simultaneously.', + formatter_class=argparse.RawTextHelpFormatter ) parser.add_argument( '--version', From a81ea1ffdeeeec35e4e9bd1f05a9e38a440b7c4c Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Wed, 6 Sep 2017 16:41:51 -0400 Subject: [PATCH 6/7] Update release documentation to reflect new usage of `bump-version` script. --- docs/development/releasing.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/development/releasing.md b/docs/development/releasing.md index a40ac2ce1401..1ef83234f8c4 100644 --- a/docs/development/releasing.md +++ b/docs/development/releasing.md @@ -24,10 +24,17 @@ make sure there are no drafts. ## Bump the version -Run the `bump-version` script, passing `major`, `minor`, or `patch` as an argument: +Run the `bump-version` script with arguments according to your need: +- `--bump=patch` to increment patch version, or +- `--stable` to indicate this is a stable version, or +- `--version={version}` to set version number directly. + +**Note**: you can use both `--bump` and `--stable` simultaneously. + +There is also a `dry-run` flag you can use to make sure the version number generated is correct before committing. ```sh -npm run bump-version -- patch +npm run bump-version -- --bump=patch --stable git push origin HEAD ``` From 4fb800a8994d336a89e37251606c929d53ded682 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Wed, 6 Sep 2017 16:44:41 -0400 Subject: [PATCH 7/7] more docs edit --- docs/development/releasing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development/releasing.md b/docs/development/releasing.md index 1ef83234f8c4..6a6f8dff7938 100644 --- a/docs/development/releasing.md +++ b/docs/development/releasing.md @@ -25,7 +25,7 @@ make sure there are no drafts. ## Bump the version Run the `bump-version` script with arguments according to your need: -- `--bump=patch` to increment patch version, or +- `--bump=[major|minor|patch|beta]` to increment one of the version numbers, or - `--stable` to indicate this is a stable version, or - `--version={version}` to set version number directly.