diff --git a/eng/mgmt/automation/generate.py b/eng/mgmt/automation/generate.py index fcba16e1ed25b..1c46b9d0c1dcd 100755 --- a/eng/mgmt/automation/generate.py +++ b/eng/mgmt/automation/generate.py @@ -225,6 +225,7 @@ def sdk_automation_typespec(config: dict) -> List[dict]: return packages + def sdk_automation_typespec_project(tsp_project: str, config: dict) -> dict: # TODO(xiaofei) support changelog, etc @@ -281,6 +282,7 @@ def sdk_automation_typespec_project(tsp_project: str, config: dict) -> dict: 'result': 'failed', } + def main(): (parser, args) = parse_args() args = vars(args) diff --git a/eng/mgmt/automation/generate_utils.py b/eng/mgmt/automation/generate_utils.py index 456b8e6aceeab..dbe85545562e1 100644 --- a/eng/mgmt/automation/generate_utils.py +++ b/eng/mgmt/automation/generate_utils.py @@ -10,7 +10,7 @@ import tempfile import subprocess import urllib.parse -from typing import Tuple, List +from typing import Tuple, List, Union pwd = os.getcwd() #os.chdir(os.path.abspath(os.path.dirname(sys.argv[0]))) @@ -208,7 +208,7 @@ def compare_with_maven_package(sdk_root: str, service: str, stable_version: str, def get_version( sdk_root: str, module: str, -) -> str: +) -> Union[str, None]: version_file = os.path.join(sdk_root, 'eng/versioning/version_client.txt') project = '{0}:{1}'.format(GROUP_ID, module) @@ -310,17 +310,20 @@ def generate_typespec_project(tsp_project: str, sdk_root: str, spec_root: str, h tsp_dir = os.path.join(spec_root, tsp_project) 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) + repo = remove_prefix(repo_url, 'https://github.com/') + cmd = ['npx', 'tsp-client', 'init', '--debug', + '--tsp-config', tsp_dir, + '--commit', head_sha, + '--repo', repo, + '--local-spec-repo', tsp_dir] + check_call(cmd, sdk_root) + + sdk_folder = find_sdk_folder(sdk_root) logging.info('SDK folder: ' + sdk_folder) 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 @@ -343,6 +346,33 @@ def generate_typespec_project(tsp_project: str, sdk_root: str, spec_root: str, h return succeeded, require_sdk_integration, sdk_folder, service, module + def check_call(cmd: List[str], work_dir: str): logging.info('Command line: ' + ' '.join(cmd)) - subprocess.check_call(cmd, cwd=work_dir) \ No newline at end of file + subprocess.check_call(cmd, cwd=work_dir) + + +def remove_prefix(text, prefix): + if text.startswith(prefix): + return text[len(prefix):] + return text + + +def find_sdk_folder(sdk_root: str): + 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 diff --git a/eng/mgmt/automation/init.sh b/eng/mgmt/automation/init.sh index 3a8d38ee0c15c..8cc167905e1cb 100755 --- a/eng/mgmt/automation/init.sh +++ b/eng/mgmt/automation/init.sh @@ -1,9 +1,14 @@ #!/bin/sh -sudo apt-get install -y --upgrade python3-pip python3-setuptools -pip3 install --upgrade wheel -pip3 install --upgrade PyYAML requests +echo Install Python +sudo apt-get install -y --upgrade python3-pip python3-setuptools 2>&1 +pip3 install --upgrade wheel 2>&1 +pip3 install --upgrade PyYAML requests 2>&1 + +# install tsp-client globally (local install may interfere with tooling) +echo Install tsp-client +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 \ No newline at end of file +EOF