| 1 | """ |
| 2 | Check whether there are any breaking changes in the PRs between the base and head commits. |
| 3 | If there are, assert that we have incremented the minor version. |
| 4 | """ |
| 5 | import argparse |
| 6 | import os |
| 7 | from packaging.version import parse |
| 8 | |
| 9 | from github import Github |
| 10 | |
| 11 | if __name__ == "__main__": |
| 12 | parser = argparse.ArgumentParser() |
| 13 | parser.add_argument("base") |
| 14 | parser.add_argument("head") |
| 15 | parser.add_argument("last_stable_version") |
| 16 | parser.add_argument("current_version") |
| 17 | args = parser.parse_args() |
| 18 | |
| 19 | repo = Github(os.environ["GITHUB_TOKEN"]).get_repo(os.environ["GITHUB_REPOSITORY"]) |
| 20 | commits = repo.compare(args.base, args.head).commits |
| 21 | prs = (pr for commit in commits for pr in commit.get_pulls()) |
| 22 | |
| 23 | for pr in prs: |
| 24 | if any(label.name == "breaking-change" for label in pr.labels): |
| 25 | print(f"Breaking change in PR: {pr.html_url}") |
| 26 | break |
| 27 | else: |
| 28 | print("No breaking changes found.") |
| 29 | exit(0) |
| 30 | |
| 31 | last_stable_version = parse(args.last_stable_version) |
| 32 | current_version = parse(args.current_version) |
| 33 | if current_version.minor <= last_stable_version.minor: |
| 34 | print("Minor version is not greater than the last stable version.") |
| 35 | exit(1) |