12
12
from ghapi .all import GhApi
13
13
from github import Github
14
14
from datetime import datetime , timedelta
15
- import importlib
16
15
17
16
_LOG = logging .getLogger ()
18
17
@@ -47,40 +46,6 @@ def print_check(cmd):
47
46
subprocess .check_call (cmd , shell = True )
48
47
49
48
50
- def preview_version_plus (preview_label : str , last_version : str ) -> str :
51
- num = last_version .split (preview_label )
52
- num [1 ] = str (int (num [1 ]) + 1 )
53
- return f"{ num [0 ]} { preview_label } { num [1 ]} "
54
-
55
-
56
- def stable_version_plus (changelog : str , last_version : str ):
57
- flag = [False , False , False ] # breaking, feature, bugfix
58
- flag [0 ] = "### Breaking Changes" in changelog
59
- flag [1 ] = "### Features Added" in changelog
60
- flag [2 ] = "### Bugs Fixed" in changelog
61
-
62
- num = last_version .split ("." )
63
- if flag [0 ]:
64
- return f"{ int (num [0 ]) + 1 } .0.0"
65
- elif flag [1 ]:
66
- return f"{ num [0 ]} .{ int (num [1 ]) + 1 } .0"
67
- elif flag [2 ]:
68
- return f"{ num [0 ]} .{ num [1 ]} .{ int (num [2 ]) + 1 } "
69
- else :
70
- return "0.0.0"
71
-
72
-
73
- # find all the files of one folder, including files in subdirectory
74
- def all_files (path : str , files : List [str ]):
75
- all_folder = os .listdir (path )
76
- for item in all_folder :
77
- folder = str (Path (f"{ path } /{ item } " ))
78
- if os .path .isdir (folder ):
79
- all_files (folder , files )
80
- else :
81
- files .append (folder )
82
-
83
-
84
49
def modify_file (file_path : str , func : Any ):
85
50
with open (file_path , "r" ) as file_in :
86
51
content = file_in .readlines ()
@@ -182,6 +147,8 @@ def generate_code(self):
182
147
"repoHttpsUrl" : "https://github.com/Azure/azure-rest-api-specs" ,
183
148
"specFolder" : self .spec_repo ,
184
149
file_name : [self .readme_local_folder ()],
150
+ "targetReleaseDate" : self .target_release_date ,
151
+ "allowInvalidNextVersion" : True ,
185
152
}
186
153
log (str (input_data ))
187
154
@@ -218,16 +185,6 @@ def create_new_branch(self):
218
185
self .new_branch = f"t2-{ self .package_name } -{ current_time ()} -{ str (time .time ())[- 5 :]} "
219
186
print_check (f"git checkout -b { self .new_branch } " )
220
187
221
- def check_sdk_readme (self ):
222
- sdk_readme = str (Path (f"sdk/{ self .sdk_folder } /{ self .whole_package_name } /README.md" ))
223
-
224
- def edit_sdk_readme (content : List [str ]):
225
- for i in range (0 , len (content )):
226
- if content [i ].find ("MyService" ) > 0 :
227
- content [i ] = content [i ].replace ("MyService" , self .package_name .capitalize ())
228
-
229
- modify_file (sdk_readme , edit_sdk_readme )
230
-
231
188
@property
232
189
def readme_md_path (self ) -> Path :
233
190
return Path (self .spec_repo ) / "specification" / self .spec_readme .split ("specification/" )[- 1 ]
@@ -236,89 +193,6 @@ def readme_md_path(self) -> Path:
236
193
def readme_python_md_path (self ) -> Path :
237
194
return Path (str (self .readme_md_path ).replace ("readme.md" , "readme.python.md" ))
238
195
239
- # Use the template to update readme and setup by packaging_tools
240
- @return_origin_path
241
- def check_file_with_packaging_tool (self ):
242
- print_check (f"pip install { self .get_whl_package } --force-reinstall" )
243
- module = importlib .import_module (self .whole_package_name .replace ("-" , "." ))
244
- title = ""
245
- for item in getattr (module , "__all__" , []):
246
- if item .endswith ("Client" ):
247
- title = item
248
- break
249
-
250
- if not title :
251
- log (f"Can not find the title in { self .whole_package_name } " )
252
-
253
- os .chdir (Path (f"sdk/{ self .sdk_folder } " ))
254
- # add `title` and update `is_stable` in sdk_packaging.toml
255
- toml = Path (self .whole_package_name ) / "sdk_packaging.toml"
256
- stable_config = "is_stable = " + ("true" if self .tag_is_stable else "false" ) + "\n "
257
- if toml .exists ():
258
-
259
- def edit_toml (content : List [str ]):
260
- has_title = False
261
- has_isstable = False
262
- for idx in range (len (content )):
263
- if "title" in content [idx ]:
264
- has_title = True
265
- if "is_stable" in content [idx ]:
266
- has_isstable = True
267
- content [idx ] = stable_config
268
- if not has_title :
269
- content .append (f'title = "{ title } "\n ' )
270
- if not has_isstable :
271
- content .append (stable_config )
272
-
273
- modify_file (str (toml ), edit_toml )
274
- else :
275
- log (f"{ os .getcwd ()} /{ toml } does not exist" )
276
-
277
- print_check (f"python -m packaging_tools --build-conf { self .whole_package_name } " )
278
- log ("packaging_tools --build-conf successfully " )
279
-
280
- def check_pprint_name (self ):
281
- pprint_name = self .package_name .capitalize ()
282
-
283
- def edit_file_for_pprint_name (content : List [str ]):
284
- for i in range (0 , len (content )):
285
- content [i ] = content [i ].replace ("MyService" , pprint_name )
286
-
287
- for file in os .listdir (self .sdk_code_path ()):
288
- file_path = str (Path (self .sdk_code_path ()) / file )
289
- if os .path .isfile (file_path ):
290
- modify_file (file_path , edit_file_for_pprint_name )
291
- log (f' replace "MyService" with "{ pprint_name } " successfully ' )
292
-
293
- def get_all_files_under_package_folder (self ) -> List [str ]:
294
- files = []
295
- all_files (self .sdk_code_path (), files )
296
- return files
297
-
298
- def calculate_next_version_proc (self , last_version : str ):
299
- preview_tag = not self .tag_is_stable
300
- changelog = self .get_changelog ()
301
- if changelog == "" :
302
- self .version_suggestion = "(it should be stable)" if self .tag_is_stable else "(it should be perview)"
303
- return "0.0.0"
304
- preview_version = "rc" in last_version or "b" in last_version
305
- # | preview tag | stable tag
306
- # preview version(1.0.0rc1/1.0.0b1) | 1.0.0rc2(track1)/1.0.0b2(track2) | 1.0.0
307
- # stable version (1.0.0) (breaking change) | 2.0.0rc1(track1)/2.0.0b1(track2) | 2.0.0
308
- # stable version (1.0.0) (feature) | 1.1.0rc1(track1)/1.1.0b1(track2) | 1.1.0
309
- # stable version (1.0.0) (bugfix) | 1.0.1rc1(track1)/1.0.1b1(track2) | 1.0.1
310
- preview_label = "b"
311
- if preview_version and preview_tag :
312
- next_version = preview_version_plus (preview_label , last_version )
313
- elif preview_version and not preview_tag :
314
- next_version = last_version .split (preview_label )[0 ]
315
- elif not preview_version and preview_tag :
316
- next_version = stable_version_plus (changelog , last_version ) + preview_label + "1"
317
- else :
318
- next_version = stable_version_plus (changelog , last_version )
319
-
320
- return next_version
321
-
322
196
def get_autorest_result (self ) -> Dict [Any , Any ]:
323
197
with open (self .autorest_result , "r" ) as file_in :
324
198
content = json .load (file_in )
@@ -336,52 +210,6 @@ def get_last_release_version(self) -> str:
336
210
except :
337
211
return ""
338
212
339
- def calculate_next_version (self ):
340
- last_version = self .get_last_release_version ()
341
- if last_version :
342
- self .next_version = self .calculate_next_version_proc (last_version )
343
- else :
344
- self .next_version = "1.0.0b1"
345
-
346
- def edit_all_version_file (self ):
347
- files = self .get_all_files_under_package_folder ()
348
-
349
- def edit_version_file (content : List [str ]):
350
- for i in range (0 , len (content )):
351
- if content [i ].find ("VERSION" ) > - 1 :
352
- content [i ] = f'VERSION = "{ self .next_version } "\n '
353
- break
354
-
355
- for file in files :
356
- if Path (file ).name == "_version.py" :
357
- modify_file (file , edit_version_file )
358
-
359
- def check_version (self ):
360
- self .calculate_next_version ()
361
- self .edit_all_version_file ()
362
-
363
- def check_changelog_file (self ):
364
- def edit_changelog_proc (content : List [str ]):
365
- next_version = self .next_version
366
- content [1 :1 ] = [
367
- "\n " ,
368
- f"## { next_version } { self .version_suggestion } ({ self .target_release_date } )\n \n " ,
369
- self .get_changelog (),
370
- "\n " ,
371
- ]
372
- if next_version == "1.0.0b1" :
373
- for _ in range (4 ):
374
- content .pop ()
375
-
376
- modify_file (str (Path (self .sdk_code_path ()) / "CHANGELOG.md" ), edit_changelog_proc )
377
-
378
- def check_dev_requirement (self ):
379
- file = Path (f"sdk/{ self .sdk_folder } /{ self .whole_package_name } /dev_requirements.txt" )
380
- content = ["-e ../../../tools/azure-sdk-tools\n " , "../../identity/azure-identity\n " ]
381
- if not file .exists ():
382
- with open (file , "w" ) as file_out :
383
- file_out .writelines (content )
384
-
385
213
def check_package_size (self ):
386
214
if self .after_multiapi_combiner :
387
215
packages = self .get_private_package ()
@@ -392,7 +220,10 @@ def check_package_size(self):
392
220
)
393
221
394
222
def check_model_flatten (self ):
395
- if self .whole_package_name in ["azure-mgmt-mysqlflexibleservers" , "azure-mgmt-postgresqlflexibleservers" ]:
223
+ if self .whole_package_name in [
224
+ "azure-mgmt-mysqlflexibleservers" ,
225
+ "azure-mgmt-postgresqlflexibleservers" ,
226
+ ]:
396
227
return
397
228
if self .from_swagger :
398
229
last_version = self .get_last_release_version ()
@@ -416,38 +247,9 @@ def check_model_flatten(self):
416
247
issue .create_comment (f"@{ assignee } , { message } " )
417
248
raise Exception (message )
418
249
419
- @return_origin_path
420
- def check_pyproject_toml (self ):
421
- os .chdir (Path ("sdk" ) / self .sdk_folder / self .whole_package_name )
422
- # add `breaking = false` in pyproject.toml
423
- toml = Path ("pyproject.toml" )
424
- if not toml .exists ():
425
- with open (toml , "w" ) as file :
426
- file .write ("[tool.azure-sdk-build]\n breaking = false\n " )
427
- _LOG .info ("create pyproject.toml" )
428
-
429
- def edit_toml (content : List [str ]):
430
- has_breaking = False
431
- for line in content :
432
- if "breaking = false" in line :
433
- has_breaking = True
434
- break
435
- if not has_breaking :
436
- _LOG .info ("add breaking = false to pyproject.toml" )
437
- content .append ("breaking = false\n " )
438
-
439
- modify_file (str (toml ), edit_toml )
440
-
441
250
def check_file (self ):
442
- self .check_file_with_packaging_tool ()
443
- self .check_pprint_name ()
444
- self .check_sdk_readme ()
445
- self .check_version ()
446
- self .check_changelog_file ()
447
- self .check_dev_requirement ()
448
251
self .check_package_size ()
449
252
self .check_model_flatten ()
450
- self .check_pyproject_toml ()
451
253
452
254
def sdk_code_path (self ) -> str :
453
255
return str (Path (f"sdk/{ self .sdk_folder } /{ self .whole_package_name } " ))
@@ -550,10 +352,6 @@ def get_private_package(self) -> List[str]:
550
352
content = self .get_autorest_result ()
551
353
return content ["packages" ][0 ]["artifacts" ]
552
354
553
- @property
554
- def get_whl_package (self ) -> str :
555
- return [package for package in self .get_private_package () if package .endswith (".whl" )][0 ]
556
-
557
355
def ask_check_policy (self ):
558
356
changelog = self .get_changelog ()
559
357
if changelog == "" :
0 commit comments