Skip to content

Commit a1ce417

Browse files
authored
[SDK generation pipeline] Breaking detector adoption (#36601)
* optimize changelog output * open breaking change detection for mgmt sdk * adopt breaking change detector * format * update * update * update * update for requirements * Update package_utils.py
1 parent 5b171c8 commit a1ce417

File tree

5 files changed

+63
-16
lines changed

5 files changed

+63
-16
lines changed

scripts/auto_release/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def create_pr_proc(self):
490490
pr_body = "" if not self.check_package_size_result else "{}\n".format("\n".join(self.check_package_size_result))
491491
pr_body = pr_body + "{} \n{} \n{}".format(self.issue_link, self.test_result, self.pipeline_link)
492492
if not self.is_single_path:
493-
pr_body += f'\nBuildTargetingString\n {self.whole_package_name}\nSkip.CreateApiReview\ntrue'
493+
pr_body += f'\nBuildTargetingString\n {self.whole_package_name}\nSkip.CreateApiReview\ntrue\nSkip.BreakingChanges\ntrue'
494494
res_create = api.pulls.create(pr_title, pr_head, pr_base, pr_body)
495495

496496
# Add issue link on PR

scripts/auto_release/requirement.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ ghapi==0.1.19
44
PyGithub==1.55
55
packaging==23.1
66
pytest==6.2.5
7-
fastcore==1.3.25
7+
fastcore==1.3.25
8+
tox==4.5.0

scripts/breaking_changes_checker/breaking_changes_allowlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# --------------------------------------------------------------------------------------------
77

88

9-
RUN_BREAKING_CHANGES_PACKAGES = []
9+
RUN_BREAKING_CHANGES_PACKAGES = ["azure-mgmt-*"]
1010

1111

1212
# See Readme for ignore format

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

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import os
2+
from typing import Optional
13
from pathlib import Path
2-
3-
from subprocess import check_call
4+
import logging
5+
from subprocess import check_call, check_output, CalledProcessError
46

57
from .change_log import main as change_log_main
68

79
DEFAULT_DEST_FOLDER = "./dist"
810

11+
_LOGGER = logging.getLogger(__name__)
12+
13+
914
# prefolder: "sdk/compute"; name: "azure-mgmt-compute"
1015
def create_package(prefolder, name, dest_folder=DEFAULT_DEST_FOLDER):
1116
absdirpath = Path(prefolder, name).absolute()
@@ -16,7 +21,26 @@ def create_package(prefolder, name, dest_folder=DEFAULT_DEST_FOLDER):
1621
)
1722

1823

19-
def change_log_generate(package_name, last_version, tag_is_stable: bool = False):
24+
def change_log_new(package_folder: str, lastest_pypi_version: bool) -> str:
25+
cmd = "tox run -c ../../../eng/tox/tox.ini --root . -e breaking -- --changelog "
26+
if lastest_pypi_version:
27+
cmd += "--latest-pypi-version"
28+
try:
29+
output = check_output(cmd, cwd=package_folder, shell=True)
30+
except CalledProcessError as e:
31+
_LOGGER.warning(f"Failed to generate sdk from typespec: {e.output.decode('utf-8')}")
32+
raise e
33+
result = [l for l in output.decode("utf-8").split(os.linesep)]
34+
begin = result.index("===== changelog start =====")
35+
end = result.index("===== changelog end =====")
36+
if begin == -1 or end == -1:
37+
warn_info = "Failed to get changelog from breaking change detector"
38+
_LOGGER.warning(warn_info)
39+
raise Exception(warn_info)
40+
return "\n".join(result[begin + 1 : end]).strip()
41+
42+
43+
def change_log_generate(package_name, last_version, tag_is_stable: bool = False, *, prefolder: Optional[str] = None):
2044
from pypi_tools.pypi import PyPIClient
2145

2246
client = PyPIClient()
@@ -31,15 +55,27 @@ def change_log_generate(package_name, last_version, tag_is_stable: bool = False)
3155
last_version[-1] = str(last_release)
3256
except:
3357
return "### Other Changes\n\n - Initial version"
34-
else:
35-
return change_log_main(f"{package_name}:pypi", f"{package_name}:latest", tag_is_stable)
58+
59+
# try new changelog tool
60+
if prefolder:
61+
try:
62+
return change_log_new(str(Path(prefolder) / package_name), not (last_stable_release and tag_is_stable))
63+
except Exception as e:
64+
_LOGGER.warning(f"Failed to generate changelog with breaking_change_detector: {e}")
65+
66+
# fallback to old changelog tool
67+
_LOGGER.info("Fallback to old changelog tool")
68+
return change_log_main(f"{package_name}:pypi", f"{package_name}:latest", tag_is_stable)
3669

3770

3871
def extract_breaking_change(changelog):
3972
log = changelog.split("\n")
4073
breaking_change = []
41-
for i in range(0, len(log)):
42-
if log[i].find("Breaking Changes") > -1:
43-
breaking_change = log[min(i + 2, len(log) - 1) :]
44-
break
74+
idx = log.index("### Breaking Changes")
75+
if idx > -1:
76+
for i in range(idx + 1, len(log)):
77+
if log[i].find("###") > -1:
78+
break
79+
if log[i]:
80+
breaking_change.append(log[i])
4581
return sorted([x.replace(" - ", "") for x in breaking_change])

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def main(generate_input, generate_output):
2424
last_version = ["first release"]
2525
if "azure-mgmt-" in package_name:
2626
try:
27-
md_output = change_log_generate(package_name, last_version, package["tagIsStable"])
27+
md_output = change_log_generate(package_name, last_version, package["tagIsStable"], prefolder=prefolder)
2828
except:
2929
md_output = "change log generation failed!!!"
3030
else:
@@ -47,9 +47,19 @@ def main(generate_input, generate_output):
4747
if "azure-mgmt-" not in package_name:
4848
try:
4949
package_path = Path(sdk_folder, folder_name, package_name)
50-
check_call(["python", "-m" "pip", "install", "-r", "../../../eng/apiview_reqs.txt",
51-
"--index-url=https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi"
52-
"/simple/"], cwd=package_path, timeout=300)
50+
check_call(
51+
[
52+
"python",
53+
"-m" "pip",
54+
"install",
55+
"-r",
56+
"../../../eng/apiview_reqs.txt",
57+
"--index-url=https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi"
58+
"/simple/",
59+
],
60+
cwd=package_path,
61+
timeout=300,
62+
)
5363
check_call(["apistubgen", "--pkg-path", "."], cwd=package_path, timeout=600)
5464
for file in os.listdir(package_path):
5565
if "_python.json" in file and package_name in file:

0 commit comments

Comments
 (0)