From f5661b73d9f21c4073818d550e19f8ed5286fdaa Mon Sep 17 00:00:00 2001 From: dorimedini-starkware Date: Wed, 22 Jan 2025 09:44:50 +0200 Subject: [PATCH] feat(ci): add parent_branch.txt, make sure it's on the merge path (#3564) --- scripts/merge_branches.py | 2 +- scripts/merge_paths_test.py | 27 ++++++++++++++++++++++----- scripts/parent_branch.txt | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 scripts/parent_branch.txt diff --git a/scripts/merge_branches.py b/scripts/merge_branches.py index 7c43f477dc..40d592fd1b 100755 --- a/scripts/merge_branches.py +++ b/scripts/merge_branches.py @@ -17,7 +17,7 @@ FINAL_BRANCH = "main" MERGE_PATHS_FILE = "scripts/merge_paths.json" -FILES_TO_PRESERVE = {"rust-toolchain.toml"} +FILES_TO_PRESERVE = {"rust-toolchain.toml", "scripts/parent_branch.txt"} def load_merge_paths() -> Dict[str, str]: diff --git a/scripts/merge_paths_test.py b/scripts/merge_paths_test.py index 3b083904cb..e98272b6f9 100755 --- a/scripts/merge_paths_test.py +++ b/scripts/merge_paths_test.py @@ -1,9 +1,20 @@ +import pytest +from typing import Dict + from merge_branches import FINAL_BRANCH, MERGE_PATHS_FILE, load_merge_paths -def test_linear_path(): - merge_paths = load_merge_paths() +@pytest.fixture +def parent_branch() -> str: + return open("scripts/parent_branch.txt").read().strip() + + +@pytest.fixture +def merge_paths() -> Dict[str, str]: + return load_merge_paths() + +def test_linear_path(merge_paths: Dict[str, str]): src_dst_iter = iter(merge_paths.items()) (oldest_branch, prev_dst_branch) = next(src_dst_iter) assert ( @@ -11,9 +22,7 @@ def test_linear_path(): ), f"Oldest branch '{oldest_branch}' cannot be a destination branch." for src_branch, dst_branch in src_dst_iter: - assert ( - prev_dst_branch == src_branch - ), ( + assert prev_dst_branch == src_branch, ( f"Since the merge graph is linear, the source branch '{src_branch}' must be the same " f"as the previous destination branch, which is '{prev_dst_branch}'. Check out " f"{MERGE_PATHS_FILE}." @@ -23,3 +32,11 @@ def test_linear_path(): assert ( prev_dst_branch == FINAL_BRANCH ), f"The last destination is '{prev_dst_branch}' but must be '{FINAL_BRANCH}'." + + +def test_parent_branch_is_on_path(parent_branch: str, merge_paths: Dict[str, str]): + known_branches = set(merge_paths.keys()) | set(merge_paths.values()) + assert parent_branch in known_branches, ( + f"Parent branch '{parent_branch}' is not on the merge path (branches in merge path: " + f"{known_branches})." + ) diff --git a/scripts/parent_branch.txt b/scripts/parent_branch.txt new file mode 100644 index 0000000000..ba2906d066 --- /dev/null +++ b/scripts/parent_branch.txt @@ -0,0 +1 @@ +main