mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
block-ci: refuse host files in a labelled PR outside the allow list
Host paths went through the module allow list, where "*_test.go", "*.md" and "docs/*" also match root files, so a labelled PR changing weed/example_test.go or README.md passed. List host changes separately and fail on any of them; the module list still runs. The port test now runs the step in a scratch repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27f97dd6d1
commit
7c31672e4a
2 files changed
+40
-7
No files matched your search
@@ -50,7 +50,36 @@ class PortTests(unittest.TestCase):
|
||||
self.assertNotRegex(test, r"if: matrix\.suite == 'process'\s*\n")
|
||||
post = (ROOT / ".github/workflows/block-post-merge-review.yml").read_text()
|
||||
self.assertIn("working-directory: ${{ github.workspace }}", post)
|
||||
self.assertIn("""git -C .. diff -z --name-status --no-renames "$BASE...$HEAD" -- . ':(exclude)seaweed-block/'""", post)
|
||||
|
||||
def test_labelled_post_merge_review_refuses_host_files(self):
|
||||
post = (ROOT / ".github/workflows/block-post-merge-review.yml").read_text()
|
||||
step = post.split(" - name: Check changed paths\n", 1)[1].split(" run: |\n", 1)[1].split("\n\n - name:", 1)[0]
|
||||
script = "\n".join(line[10:] for line in step.splitlines())
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp); module = root / "seaweed-block"
|
||||
def git(*args): return subprocess.check_output(["git", *args], cwd=root, timeout=15)
|
||||
git("init", "-b", "master"); git("config", "user.name", "Example"); git("config", "user.email", "example@example.invalid"); git("config", "commit.gpgsign", "false")
|
||||
for name in ("post-merge-review-check.sh", "post-merge-review-allow.txt"):
|
||||
source = ROOT / "seaweed-block/.github" / ("scripts/" + name if name.endswith(".sh") else name)
|
||||
target = module / ".github" / ("scripts/" + name if name.endswith(".sh") else name)
|
||||
target.parent.mkdir(parents=True, exist_ok=True); target.write_bytes(source.read_bytes())
|
||||
(module / ".github/scripts/post-merge-review-check-test.sh").write_text("exit 0\n")
|
||||
(root / ".github/block/scripts").mkdir(parents=True)
|
||||
(root / ".github/block/scripts/post-merge-review-changed.sh").write_bytes((HERE / "post-merge-review-changed.sh").read_bytes())
|
||||
git("add", "."); git("commit", "-m", "base"); git("remote", "add", "origin", str(root))
|
||||
base = git("rev-parse", "HEAD").decode().strip()
|
||||
def check(*paths):
|
||||
git("reset", "-q", "--hard", base)
|
||||
for path in paths: (root / path).parent.mkdir(parents=True, exist_ok=True); (root / path).write_text("changed\n")
|
||||
git("add", "--", *paths); git("commit", "-m", "change")
|
||||
git("update-ref", "refs/pull/1/head", "HEAD")
|
||||
env = dict(os.environ, BASE=base, HEAD=git("rev-parse", "HEAD").decode().strip(), PR="1")
|
||||
return subprocess.run(["bash", "-eo", "pipefail", "-c", script], cwd=module, env=env, capture_output=True, timeout=30)
|
||||
self.assertEqual(check("seaweed-block/docs/a.md").returncode, 0)
|
||||
for host in ("weed/example_test.go", "README.md", "docs/a.md"):
|
||||
out = check("seaweed-block/docs/a.md", host)
|
||||
self.assertEqual(out.returncode, 1, out)
|
||||
self.assertEqual([l for l in out.stdout.splitlines() if l.startswith(b"DENY")], [b"DENY host " + host.encode() + b" (outside seaweed-block)"])
|
||||
|
||||
def test_known_bugs_use_the_module_verdict_helper(self):
|
||||
text = (ROOT / ".github/workflows/block-known-bugs.yml").read_text()
|
||||
|
||||
Reference in new issue
Block a user