|
| 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()) |
0 commit comments