blob: f93479bd76caec9c8c839cdca12ad24c291aae1a [file] [log] [blame]
Jie Luoe3993082019-07-25 14:31:00 -07001#!/usr/bin/env python
Paul Yang763c3582019-09-12 11:03:27 -07002"""Compatibility tests between last released and the current version.
Jie Luoe3993082019-07-25 14:31:00 -07003
Paul Yang763c3582019-09-12 11:03:27 -07004Usage: ./update_compatibility_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
5Example: ./update_compatibility_version.py 3.7.1
6"""
7
8from __future__ import print_function
Jie Luoe3993082019-07-25 14:31:00 -07009import re
10import sys
Jie Luoe3993082019-07-25 14:31:00 -070011
12if len(sys.argv) < 2 or len(sys.argv) > 3:
Paul Yang763c3582019-09-12 11:03:27 -070013 print("""
Jie Luoe3993082019-07-25 14:31:00 -070014[ERROR] Please specify a version.
15
Paul Yang763c3582019-09-12 11:03:27 -070016./update_compatibility_version.py.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
Jie Luoe3993082019-07-25 14:31:00 -070017
18Example:
Paul Yang763c3582019-09-12 11:03:27 -070019./update_compatibility_version.py.py 3.7.1 2
20""")
Jie Luoe3993082019-07-25 14:31:00 -070021 exit(1)
22
23NEW_VERSION = sys.argv[1]
24NEW_VERSION_INFO = NEW_VERSION.split('.')
25if len(NEW_VERSION_INFO) != 3:
Paul Yang763c3582019-09-12 11:03:27 -070026 print("""
Jie Luoe3993082019-07-25 14:31:00 -070027[ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO>
28
29Example:
Paul Yang763c3582019-09-12 11:03:27 -070030./update_compatibility_version.py.py 3.7.3
31""")
Jie Luoe3993082019-07-25 14:31:00 -070032 exit(1)
33
34if 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 Yang763c3582019-09-12 11:03:27 -070040
Jie Luoe3993082019-07-25 14:31:00 -070041def 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 Yang763c3582019-09-12 11:03:27 -070047 print('%s was not updated. Please double check.' % filename)
Jie Luoe3993082019-07-25 14:31:00 -070048 f = open(filename, 'w')
49 f.write(''.join(updated_lines))
50 f.close()
51
52
Paul Yang763c3582019-09-12 11:03:27 -070053def ReplaceVersion(line):
54 return re.sub(r'LAST_RELEASED=.*$', 'LAST_RELEASED=%s' % NEW_VERSION, line)
Jie Luoe3993082019-07-25 14:31:00 -070055
Paul Yang763c3582019-09-12 11:03:27 -070056RewriteTextFile('tests.sh', ReplaceVersion)