Skip to content

Commit

Permalink
eng, migrate sdk automation to tsp-client (Azure#38563)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Feb 7, 2024
1 parent 3da3581 commit adbd86a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
44 changes: 34 additions & 10 deletions eng/mgmt/automation/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def sdk_automation_typespec(config: dict) -> List[dict]:
if 'relatedTypeSpecProjectFolder' not in config:
return packages

head_sha = config['headSha']
repo_url = config['repoHttpsUrl']
head_sha: str = config['headSha']
repo_url: str = config['repoHttpsUrl']

tsp_projects = config['relatedTypeSpecProjectFolder']
if isinstance(tsp_projects, str):
Expand All @@ -47,16 +47,40 @@ def sdk_automation_typespec(config: dict) -> List[dict]:
service = None
module = None
try:
cmd = ['pwsh', './eng/common/scripts/TypeSpec-Project-Process.ps1', tsp_dir, head_sha, repo_url]
logging.info('Command line: ' + ' '.join(cmd))
output = subprocess.check_output(cmd, cwd=sdk_root)
output_str = str(output, 'utf-8')
script_return = output_str.splitlines()[-1] # the path to sdk folder
sdk_folder = os.path.relpath(script_return, sdk_root)
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text

def find_sdk_folder():
cmd = ['git', 'add', '.']
check_call(cmd, sdk_root)

cmd = ['git', 'status', '--porcelain', '**/tsp-location.yaml']
logging.info('Command line: ' + ' '.join(cmd))
output = subprocess.check_output(cmd, cwd=sdk_root)
output_str = str(output, 'utf-8')
git_items = output_str.splitlines()
sdk_folder = None
if len(git_items) > 0:
tsp_location_item: str = git_items[0]
sdk_folder = tsp_location_item[1:].strip()[0:-len('/tsp-location.yaml')]

cmd = ['git', 'reset', '.']
check_call(cmd, sdk_root)

return sdk_folder

repo = remove_prefix(repo_url, 'https://github.com/')
cmd = ['npx', 'tsp-client', 'init', '--debug', '--tsp-config', tsp_dir, '--commit', head_sha, '--repo', repo]
check_call(cmd, sdk_root)

sdk_folder = find_sdk_folder()
logging.info('SDK folder: ' + sdk_folder)
succeeded = True
if sdk_folder:
succeeded = True
except subprocess.CalledProcessError as error:
logging.error(f'TypeSpec-Project-Process.ps1 fail: {error}')
logging.error(f'tsp-client init fail: {error}')

if succeeded:
# check require_sdk_integration
Expand Down
3 changes: 3 additions & 0 deletions eng/mgmt/automation/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export NVM_DIR="$HOME/.nvm"
nvm install v18.15.0
nvm alias default node

# install tsp-client globally (local install may interfere with tooling)
npm install -g @azure-tools/typespec-client-generator-cli

cat << EOF > $2
{"envs": {"PATH": "$JAVA_HOME_11_X64/bin:$PATH", "JAVA_HOME": "$JAVA_HOME_11_X64"}}
EOF

0 comments on commit adbd86a

Please sign in to comment.