Created
April 2, 2015 18:55
-
-
Save john-g-g/ff8832a2b13ba18b736d to your computer and use it in GitHub Desktop.
Increment Google App Engine app version string. If each deploy is a unique version, App Engine deploys are zero risk thanks to version routing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import yaml | |
def increment_version(version, inc_major=None, inc_minor=None, sep='-'): | |
version_string = str(version) | |
if '-' in version_string: | |
major, minor = version_string.split('-') | |
else: | |
major = version_string | |
minor = 0 | |
try: | |
if inc_major: | |
major = int(major) + 1 | |
if inc_minor: | |
minor = int(minor) + 1 | |
except ValueError: | |
raise SystemExit('Bad version string format! Format is: "1" or "1-0"') | |
return sep.join([str(major), str(minor)]) | |
description = '''\ | |
increment Appengine app version string in app.yaml. | |
version string format must be: | |
"1" or "2-1"''' | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.RawDescriptionHelpFormatter, | |
description=description) | |
parser.add_argument('path', help='Appengine yaml file') | |
parser.add_argument('--major', action='store_true', | |
help='Increment major version') | |
parser.add_argument('--minor', action='store_true', default=True, | |
help='Increment minor version') | |
args = parser.parse_args() | |
with open(args.path) as f: | |
data = yaml.load(f) | |
version = increment_version(data['version'], args.major, args.minor) | |
data['version'] = version | |
print yaml.dump(data) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment