Skip to content

Commit

Permalink
eng, ignore generated folder in sdk sync, if that folder not in sdk r…
Browse files Browse the repository at this point in the history
…epo (#2413)
  • Loading branch information
weidongxu-microsoft authored Nov 17, 2023
1 parent 2f6fdfb commit b1ca2e6
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions eng/sdk/sync_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import subprocess
import glob
import json
import shutil
from typing import List

sdk_root: str

skip_artifacts: List[str] = ['azure-ai-anomalydetector']
skip_artifacts: List[str] = [
'azure-ai-anomalydetector' # deprecated
]


def parse_args() -> argparse.Namespace:
Expand Down Expand Up @@ -44,26 +47,45 @@ def update_emitter(version: str):
logging.info('Update emitter-package.json to use @azure-tools/typespec-java version %s', version)


def get_generated_folder_from_artifact(module_path: str, type: str, artifact: str) -> str:
path = os.path.join(module_path, 'src', type, 'java', 'com')
for seg in artifact.split('-'):
path = os.path.join(path, seg)
path = os.path.join(path, 'generated')
return path


def update_sdks():
for tsp_location_file in glob.glob(os.path.join(sdk_root, 'sdk/*/*/tsp-location.yaml')):
artifact_path = os.path.dirname(tsp_location_file)
artifact = os.path.basename(artifact_path)
tsp_location_path = os.path.dirname(tsp_location_file)
artifact = os.path.basename(tsp_location_path)

if artifact in skip_artifacts:
continue

module_path = os.path.join(sdk_root, os.path.dirname(tsp_location_path))
generated_samples_path = get_generated_folder_from_artifact(module_path, 'samples', artifact)
generated_test_path = get_generated_folder_from_artifact(module_path, 'test', artifact)
generated_samples_exists = os.path.isdir(generated_samples_path)
generated_test_exists = os.path.isdir(generated_test_path)

logging.info('Generate for module %s', artifact)

cmd = [
'pwsh',
os.path.join(sdk_root, 'eng/common/scripts/TypeSpec-Project-Sync.ps1'),
artifact_path
tsp_location_path
]
subprocess.check_call(cmd, cwd=sdk_root)

cmd[1] = os.path.join(sdk_root, 'eng/common/scripts/TypeSpec-Project-Generate.ps1')
subprocess.check_call(cmd, cwd=sdk_root)

if not generated_samples_exists:
shutil.rmtree(os.path.join(module_path, generated_samples_path), ignore_errors=True)
if not generated_test_exists:
shutil.rmtree(os.path.join(module_path, generated_test_path), ignore_errors=True)

cmd = ['git', 'add', '.']
subprocess.check_call(cmd, cwd=sdk_root)

Expand Down

0 comments on commit b1ca2e6

Please sign in to comment.