Skip to content

infra: add griffe to public-symbols check CI #4633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions scripts/griffe_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import argparse
import sys

import griffe
from eachdist import find_projectroot, find_targets


def get_modules() -> list[str]:
rootpath = find_projectroot()
targets = find_targets("DEFAULT", rootpath)

dirs_to_exclude = [
"docs",
"scripts",
"opentelemetry-docker-tests",
"examples",
"_template",
]

packages = []
for target in targets:
rel_path = target.relative_to(rootpath)
if not any(excluded in str(rel_path) for excluded in dirs_to_exclude):
packages.append(str(rel_path / "src"))
return packages


def main():
parser = argparse.ArgumentParser(
description="Check for breaking changes using griffe",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

parser.add_argument(
"--module",
default="opentelemetry",
help="Name of the module to check for breaking changes (e.g., opentelemetry, opentelemetry.sdk, opentelemetry.sdk.resources)",
)
parser.add_argument(
"--against",
default="main",
help="Git ref to compare against (e.g., branch, tag, or commit)",
)
args = parser.parse_args()

modules = get_modules()
base = griffe.load(args.module, search_paths=modules)
against = griffe.load_git(
args.module, ref=args.against, search_paths=modules
)

breakages = list(griffe.find_breaking_changes(against, base))

if breakages:
for b in breakages:
# We can use `b.explain()` to get a detailed explanation of the breaking change
# and we can iterate over breakages to perform more complex logic
# like skipping per object.path or breakage type
print(b.explain())
return 1
return 0


if __name__ == "__main__":
sys.exit(main())
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,14 @@ commands_post =
docker-compose down -v

[testenv:public-symbols-check]
basepython: python3
recreate = True
deps =
GitPython==3.1.40
griffe==1.7.3
toml
commands =
; griffe check before to fail fast if there are any issues
python {toxinidir}/scripts/griffe_check.py
python {toxinidir}/scripts/public_symbols_checker.py

[testenv:generate-workflows]
Expand Down