7
7
from azure_devtools .ci_tools .git_tools import get_add_diff_file_list
8
8
from pathlib import Path
9
9
from subprocess import check_call
10
- from typing import List , Dict , Any
10
+ from typing import Dict , Any
11
11
from glob import glob
12
12
import yaml
13
13
14
14
from .swaggertosdk .autorest_tools import build_autorest_options , generate_code
15
15
from .swaggertosdk .SwaggerToSdkCore import CONFIG_FILE_DPG , read_config
16
+ from jinja2 import Environment , FileSystemLoader
16
17
17
18
18
19
_LOGGER = logging .getLogger (__name__ )
@@ -326,6 +327,25 @@ def get_npm_package_version(package: str) -> Dict[any, any]:
326
327
327
328
return data ["dependencies" ]
328
329
330
+ def generate_ci (template_path : Path , folder_path : Path , package_name : str ) -> None :
331
+ ci = Path (folder_path , "ci.yml" )
332
+ service_name = folder_path .name
333
+ safe_name = package_name .replace ("-" , "" )
334
+ if not ci .exists ():
335
+ env = Environment (loader = FileSystemLoader (template_path ), keep_trailing_newline = True )
336
+ template = env .get_template ('ci.yml' )
337
+ content = template .render (package_name = package_name , service_name = service_name , safe_name = safe_name )
338
+ else :
339
+ with open (ci , "r" ) as file_in :
340
+ content = file_in .readlines ()
341
+ for line in content :
342
+ if package_name in line :
343
+ return
344
+ content .append (f' - name: { package_name } \n ' )
345
+ content .append (f' safeName: { safe_name } \n ' )
346
+ with open (ci , "w" ) as file_out :
347
+ file_out .writelines (content )
348
+
329
349
def gen_cadl (cadl_relative_path : str , spec_folder : str ) -> Dict [str , Any ]:
330
350
# update config file
331
351
cadl_python = "@azure-tools/cadl-python"
@@ -353,13 +373,20 @@ def gen_cadl(cadl_relative_path: str, spec_folder: str) -> Dict[str, Any]:
353
373
354
374
# generate code
355
375
check_call (f"npx cadl compile . --emit { cadl_python } " , shell = True )
356
- if Path (output_path / "output.yaml" ).exists ():
357
- os .remove (Path ( output_path / "output.yaml" ) )
376
+ if (output_path / "output.yaml" ).exists ():
377
+ os .remove (output_path / "output.yaml" )
358
378
359
379
# get version of codegen used in generation
360
380
npm_package_verstion = get_npm_package_version (autorest_python )
361
381
362
382
# return to original folder
363
383
os .chdir (origin_path )
364
384
385
+ # add ci.yaml
386
+ generate_ci (
387
+ template_path = Path ("scripts/quickstart_tooling_dpg/template_ci" ),
388
+ folder_path = output_path .parent ,
389
+ package_name = project_yaml ["emitters" ][cadl_python ]["package-name" ]
390
+ )
391
+
365
392
return npm_package_verstion
0 commit comments