@@ -32,8 +32,8 @@ def sdk_automation_typespec(config: dict) -> List[dict]:
32
32
if 'relatedTypeSpecProjectFolder' not in config :
33
33
return packages
34
34
35
- head_sha = config ['headSha' ]
36
- repo_url = config ['repoHttpsUrl' ]
35
+ head_sha : str = config ['headSha' ]
36
+ repo_url : str = config ['repoHttpsUrl' ]
37
37
38
38
tsp_projects = config ['relatedTypeSpecProjectFolder' ]
39
39
if isinstance (tsp_projects , str ):
@@ -47,16 +47,40 @@ def sdk_automation_typespec(config: dict) -> List[dict]:
47
47
service = None
48
48
module = None
49
49
try :
50
- cmd = ['pwsh' , './eng/common/scripts/TypeSpec-Project-Process.ps1' , tsp_dir , head_sha , repo_url ]
51
- logging .info ('Command line: ' + ' ' .join (cmd ))
52
- output = subprocess .check_output (cmd , cwd = sdk_root )
53
- output_str = str (output , 'utf-8' )
54
- script_return = output_str .splitlines ()[- 1 ] # the path to sdk folder
55
- sdk_folder = os .path .relpath (script_return , sdk_root )
50
+ def remove_prefix (text , prefix ):
51
+ if text .startswith (prefix ):
52
+ return text [len (prefix ):]
53
+ return text
54
+
55
+ def find_sdk_folder ():
56
+ cmd = ['git' , 'add' , '.' ]
57
+ check_call (cmd , sdk_root )
58
+
59
+ cmd = ['git' , 'status' , '--porcelain' , '**/tsp-location.yaml' ]
60
+ logging .info ('Command line: ' + ' ' .join (cmd ))
61
+ output = subprocess .check_output (cmd , cwd = sdk_root )
62
+ output_str = str (output , 'utf-8' )
63
+ git_items = output_str .splitlines ()
64
+ sdk_folder = None
65
+ if len (git_items ) > 0 :
66
+ tsp_location_item : str = git_items [0 ]
67
+ sdk_folder = tsp_location_item [1 :].strip ()[0 :- len ('/tsp-location.yaml' )]
68
+
69
+ cmd = ['git' , 'reset' , '.' ]
70
+ check_call (cmd , sdk_root )
71
+
72
+ return sdk_folder
73
+
74
+ repo = remove_prefix (repo_url , 'https://github.com/' )
75
+ cmd = ['npx' , 'tsp-client' , 'init' , '--debug' , '--tsp-config' , tsp_dir , '--commit' , head_sha , '--repo' , repo ]
76
+ check_call (cmd , sdk_root )
77
+
78
+ sdk_folder = find_sdk_folder ()
56
79
logging .info ('SDK folder: ' + sdk_folder )
57
- succeeded = True
80
+ if sdk_folder :
81
+ succeeded = True
58
82
except subprocess .CalledProcessError as error :
59
- logging .error (f'TypeSpec-Project-Process.ps1 fail: { error } ' )
83
+ logging .error (f'tsp-client init fail: { error } ' )
60
84
61
85
if succeeded :
62
86
# check require_sdk_integration
0 commit comments