Last active
August 6, 2019 03:58
-
-
Save kiichi/b3fe559fec5fb9e6ec30708dbb997afb to your computer and use it in GitHub Desktop.
Version Bump Script which generates version.json based on Ionic config.xml
This file contains hidden or 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
{"date": "2019-08-05T11:44:08.787879", "core": "1.1.3", "shell": "1.0.21", "mode": "DEBUG"} |
This file contains hidden or 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
# Run this script | |
# python version.py | |
# this will update src/assets/version.json | |
import sys | |
import datetime | |
import json | |
import re | |
content = '' | |
shell = '' | |
obj = [] | |
path = 'src/assets/version.json' | |
def print_usage(): | |
print("========================================= [Usage] ================================================"); | |
print("python version.py show help"); | |
print("python version.py --help show help"); | |
print("python version.py --debug set mode to debug"); | |
print("python version.py --prod set mode to prod"); | |
print("python version.py --date increment only timestamp. mode is fixed to prod."); | |
print("python version.py --patch increment patch number and timestamp. mode is fixed to prod."); | |
print("python version.py --minor increment minor number and timestamp. mode is fixed to prod."); | |
print("python version.py --major increment major number and timestamp. mode is fixed to prod."); | |
print("================================================================================================="); | |
def get_shell_version(): | |
p = re.compile('version="\d*.\d*.\d*"') | |
ret = '' | |
with open('config.xml', 'r') as config_file: | |
config_content = config_file.read() | |
found = re.findall('version="\d*.\d*.\d*"',config_content) | |
ret=found[0].replace('version="','').replace('"','') | |
return ret | |
#if sys.argv[1] == '--debug': | |
shell = get_shell_version() | |
print('Detected Shell Version in config.xml: %s'%shell) | |
with open(path, 'r') as content_file: | |
content = content_file.read() | |
obj = json.loads(content) | |
print('Detected current core version in version.json:') | |
print(content) | |
if len(sys.argv) < 2 or sys.argv[1] == '--help': | |
print_usage() | |
exit() | |
obj['mode'] = 'PROD' | |
obj['shell'] = shell | |
if sys.argv[1] == '--prod': | |
pass | |
elif sys.argv[1] == '--debug': | |
obj['mode'] = 'DEBUG' | |
else: | |
segments = obj['core'].split('.') | |
ver = list(map(lambda x: int(x), segments)) | |
obj['date'] = datetime.datetime.now().isoformat() | |
if sys.argv[1] == '--date': | |
pass | |
elif sys.argv[1] == '--patch': | |
ver[2] = ver[2]+1 | |
elif sys.argv[1] == '--minor': | |
ver[1] = ver[1]+1 | |
ver[2] = 0 | |
elif sys.argv[1] == '--major': | |
ver[0] = ver[0]+1 | |
ver[1] = 0 | |
ver[2] = 0 | |
obj['core'] = '%d.%d.%d' % (ver[0],ver[1],ver[2]) | |
out_str = json.dumps(obj) | |
with open(path, 'w') as text_file: | |
text_file.write(out_str) | |
print(out_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment