Skip to content

Commit 392e0ae

Browse files
[bct] Support regex suppressions (#37196)
* add regex suppressions * clean up ignore logic * pass ignores at tracker start up * add ListResult suppression * fix model, add test * update allowlist --------- Co-authored-by: Catalina Peralta <[email protected]>
1 parent e964d98 commit 392e0ae

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

scripts/breaking_changes_checker/_models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Licensed under the MIT License. See License.txt in the project root for license information.
66
# --------------------------------------------------------------------------------------------
77

8+
import re
89
from typing import List, Optional, NamedTuple, Protocol, runtime_checkable, Union
910

1011
class BreakingChange(NamedTuple):
@@ -22,6 +23,15 @@ class Suppression(NamedTuple):
2223
function_name: Optional[str] = None
2324
parameter_or_property_name: Optional[str] = None
2425

26+
class RegexSuppression:
27+
value: str
28+
29+
def __init__(self, value: str):
30+
self.value = value
31+
32+
def match(self, compare_value: str) -> bool:
33+
return True if re.fullmatch(self.value, compare_value) else False
34+
2535
@runtime_checkable
2636
class ChangesChecker(Protocol):
2737
name: str

scripts/breaking_changes_checker/breaking_changes_allowlist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Licensed under the MIT License. See License.txt in the project root for license information.
66
# --------------------------------------------------------------------------------------------
77

8+
from _models import RegexSuppression
89

910
RUN_BREAKING_CHANGES_PACKAGES = ["azure-mgmt-*", "azure-ai-contentsafety", "azure-ai-vision-face"]
1011

@@ -16,6 +17,7 @@
1617
# Changes due to latest dpg design + need to support overloads in this tool
1718
("ChangedParameterOrdering", "*", "*", "__init__"),
1819
# Changes due to latest dpg design
20+
("RemovedOrRenamedClass", "*", RegexSuppression(".*ListResult$")),
1921
("ChangedParameterKind", "*", "*", "*", "top"),
2022
("ChangedParameterKind", "*", "*", "*", "filter"),
2123
("ChangedParameterKind", "*", "*", "*", "skip"),

scripts/breaking_changes_checker/breaking_changes_tracker.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from enum import Enum
1111
from typing import Any, Dict, List, Union
1212
from copy import deepcopy
13-
from breaking_changes_allowlist import IGNORE_BREAKING_CHANGES
14-
from _models import ChangesChecker, Suppression
13+
from _models import ChangesChecker, Suppression, RegexSuppression
1514

1615

1716
class BreakingChangeType(str, Enum):
@@ -98,7 +97,7 @@ def __init__(self, stable: Dict, current: Dict, package_name: str, **kwargs: Any
9897
self._class_name = None
9998
self._function_name = None
10099
self._parameter_name = None
101-
self.ignore = kwargs.get("ignore", None)
100+
self.ignore = kwargs.get("ignore", {})
102101
checkers: List[ChangesChecker] = kwargs.get("checkers", [])
103102
for checker in checkers:
104103
if not isinstance(checker, ChangesChecker):
@@ -593,6 +592,11 @@ def match(self, bc, ignored):
593592
for b, i in zip(bc, ignored):
594593
if i == "*":
595594
continue
595+
if isinstance(i, RegexSuppression) and b is not None:
596+
if i.match(b):
597+
continue
598+
else:
599+
return False
596600
if b != i:
597601
return False
598602
return True
@@ -625,7 +629,7 @@ def get_reportable_changes(self, ignore_changes: Dict, changes_list: List) -> Li
625629
break
626630

627631
def report_changes(self) -> None:
628-
ignore_changes = self.ignore if self.ignore else IGNORE_BREAKING_CHANGES
632+
ignore_changes = self.ignore if self.ignore else {}
629633
self.get_reportable_changes(ignore_changes, self.breaking_changes)
630634

631635
# If there are no breaking changes after the ignore check, return early

scripts/breaking_changes_checker/changelog_tracker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import Any, Dict
1010
import jsondiff
1111
from breaking_changes_tracker import BreakingChangesTracker
12-
from breaking_changes_allowlist import IGNORE_BREAKING_CHANGES
1312

1413
class ChangeType(str, Enum):
1514
ADDED_CLIENT = "AddedClient"
@@ -177,7 +176,7 @@ def check_non_positional_parameter_added(self, current_parameters_node: Dict) ->
177176

178177

179178
def report_changes(self) -> None:
180-
ignore_changes = self.ignore if self.ignore else IGNORE_BREAKING_CHANGES
179+
ignore_changes = self.ignore if self.ignore else {}
181180
self.get_reportable_changes(ignore_changes, self.breaking_changes)
182181
self.get_reportable_changes(ignore_changes, self.features_added)
183182
# Code borrowed and modified from the previous change log tool

scripts/breaking_changes_checker/detect_breaking_changes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from enum import Enum
2222
from typing import Dict, Union, Type, Callable, Optional
2323
from packaging_tools.venvtools import create_venv_with_package
24-
from breaking_changes_allowlist import RUN_BREAKING_CHANGES_PACKAGES
24+
from breaking_changes_allowlist import RUN_BREAKING_CHANGES_PACKAGES, IGNORE_BREAKING_CHANGES
2525
from breaking_changes_tracker import BreakingChangesTracker
2626
from changelog_tracker import ChangelogTracker
2727
from pathlib import Path
@@ -445,9 +445,15 @@ def test_compare_reports(pkg_dir: str, changelog: bool, source_report: str = "st
445445
stable = report_azure_mgmt_versioned_module(stable)
446446
current = report_azure_mgmt_versioned_module(current)
447447

448-
checker = BreakingChangesTracker(stable, current, package_name, checkers = CHECKERS)
448+
checker = BreakingChangesTracker(
449+
stable,
450+
current,
451+
package_name,
452+
checkers = CHECKERS,
453+
ignore = IGNORE_BREAKING_CHANGES
454+
)
449455
if changelog:
450-
checker = ChangelogTracker(stable, current, package_name, checkers = CHECKERS)
456+
checker = ChangelogTracker(stable, current, package_name, checkers = CHECKERS, ignore = IGNORE_BREAKING_CHANGES)
451457
checker.run_checks()
452458

453459
remove_json_files(pkg_dir)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
# --------------------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
# Licensed under the MIT License. See License.txt in the project root for license information.
6+
# --------------------------------------------------------------------------------------------
7+
8+
from _models import RegexSuppression
9+
10+
def test_regex_suppressions():
11+
regex_suppression = RegexSuppression(".*")
12+
assert regex_suppression.match("some_string") == True
13+
assert regex_suppression.match("another_string") == True
14+
15+
regex_suppression = RegexSuppression(".*ListResult$")
16+
assert regex_suppression.match("FooListResult") == True

0 commit comments

Comments
 (0)