Skip to content

Commit f1ab55e

Browse files
eng, SDK automation, truncate service length to max 32 (Azure#45209)
1 parent 211b1bd commit f1ab55e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

eng/automation/generate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def parse_args() -> (argparse.ArgumentParser, argparse.Namespace):
108108

109109

110110
def sdk_automation(input_file: str, output_file: str):
111+
# this function is for SDK automation from CI in specs or "spec-gen-sdk - java" pipeline
112+
111113
with open(input_file, "r") as fin:
112114
config = json.load(fin)
113115

@@ -158,7 +160,7 @@ def sdk_automation_autorest(config: dict) -> List[dict]:
158160
else:
159161
spec = match.group(1)
160162
spec = update_spec(spec, match.group(2))
161-
service = get_and_update_service_from_api_specs(api_specs_file, spec)
163+
service = get_and_update_service_from_api_specs(api_specs_file, spec, truncate_service=True)
162164

163165
pre_suffix = SUFFIX
164166
suffix = get_suffix_from_api_specs(api_specs_file, spec)

eng/automation/generate_utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ def get_and_update_service_from_api_specs(
284284
api_specs_file: str,
285285
spec: str,
286286
service: str = None,
287+
truncate_service: bool = False,
287288
):
288-
SPECIAL_SPEC = {"resources"}
289-
if spec in SPECIAL_SPEC:
289+
special_spec = {"resources"}
290+
if spec in special_spec:
290291
if not service:
291292
service = spec
292293
return valid_service(service)
@@ -299,6 +300,15 @@ def get_and_update_service_from_api_specs(
299300
service = api_spec.get("service")
300301
if not service:
301302
service = spec
303+
# remove segment contains ".", e.g. "Microsoft.KubernetesConfiguration", "Astronomer.Astro"
304+
service = re.sub(r"/[^/]+(\.[^/]+)+", "", service)
305+
# truncate length of service to 32, as this is the maximum length for package name in Java repository
306+
if truncate_service:
307+
service = valid_service(service)
308+
max_length = 32
309+
if len(service) > max_length:
310+
logging.warning(f'[VALIDATE] service name truncated from "{service}" to "{service[:max_length]}"')
311+
service = service[:max_length]
302312
service = valid_service(service)
303313

304314
if service != spec:

0 commit comments

Comments
 (0)