@@ -78,8 +78,41 @@ def create_changelog_content():
7878 return add_content
7979
8080
81- def edit_version (add_content ):
82- global VERSION_NEW , VERSION_LAST_RELEASE
81+ def judge_tag ():
82+ path = f'{ os .getcwd ()} /sdk/{ SDK_FOLDER } /azure-mgmt-{ SERVICE_NAME } '
83+ files = []
84+ all_files (path , files )
85+ default_api_version = '' # for multi-api
86+ api_version = '' # for single-api
87+ for file in files :
88+ if '.py' not in file :
89+ continue
90+ try :
91+ with open (file , 'r' ) as file_in :
92+ list_in = file_in .readlines ()
93+ except :
94+ _LOG .info (f'can not open { file } ' )
95+ continue
96+
97+ for line in list_in :
98+ if line .find ('DEFAULT_API_VERSION = ' ) > - 1 :
99+ default_api_version += line .split ('=' )[- 1 ].strip ('\n ' ) # collect all default api version
100+ if default_api_version == '' and line .find ('api_version = ' ) > - 1 :
101+ api_version += line .split ('=' )[- 1 ].strip ('\n ' ) # collect all single api version
102+ if default_api_version != '' :
103+ my_print (f'find default api version:{ default_api_version } ' )
104+ return 'preview' in default_api_version
105+ my_print (f'find single api version:{ api_version } ' )
106+ return 'preview' in api_version
107+
108+
109+ def preview_version_plus (preview_label ):
110+ num = VERSION_LAST_RELEASE .split (preview_label )
111+ num [1 ] = str (int (num [1 ]) + 1 )
112+ return f'{ num [0 ]} { preview_label } { num [1 ]} '
113+
114+
115+ def stable_version_plus (add_content ):
83116 flag = [False , False , False ] # breaking, feature, bugfix
84117 for line in add_content :
85118 if line .find ('**Breaking changes**' ) > - 1 :
@@ -89,36 +122,41 @@ def edit_version(add_content):
89122 flag [1 ] = True
90123 elif line .find ('**Bugfixes**' ) > - 1 :
91124 flag [2 ] = True
92-
93- path = f'sdk/{ SDK_FOLDER } /azure-mgmt-{ SERVICE_NAME } /azure/mgmt/{ SERVICE_NAME } '
94- file_name = 'version.py' if TRACK == '1' else '_version.py'
95- with open (f'{ path } /{ file_name } ' , 'r' ) as file_in :
96- list_in = file_in .readlines ()
97-
98125 num = VERSION_LAST_RELEASE .split ('.' )
99- if TRACK == '1' and num [0 ] == '0' :
100- VERSION_NEW = f'0.{ str (int (num [1 ]) + 1 )} .0'
101- elif VERSION_LAST_RELEASE .find ('b' ) > - 1 :
102- lastnum = num [2 ].split ('b' )
103- lastnum [1 ] = str (int (lastnum [1 ]) + 1 )
104- VERSION_NEW = f'{ num [0 ]} .{ num [1 ]} .{ lastnum [0 ]} b{ lastnum [1 ]} '
105- elif VERSION_LAST_RELEASE .find ('rc' ) > - 1 :
106- lastnum = num [2 ].split ('rc' )
107- lastnum [1 ] = str (int (lastnum [1 ]) + 1 )
108- VERSION_NEW = f'{ num [0 ]} .{ num [1 ]} .{ lastnum [0 ]} rc{ lastnum [1 ]} '
109- elif flag [0 ]:
110- VERSION_NEW = f'{ int (num [0 ]) + 1 } .0.0'
126+ if flag [0 ]:
127+ return f'{ int (num [0 ]) + 1 } .0.0'
111128 elif flag [1 ]:
112- VERSION_NEW = f'{ num [0 ]} .{ int (num [1 ]) + 1 } .0'
129+ return f'{ num [0 ]} .{ int (num [1 ]) + 1 } .0'
113130 elif flag [2 ]:
114- VERSION_NEW = f'{ num [0 ]} .{ num [1 ]} .{ int (num [2 ]) + 1 } '
131+ return f'{ num [0 ]} .{ num [1 ]} .{ int (num [2 ]) + 1 } '
132+ else :
133+ return '0.0.0'
115134
116- for i in range (0 , len (list_in )):
117- if list_in [i ].find ('VERSION ' ) > - 1 :
118- list_in [i ] = f'VERSION = "{ VERSION_NEW } "\n '
119- break
120- with open (f'{ path } /{ file_name } ' , 'w' ) as file_out :
121- file_out .writelines (list_in )
135+
136+ def edit_version (add_content ):
137+ global VERSION_NEW
138+
139+ preview_tag = judge_tag ()
140+ preview_version = 'rc' in VERSION_LAST_RELEASE or 'b' in VERSION_LAST_RELEASE
141+ # | preview tag | stable tag
142+ # preview version(1.0.0rc1/1.0.0b1) | 1.0.0rc2(track1)/1.0.0b2(track2) | 1.0.0
143+ # stable version (1.0.0) (breaking change) | 2.0.0rc1(track1)/2.0.0b1(track2) | 2.0.0
144+ # stable version (1.0.0) (feature) | 1.1.0rc1(track1)/1.1.0b1(track2) | 1.1.0
145+ # stable version (1.0.0) (bugfix) | 1.0.1rc1(track1)/1.0.1b1(track2) | 1.0.1
146+ preview_label = 'rc' if TRACK == '1' else 'b'
147+ if preview_version and preview_tag :
148+ VERSION_NEW = preview_version_plus (preview_label )
149+ elif preview_version and not preview_tag :
150+ VERSION_NEW = VERSION_LAST_RELEASE .split (preview_label )[0 ]
151+ elif not preview_version and preview_tag :
152+ VERSION_NEW = stable_version_plus (add_content ) + preview_label + '1'
153+ else :
154+ VERSION_NEW = stable_version_plus (add_content )
155+
156+ # additional rule for track1: if version is 0.x.x, next version is 0.x+1.0
157+ if TRACK == '1' and VERSION_LAST_RELEASE [0 ] == '0' :
158+ num = VERSION_LAST_RELEASE .split ('.' )
159+ VERSION_NEW = f'{ num [0 ]} .{ int (num [1 ]) + 1 } .0'
122160
123161
124162def edit_changelog (add_content ):
@@ -279,26 +317,30 @@ def run_live_test():
279317 my_print ('live test run done, do not find failure !!!' )
280318
281319
282- def edit_recursion (path , file ):
320+ # find all the files of one folder, including files in subdirectory
321+ def all_files (path , files ):
283322 all_folder = os .listdir (path )
284323 for folder in all_folder :
285- if file == folder :
286- tmp_file = f'{ path } /{ file } '
287- with open (tmp_file , 'r' ) as file_in :
288- list_in = file_in .readlines ()
289- for i in range (0 , len (list_in )):
290- if list_in [i ].find ('VERSION' ) > - 1 :
291- list_in [i ] = f'VERSION = "{ VERSION_NEW } "\n '
292- with open (tmp_file , 'w' ) as file_out :
293- file_out .writelines (list_in )
294- elif os .path .isdir (f'{ path } /{ folder } ' ):
295- edit_recursion (f'{ path } /{ folder } ' , file )
324+ if os .path .isdir (f'{ path } /{ folder } ' ):
325+ all_files (f'{ path } /{ folder } ' , files )
326+ else :
327+ files .append (f'{ path } /{ folder } ' )
296328
297329
298330def edit_useless_file ():
299- file = 'version.py' if TRACK == '1' else '_version .py'
331+ target_file = 'version.py'
300332 path = f'{ os .getcwd ()} /sdk/{ SDK_FOLDER } /azure-mgmt-{ SERVICE_NAME } '
301- edit_recursion (path , file )
333+ files = []
334+ all_files (path , files )
335+ for file in files :
336+ if target_file in file :
337+ with open (file , 'r' ) as file_in :
338+ list_in = file_in .readlines ()
339+ for i in range (0 , len (list_in )):
340+ if list_in [i ].find ('VERSION' ) > - 1 :
341+ list_in [i ] = f'VERSION = "{ VERSION_NEW } "\n '
342+ with open (file , 'w' ) as file_output :
343+ file_output .writelines (list_in )
302344
303345
304346def commit_test ():
@@ -318,7 +360,7 @@ def check_pprint_name():
318360 for file in os .listdir (path ):
319361 file_path = f'{ path } /{ file } '
320362 if os .path .isfile (file_path ):
321- with open (file_path , 'r' ) as file_in :
363+ with open (file_path , 'r' , encoding = "utf-8" ) as file_in :
322364 list_in = file_in .readlines ()
323365 for i in range (0 , len (list_in )):
324366 list_in [i ] = list_in [i ].replace ('MyService' , pprint_name )
0 commit comments