Skip to content

Commit 9a32610

Browse files
authored
fix sdk generation (Azure#39569)
* fix sdk generation * fix
1 parent 2313170 commit 9a32610

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

tools/azure-sdk-tools/packaging_tools/package_utils.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import Optional
2+
from typing import Optional, Tuple
33
from pathlib import Path
44
import logging
55
from subprocess import check_call, CalledProcessError, getoutput
@@ -41,42 +41,47 @@ def change_log_new(package_folder: str, lastest_pypi_version: bool) -> str:
4141
return "\n".join(result[begin + 1 : end]).strip()
4242

4343

44-
def change_log_generate(
45-
package_name,
46-
last_version,
47-
tag_is_stable: bool = False,
48-
*,
49-
prefolder: Optional[str] = None,
50-
is_multiapi: bool = False,
51-
):
44+
def get_version_info(package_name: str, tag_is_stable: bool = False) -> Tuple[str, str]:
5245
from pypi_tools.pypi import PyPIClient
5346

54-
client = PyPIClient()
5547
try:
48+
client = PyPIClient()
5649
ordered_versions = client.get_ordered_versions(package_name)
5750
last_release = ordered_versions[-1]
5851
stable_releases = [x for x in ordered_versions if not x.is_prerelease]
59-
last_stable_release = stable_releases[-1] if stable_releases else None
52+
last_stable_release = stable_releases[-1] if stable_releases else ""
6053
if tag_is_stable:
61-
last_version[-1] = str(last_stable_release) if last_stable_release else str(last_release)
54+
last_version = str(last_stable_release) if last_stable_release else str(last_release)
6255
else:
63-
last_version[-1] = str(last_release)
56+
last_version = str(last_release)
6457
except:
65-
return ("### Other Changes\n\n - Initial version", last_version)
58+
last_version = ""
59+
last_stable_release = ""
60+
return last_version, str(last_stable_release)
61+
62+
63+
def change_log_generate(
64+
package_name,
65+
last_version,
66+
tag_is_stable: bool = False,
67+
*,
68+
last_stable_release: Optional[str] = None,
69+
prefolder: Optional[str] = None,
70+
is_multiapi: bool = False,
71+
):
72+
if not last_version:
73+
return "### Other Changes\n\n - Initial version"
6674

6775
# try new changelog tool
6876
if prefolder and not is_multiapi:
6977
try:
70-
return (
71-
change_log_new(str(Path(prefolder) / package_name), not (last_stable_release and tag_is_stable)),
72-
last_version,
73-
)
78+
return change_log_new(str(Path(prefolder) / package_name), not (last_stable_release and tag_is_stable))
7479
except Exception as e:
7580
_LOGGER.warning(f"Failed to generate changelog with breaking_change_detector: {e}")
7681

7782
# fallback to old changelog tool
7883
_LOGGER.info("Fallback to old changelog tool")
79-
return (change_log_main(f"{package_name}:pypi", f"{package_name}:latest", tag_is_stable), last_version)
84+
return change_log_main(f"{package_name}:pypi", f"{package_name}:latest", tag_is_stable)
8085

8186

8287
def extract_breaking_change(changelog):

tools/azure-sdk-tools/packaging_tools/sdk_package.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import multiprocessing
1010
from functools import partial
1111

12-
from .package_utils import create_package, change_log_generate, extract_breaking_change
12+
from .package_utils import create_package, change_log_generate, extract_breaking_change, get_version_info
1313

1414
logging.basicConfig(
1515
stream=sys.stdout,
@@ -35,17 +35,18 @@ def main(generate_input, generate_output):
3535
package_name = package["packageName"]
3636
prefolder = package["path"][0]
3737
# Changelog
38-
last_version = ["first release"]
38+
last_version, last_stable_release = get_version_info(package_name, package["tagIsStable"])
3939
change_log_func = partial(
4040
change_log_generate,
4141
package_name,
4242
last_version,
4343
package["tagIsStable"],
44+
last_stable_release=last_stable_release,
4445
prefolder=prefolder,
4546
is_multiapi=package["isMultiapi"],
4647
)
4748
try:
48-
md_output, last_version = execute_func_with_timeout(change_log_func)
49+
md_output = execute_func_with_timeout(change_log_func)
4950
except multiprocessing.TimeoutError:
5051
md_output = "change log generation was timeout!!!"
5152
except:
@@ -55,7 +56,7 @@ def main(generate_input, generate_output):
5556
"hasBreakingChange": "Breaking Changes" in md_output,
5657
"breakingChangeItems": extract_breaking_change(md_output),
5758
}
58-
package["version"] = last_version[-1]
59+
package["version"] = last_version
5960

6061
_LOGGER.info(f"[PACKAGE]({package_name})[CHANGELOG]:{md_output}")
6162
# Built package

0 commit comments

Comments
 (0)