Skip to content

Commit

Permalink
feat(ci): add parent_branch.txt, make sure it's on the merge path (#3564
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dorimedini-starkware authored Jan 22, 2025
1 parent 4ff8aa6 commit f5661b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/merge_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
27 changes: 22 additions & 5 deletions scripts/merge_paths_test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
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 (
oldest_branch not in merge_paths.values()
), 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}."
Expand All @@ -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})."
)
1 change: 1 addition & 0 deletions scripts/parent_branch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main

0 comments on commit f5661b7

Please sign in to comment.