Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 2 | """Compatibility tests between last released and the current version. |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 3 | |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 4 | Usage: ./update_compatibility_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>] |
| 5 | Example: ./update_compatibility_version.py 3.7.1 |
| 6 | """ |
| 7 | |
| 8 | from __future__ import print_function |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 9 | import re |
| 10 | import sys |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 11 | |
| 12 | if len(sys.argv) < 2 or len(sys.argv) > 3: |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 13 | print(""" |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 14 | [ERROR] Please specify a version. |
| 15 | |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 16 | ./update_compatibility_version.py.py <MAJOR>.<MINOR>.<MICRO> [<RC version>] |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 17 | |
| 18 | Example: |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 19 | ./update_compatibility_version.py.py 3.7.1 2 |
| 20 | """) |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 21 | exit(1) |
| 22 | |
| 23 | NEW_VERSION = sys.argv[1] |
| 24 | NEW_VERSION_INFO = NEW_VERSION.split('.') |
| 25 | if len(NEW_VERSION_INFO) != 3: |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 26 | print(""" |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 27 | [ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO> |
| 28 | |
| 29 | Example: |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 30 | ./update_compatibility_version.py.py 3.7.3 |
| 31 | """) |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 32 | exit(1) |
| 33 | |
| 34 | if len(sys.argv) > 2: |
| 35 | RC_VERSION = int(sys.argv[2]) |
| 36 | # Do not update compatibility versions for rc release |
| 37 | if RC_VERSION != 0: |
| 38 | exit(0) |
| 39 | |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 40 | |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 41 | def RewriteTextFile(filename, line_rewriter): |
| 42 | lines = open(filename, 'r').readlines() |
| 43 | updated_lines = [] |
| 44 | for line in lines: |
| 45 | updated_lines.append(line_rewriter(line)) |
| 46 | if lines == updated_lines: |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 47 | print('%s was not updated. Please double check.' % filename) |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 48 | f = open(filename, 'w') |
| 49 | f.write(''.join(updated_lines)) |
| 50 | f.close() |
| 51 | |
| 52 | |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 53 | def ReplaceVersion(line): |
| 54 | return re.sub(r'LAST_RELEASED=.*$', 'LAST_RELEASED=%s' % NEW_VERSION, line) |
Jie Luo | e399308 | 2019-07-25 14:31:00 -0700 | [diff] [blame] | 55 | |
Paul Yang | 763c358 | 2019-09-12 11:03:27 -0700 | [diff] [blame] | 56 | RewriteTextFile('tests.sh', ReplaceVersion) |