Skip to content

Commit 7a0b870

Browse files
migrate to tsp-client
1 parent ded3b68 commit 7a0b870

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

eng/mgmt/automation/generate_data.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def sdk_automation_typespec(config: dict) -> List[dict]:
3232
if 'relatedTypeSpecProjectFolder' not in config:
3333
return packages
3434

35-
head_sha = config['headSha']
36-
repo_url = config['repoHttpsUrl']
35+
head_sha: str = config['headSha']
36+
repo_url: str = config['repoHttpsUrl']
3737

3838
tsp_projects = config['relatedTypeSpecProjectFolder']
3939
if isinstance(tsp_projects, str):
@@ -47,16 +47,40 @@ def sdk_automation_typespec(config: dict) -> List[dict]:
4747
service = None
4848
module = None
4949
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()
5679
logging.info('SDK folder: ' + sdk_folder)
57-
succeeded = True
80+
if sdk_folder:
81+
succeeded = True
5882
except subprocess.CalledProcessError as error:
59-
logging.error(f'TypeSpec-Project-Process.ps1 fail: {error}')
83+
logging.error(f'tsp-client init fail: {error}')
6084

6185
if succeeded:
6286
# check require_sdk_integration

eng/mgmt/automation/init.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export NVM_DIR="$HOME/.nvm"
1010
nvm install v18.15.0
1111
nvm alias default node
1212

13+
npm install -g @azure-tools/typespec-client-generator-cli
14+
1315
cat << EOF > $2
1416
{"envs": {"PATH": "$JAVA_HOME_11_X64/bin:$PATH", "JAVA_HOME": "$JAVA_HOME_11_X64"}}
1517
EOF

0 commit comments

Comments
 (0)