|
| 1 | +from __future__ import print_function |
| 2 | + |
| 3 | +import os |
| 4 | +import re |
| 5 | +from argparse import ArgumentParser |
| 6 | +from twilio import __version_info__, __version__ |
| 7 | + |
| 8 | +def main(version): |
| 9 | + current_version = __version__ |
| 10 | + |
| 11 | + if version is None: |
| 12 | + match = re.search(r'(\d+)$', __version_info__[-1]) |
| 13 | + if not match or match.group() is None: |
| 14 | + exit('Unable to auto bump version') |
| 15 | + |
| 16 | + patch = int(match.group()) |
| 17 | + patch += 1 |
| 18 | + |
| 19 | + prefix = __version_info__[-1][:(-1 * len(match.group()))] |
| 20 | + |
| 21 | + new_patch = '{}{}'.format(prefix, patch) |
| 22 | + |
| 23 | + version = '.'.join(__version_info__[:-1] + (new_patch, )) |
| 24 | + |
| 25 | + print('Deploying {} -> {}'.format(current_version, version)) |
| 26 | + |
| 27 | + info = version.split('.') |
| 28 | + |
| 29 | + init_src = ("__version_info__ = ({version_info})\n" |
| 30 | + "__version__ = '.'.join(__version_info__)") |
| 31 | + init_src = init_src.format(version_info=', '.join(["'{}'".format(i) for i in info])) |
| 32 | + |
| 33 | + print('Updating twilio/__init__.py ... ', end="") |
| 34 | + with open('twilio/__init__.py', 'w') as init_file: |
| 35 | + init_file.write(init_src) |
| 36 | + print('Done') |
| 37 | + |
| 38 | + new_readme = [] |
| 39 | + |
| 40 | + print('Updating README.md ... ', end="") |
| 41 | + with open('README.md', 'r') as readme: |
| 42 | + for line in readme.readlines(): |
| 43 | + if current_version in line: |
| 44 | + line = line.replace(current_version, version) |
| 45 | + new_readme.append(line) |
| 46 | + |
| 47 | + with open('README.md', 'w') as readme: |
| 48 | + readme.writelines(new_readme) |
| 49 | + print('Done') |
| 50 | + |
| 51 | + print('git commit version bump') |
| 52 | + os.system('git commit -am "Bumping version to {}"'.format(version)) |
| 53 | + os.system('git push') |
| 54 | + print('Done') |
| 55 | + |
| 56 | + print('Pushing to pypi') |
| 57 | + os.system('make release') |
| 58 | + print('Done') |
| 59 | + |
| 60 | + print('Adding git tag') |
| 61 | + os.system('git tag {}'.format(version)) |
| 62 | + os.system('git push --tags') |
| 63 | + print('Done') |
| 64 | + |
| 65 | + print('Deploy complete') |
| 66 | + |
| 67 | +if __name__ == '__main__': |
| 68 | + parser = ArgumentParser() |
| 69 | + parser.add_argument('version', nargs='?') |
| 70 | + args = parser.parse_args() |
| 71 | + |
| 72 | + main(args.version) |
0 commit comments