mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
fix(block-ci): refuse ambiguous merge bases in readiness checks
This commit is contained in:
1 parent
c06afc5a26
commit
2c8d8d3a14
2 files changed
+31
-1
No files matched your search
@@ -286,6 +286,33 @@ class PortTests(unittest.TestCase):
|
||||
check.local_checks({"number": 1, "body": "body", "title": "title", "head": {"sha": "head"}}, "base")
|
||||
self.assertEqual(run.call_count, 1) # fetch only; no checker certification
|
||||
|
||||
def test_control_path_diff_refuses_multiple_merge_bases(self):
|
||||
spec = importlib.util.spec_from_file_location("safe_merge", HERE / "safe-merge-check.py")
|
||||
check = importlib.util.module_from_spec(spec); spec.loader.exec_module(check)
|
||||
real_output = subprocess.check_output
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
def git(*args): return real_output(["git", *args], cwd=root, timeout=15).decode().strip()
|
||||
git("init", "-b", "master")
|
||||
git("config", "user.name", "Example"); git("config", "user.email", "example@example.invalid")
|
||||
git("config", "commit.gpgsign", "false")
|
||||
git("commit", "--allow-empty", "-m", "base"); base = git("rev-parse", "HEAD")
|
||||
git("checkout", "-q", "-b", "left")
|
||||
(root / "left.txt").write_text("left")
|
||||
git("add", "."); git("commit", "-m", "left"); left = git("rev-parse", "HEAD")
|
||||
git("checkout", "-q", "-b", "right", base)
|
||||
(root / "right.txt").write_text("right")
|
||||
git("add", "."); git("commit", "-m", "right"); right = git("rev-parse", "HEAD")
|
||||
git("checkout", "-q", "left"); git("merge", "--no-ff", right, "-m", "left merge")
|
||||
left_merge = git("rev-parse", "HEAD")
|
||||
git("checkout", "-q", "right"); git("merge", "--no-ff", left, "-m", "right merge")
|
||||
right_merge = git("rev-parse", "HEAD")
|
||||
self.assertEqual(set(git("merge-base", "--all", left_merge, right_merge).splitlines()), {left, right})
|
||||
with patch.object(check.subprocess, "check_output", side_effect=lambda args, **kw: real_output(args, cwd=root, **kw)):
|
||||
with self.assertRaisesRegex(ValueError, "ambiguous_merge_base"):
|
||||
check.check_control_paths(left_merge, right_merge)
|
||||
check.check_control_paths(left, left_merge)
|
||||
|
||||
def test_fork_runner_guard_is_required_not_only_the_fallback(self):
|
||||
expected = "${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository) && vars.BLOCK_RUNNER_LABEL || 'ubuntu-latest' }}"
|
||||
for name in ("test", "spec-trace", "known-bugs"):
|
||||
|
||||
@@ -48,7 +48,10 @@ def check_control_paths(base, head):
|
||||
# need independent workflow review; their own Actions results cannot waive it.
|
||||
# Diff from the merge base: master's later control changes are not the PR's,
|
||||
# and the tested merge commit already ran them.
|
||||
paths = subprocess.check_output(["git", "diff", "--no-renames", "--name-only", "-z", base + "..." + head]).split(b"\0")
|
||||
bases = subprocess.check_output(["git", "merge-base", "--all", base, head]).decode("ascii").splitlines()
|
||||
if len(bases) != 1:
|
||||
raise ValueError("ambiguous_merge_base: expected exactly one merge base")
|
||||
paths = subprocess.check_output(["git", "diff", "--no-renames", "--name-only", "-z", bases[0], head]).split(b"\0")
|
||||
controls = [p.decode("utf-8", errors="replace") for p in paths if p.startswith((b".github/workflows/", b".github/block/", b".github/dockerfiles/block-", b"seaweed-block/.github/"))]
|
||||
if controls:
|
||||
raise ValueError("workflow_review_required: CI controls changed: " + ", ".join(controls))
|
||||
|
||||
Reference in new issue
Block a user