Skip to content

Commit 62eed3d

Browse files
emdnetoxrmx
andauthored
infra: add griffe to public-symbols check CI (#4633)
* infra: add griffe to public-symbols check CI Signed-off-by: emdneto <[email protected]> * use griffe python api * cleanup --------- Signed-off-by: emdneto <[email protected]> Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent 9ad8269 commit 62eed3d

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

scripts/griffe_check.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import argparse
2+
import sys
3+
4+
import griffe
5+
from eachdist import find_projectroot, find_targets
6+
7+
8+
def get_modules() -> list[str]:
9+
rootpath = find_projectroot()
10+
targets = find_targets("DEFAULT", rootpath)
11+
12+
dirs_to_exclude = [
13+
"docs",
14+
"scripts",
15+
"opentelemetry-docker-tests",
16+
"examples",
17+
"_template",
18+
]
19+
20+
packages = []
21+
for target in targets:
22+
rel_path = target.relative_to(rootpath)
23+
if not any(excluded in str(rel_path) for excluded in dirs_to_exclude):
24+
packages.append(str(rel_path / "src"))
25+
return packages
26+
27+
28+
def main():
29+
parser = argparse.ArgumentParser(
30+
description="Check for breaking changes using griffe",
31+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
32+
)
33+
34+
parser.add_argument(
35+
"--module",
36+
default="opentelemetry",
37+
help="Name of the module to check for breaking changes (e.g., opentelemetry, opentelemetry.sdk, opentelemetry.sdk.resources)",
38+
)
39+
parser.add_argument(
40+
"--against",
41+
default="main",
42+
help="Git ref to compare against (e.g., branch, tag, or commit)",
43+
)
44+
args = parser.parse_args()
45+
46+
modules = get_modules()
47+
base = griffe.load(args.module, search_paths=modules)
48+
against = griffe.load_git(
49+
args.module, ref=args.against, search_paths=modules
50+
)
51+
52+
breakages = list(griffe.find_breaking_changes(against, base))
53+
54+
if breakages:
55+
for b in breakages:
56+
# We can use `b.explain()` to get a detailed explanation of the breaking change
57+
# and we can iterate over breakages to perform more complex logic
58+
# like skipping per object.path or breakage type
59+
print(b.explain())
60+
return 1
61+
return 0
62+
63+
64+
if __name__ == "__main__":
65+
sys.exit(main())

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,14 @@ commands_post =
311311
docker-compose down -v
312312

313313
[testenv:public-symbols-check]
314-
basepython: python3
315314
recreate = True
316315
deps =
317316
GitPython==3.1.40
317+
griffe==1.7.3
318+
toml
318319
commands =
320+
; griffe check before to fail fast if there are any issues
321+
python {toxinidir}/scripts/griffe_check.py
319322
python {toxinidir}/scripts/public_symbols_checker.py
320323

321324
[testenv:generate-workflows]

0 commit comments

Comments
 (0)