From eff6818ed9835f3eb6d1cd2df47160e7e68a831b Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 22 Apr 2024 13:21:32 +0800 Subject: [PATCH 1/6] install tsp-client --- eng/mgmt/automation/sdk_init.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eng/mgmt/automation/sdk_init.sh b/eng/mgmt/automation/sdk_init.sh index 439e6d7761a8e..3b21d84cf1c8e 100755 --- a/eng/mgmt/automation/sdk_init.sh +++ b/eng/mgmt/automation/sdk_init.sh @@ -3,6 +3,9 @@ apt-get install python3.8 apt-get install -y --upgrade python3-pip python3-setuptools +# install tsp-client globally (local install may interfere with tooling) +npm install -g @azure-tools/typespec-client-generator-cli + cat << EOF > $1 {} EOF From b3b794187ebaac027b4e5e1e7fe701f3bbedca20 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 22 Apr 2024 13:30:20 +0800 Subject: [PATCH 2/6] print apt-get stderr to stdout --- eng/mgmt/automation/sdk_init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/mgmt/automation/sdk_init.sh b/eng/mgmt/automation/sdk_init.sh index 3b21d84cf1c8e..49b427bc61d82 100755 --- a/eng/mgmt/automation/sdk_init.sh +++ b/eng/mgmt/automation/sdk_init.sh @@ -1,7 +1,7 @@ #!/bin/sh -apt-get install python3.8 -apt-get install -y --upgrade python3-pip python3-setuptools +apt-get install python3.8 2>&1 +apt-get install -y --upgrade python3-pip python3-setuptools 2>&1 # install tsp-client globally (local install may interfere with tooling) npm install -g @azure-tools/typespec-client-generator-cli From b092c73448737d698884e5d4980c616e8caa8128 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 22 Apr 2024 13:45:55 +0800 Subject: [PATCH 3/6] tsp-client --- eng/mgmt/automation/generate.py | 2 ++ eng/mgmt/automation/generate_utils.py | 46 ++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 8 deletions(-) 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..beda297234296 100644 --- a/eng/mgmt/automation/generate_utils.py +++ b/eng/mgmt/automation/generate_utils.py @@ -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() 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 From 93386f8ee176240733661557a8aa55b2692101be Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 22 Apr 2024 14:25:23 +0800 Subject: [PATCH 4/6] log in init.sh --- eng/mgmt/automation/sdk_init.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eng/mgmt/automation/sdk_init.sh b/eng/mgmt/automation/sdk_init.sh index 49b427bc61d82..f5651208ea31f 100755 --- a/eng/mgmt/automation/sdk_init.sh +++ b/eng/mgmt/automation/sdk_init.sh @@ -1,9 +1,11 @@ #!/bin/sh +echo Install Python apt-get install python3.8 2>&1 apt-get install -y --upgrade python3-pip python3-setuptools 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 > $1 From e24cdf4aecda37f931491335c2f5158105812c83 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 22 Apr 2024 14:39:31 +0800 Subject: [PATCH 5/6] update init.sh --- eng/mgmt/automation/init.sh | 13 +++++++++---- eng/mgmt/automation/sdk_init.sh | 9 ++------- 2 files changed, 11 insertions(+), 11 deletions(-) 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 diff --git a/eng/mgmt/automation/sdk_init.sh b/eng/mgmt/automation/sdk_init.sh index f5651208ea31f..439e6d7761a8e 100755 --- a/eng/mgmt/automation/sdk_init.sh +++ b/eng/mgmt/automation/sdk_init.sh @@ -1,12 +1,7 @@ #!/bin/sh -echo Install Python -apt-get install python3.8 2>&1 -apt-get install -y --upgrade python3-pip python3-setuptools 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 +apt-get install python3.8 +apt-get install -y --upgrade python3-pip python3-setuptools cat << EOF > $1 {} From 89d4633191a34c3b0ec53d15a8a1ed67c29969a1 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 22 Apr 2024 14:50:10 +0800 Subject: [PATCH 6/6] fix --- eng/mgmt/automation/generate_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/mgmt/automation/generate_utils.py b/eng/mgmt/automation/generate_utils.py index beda297234296..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) @@ -318,7 +318,7 @@ def generate_typespec_project(tsp_project: str, sdk_root: str, spec_root: str, h '--local-spec-repo', tsp_dir] check_call(cmd, sdk_root) - sdk_folder = find_sdk_folder() + sdk_folder = find_sdk_folder(sdk_root) logging.info('SDK folder: ' + sdk_folder) if sdk_folder: succeeded = True