Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eng, sdk automation, migrate to tsp-client 0.7.0+ #39829

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eng/mgmt/automation/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
50 changes: 40 additions & 10 deletions eng/mgmt/automation/generate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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]
Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--local-spec-repo is the new feature of tsp-client 0.7.0 on init action

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
Expand All @@ -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)
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
13 changes: 9 additions & 4 deletions eng/mgmt/automation/init.sh
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +4 to +6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2>&1 is not related to tsp-client
It is an improvement to SDK automation output, to avoid irrelevant info get printed to error message.


# 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
EOF