Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c57b6b1b69 | ||
|
|
99f8b73654 | ||
|
|
272504eab3 | ||
|
|
fa9f8791bd | ||
|
|
694c28109d | ||
|
|
090ab1f42a | ||
|
|
d6207d60e9 | ||
|
|
6aed7a26c5 | ||
|
|
0190fc7474 |
@@ -4,7 +4,10 @@ from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="immoscout")
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/mcps"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/mcps"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="gmail_mcp",
|
||||
@@ -23,7 +26,7 @@ checkoutMerged = CheckoutMerged(clone,
|
||||
buildDocker = DockerComposeBuild(clone,
|
||||
docker_repo_username="",
|
||||
docker_repo_password="",
|
||||
docker_compose_path="gmail-mcp-server/docker-compose.yml",
|
||||
docker_compose_path="docker-compose.yml",
|
||||
docker_repo_url="https://registry.rudolf.keenetic.link",
|
||||
publish=False,
|
||||
envs=lambda: {
|
||||
@@ -39,7 +42,7 @@ deployDocker = DockerSwarmDeploy(
|
||||
"version": "auto-" + checkoutMerged.progress().version,
|
||||
},
|
||||
stack_name="gmail_mcp",
|
||||
docker_compose_path="gmail-mcp-server/docker-compose.yml",
|
||||
docker_compose_path="docker-compose.yml",
|
||||
)
|
||||
|
||||
checkPing1 = UrlCheck(
|
||||
|
||||
@@ -4,7 +4,28 @@ from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="ansible")
|
||||
# Dual-remote clone for the ansible mirror (the deploy target, not brencher itself).
|
||||
# - gitea_hermes is where the feature branch lives (hermes/ansible:*)
|
||||
# - gitea_admin is the live-deploy source (where brencher-bot reads compose files from)
|
||||
#
|
||||
# Why not github? github.com is unreachable from the brencher container -- the
|
||||
# proxy returns HTTP 403 on CONNECT tunnel, so the URL would always fail to
|
||||
# fetch. See backend/configs/docker_socket_proxy.py for the same migration.
|
||||
#
|
||||
# Why drop branchNamePrefix? GitClone only applies its prefix refspec to a
|
||||
# remote named "origin" (backend/steps/git.py ~L104); neither remote here is
|
||||
# named "origin", so the prefix would be a silent no-op. Both remotes fetch
|
||||
# their full refset instead.
|
||||
#
|
||||
# Why two remotes? The deploy step (DockerSwarmDeploy) checks out a specific
|
||||
# branch and uses the resulting checkout as wd for the compose path. With
|
||||
# gitea_hermes as primary, feature branches opened in the fork are picked up;
|
||||
# gitea_admin provides the live-deploy source as a fallback / for cross-fork
|
||||
# PRs. This matches the form in backend/configs/brencher.py after PR #3.
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/ansible"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/ansible"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="hermes",
|
||||
|
||||
@@ -4,7 +4,28 @@ from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="ansible")
|
||||
# Dual-remote clone for the ansible mirror (the deploy target, not brencher itself).
|
||||
# - gitea_hermes is where the feature branch lives (hermes/ansible:*)
|
||||
# - gitea_admin is the live-deploy source (where brencher-bot reads compose files from)
|
||||
#
|
||||
# Why not github? github.com is unreachable from the brencher container -- the
|
||||
# proxy returns HTTP 403 on CONNECT tunnel, so the URL would always fail to
|
||||
# fetch. See backend/configs/docker_socket_proxy.py for the same migration.
|
||||
#
|
||||
# Why drop branchNamePrefix? GitClone only applies its prefix refspec to a
|
||||
# remote named "origin" (backend/steps/git.py ~L104); neither remote here is
|
||||
# named "origin", so the prefix would be a silent no-op. Both remotes fetch
|
||||
# their full refset instead.
|
||||
#
|
||||
# Why two remotes? The deploy step (DockerSwarmDeploy) checks out a specific
|
||||
# branch and uses the resulting checkout as wd for the compose path. With
|
||||
# gitea_hermes as primary, feature branches opened in the fork are picked up;
|
||||
# gitea_admin provides the live-deploy source as a fallback / for cross-fork
|
||||
# PRs. This matches the form in backend/configs/brencher.py after PR #3.
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/ansible"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/ansible"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="immich",
|
||||
|
||||
+11
-4
@@ -48,8 +48,13 @@ class GitClone(AbstractStep[str]):
|
||||
raise ValueError(f"Remote {name!r} requires a non-empty 'url' (string)")
|
||||
if name in seen:
|
||||
raise ValueError(f"Duplicate remote name: {name!r}")
|
||||
prefix_value = entry.get("prefix")
|
||||
if prefix_value is not None and not isinstance(prefix_value, str):
|
||||
raise ValueError(
|
||||
f"Remote {name!r} 'prefix' must be a string when set, got {type(prefix_value).__name__}"
|
||||
)
|
||||
seen.add(name)
|
||||
normalized.append({"name": name, "url": url_value})
|
||||
normalized.append({"name": name, "url": url_value, "prefix": prefix_value or ""})
|
||||
elif url is not None:
|
||||
if isinstance(url, str):
|
||||
raw = [url]
|
||||
@@ -103,10 +108,12 @@ class GitClone(AbstractStep[str]):
|
||||
remote.set_url(auth_url)
|
||||
else:
|
||||
remote = repo.create_remote(remote_name, auth_url)
|
||||
if remote_name == "origin" and self.branchNamePrefix != "":
|
||||
prefix = entry.get("prefix", "")
|
||||
effective_prefix = prefix or (self.branchNamePrefix if remote_name == "origin" else "")
|
||||
if effective_prefix:
|
||||
with repo.config_writer() as config:
|
||||
config.set_value('remote "origin"', "fetch",
|
||||
f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*")
|
||||
config.set_value(f'remote "{remote_name}"', "fetch",
|
||||
f"+refs/heads/{effective_prefix}/*:refs/remotes/{remote_name}/{effective_prefix}/*")
|
||||
result = remote.fetch(prune=True)
|
||||
if not result or any(fetch_info.flags & fetch_info.ERROR for fetch_info in result):
|
||||
raise BaseException(f"Failed to fetch updates for {repository_url}")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
from enironment import wrap_in_cached, SharedStateConflictError
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
from tests.test_remote_repo import RemoteRepoHelper
|
||||
|
||||
@@ -7,6 +8,24 @@ from tests.test_remote_repo import RemoteRepoHelper
|
||||
class TestCachedEnv:
|
||||
"""Tests for the CachedEnv wrapper around GitEnv."""
|
||||
|
||||
def test_inmemory_state_refreshes_removed_branch(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1", "Initial commit")
|
||||
commit1 = repo_helper.create_commit(repo_helper.repo, "master", "branch1", "file2.txt", "content2", "Branch1 commit")
|
||||
commit2 = repo_helper.create_commit(repo_helper.repo, "master", "branch2", "file3.txt", "content3", "Branch2 commit")
|
||||
|
||||
repo_helper.set_desired_branches([("branch1", "HEAD"), ("branch2", "HEAD")])
|
||||
_ = repo_helper.checkout_merged.progress()
|
||||
setattr(repo_helper.mock_check, "version", lambda: f"auto-{commit1.hexsha[:8]}-{commit2.hexsha[:8]}")
|
||||
state = SharedStateHolderInMemory(repo_helper.git_unmerge)
|
||||
|
||||
assert state.progress().branches == [("branch1", commit1.hexsha), ("branch2", commit2.hexsha)]
|
||||
|
||||
repo_helper.delete_branch("branch2")
|
||||
repo_helper.git_clone.progress()
|
||||
|
||||
assert repo_helper.git_unmerge.progress().branches == [("branch1", commit1.hexsha)]
|
||||
assert state.progress().branches == [("branch1", commit1.hexsha)]
|
||||
|
||||
def test_checkout_merged_empty_branches(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
"""Test CheckoutMerged with empty branches list - should fail"""
|
||||
|
||||
|
||||
@@ -101,6 +101,104 @@ class TestGitIntegration:
|
||||
with pytest.raises(ValueError, match="requires either 'url' or 'remotes'"):
|
||||
GitClone()
|
||||
|
||||
def test_git_clone_remotes_per_remote_prefix(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
# Per-remote `prefix` filters fetch refspec so only matching branches are visible.
|
||||
# Two repos, two branches each (one matching the prefix, one not). Only the
|
||||
# matching branch should appear in get_branches() for each remote.
|
||||
def fresh_repo(prefix: str) -> str:
|
||||
path = tempfile.mkdtemp(prefix=prefix)
|
||||
repo = git.Repo.init(path, bare=False)
|
||||
with repo.config_writer() as cw:
|
||||
cw.set_value("user", "email", "test@example.com")
|
||||
cw.set_value("user", "name", "Test User")
|
||||
# Branches literally named `ansible/...` to match the prefix filter.
|
||||
# create_commit creates an initial master, then branches off it.
|
||||
repo_helper.create_commit(repo, "master", "master", "README.md", "content", f"{prefix} init")
|
||||
repo_helper.create_commit(repo, "master", "ansible/master", "AN.md", "ansible", f"{prefix} ansible")
|
||||
repo_helper.create_commit(repo, "master", "ansible/fix", "FIX.md", "fix", f"{prefix} fix")
|
||||
return path
|
||||
|
||||
github_dir = fresh_repo("test_prefix_github_")
|
||||
gitea_dir = fresh_repo("test_prefix_gitea_")
|
||||
try:
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "github", "url": github_dir, "prefix": "ansible"},
|
||||
{"name": "gitea_admin", "url": gitea_dir, "prefix": "ansible"},
|
||||
])
|
||||
clone.env = repo_helper.env
|
||||
|
||||
repo_path = clone.progress()
|
||||
repo = git.Repo(repo_path)
|
||||
|
||||
branches = set(clone.get_branches())
|
||||
# Per-remote refspec was applied: only ansible/* branches fetched.
|
||||
assert "github/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "github/ansible/fix" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/ansible/fix" in branches, f"missing: {branches}"
|
||||
|
||||
# `master` exists upstream but is NOT visible (filtered by prefix).
|
||||
assert "github/master" not in branches, f"unwanted: {branches}"
|
||||
assert "gitea_admin/master" not in branches, f"unwanted: {branches}"
|
||||
finally:
|
||||
shutil.rmtree(github_dir, ignore_errors=True)
|
||||
shutil.rmtree(gitea_dir, ignore_errors=True)
|
||||
|
||||
def test_git_clone_remotes_mixed_prefix(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
# Some remotes with prefix, others without. Each behaves independently:
|
||||
# prefixed remotes only see matching branches, unprefixed see all.
|
||||
def fresh_repo(prefix: str) -> str:
|
||||
path = tempfile.mkdtemp(prefix=prefix)
|
||||
repo = git.Repo.init(path, bare=False)
|
||||
with repo.config_writer() as cw:
|
||||
cw.set_value("user", "email", "test@example.com")
|
||||
cw.set_value("user", "name", "Test User")
|
||||
repo_helper.create_commit(repo, "master", "master", "README.md", "content", f"{prefix} init")
|
||||
repo_helper.create_commit(repo, "master", "ansible/master", "AN.md", "ansible", f"{prefix} ansible")
|
||||
repo_helper.create_commit(repo, "master", "feature_y", "OTHER.md", "other", f"{prefix} feature")
|
||||
return path
|
||||
|
||||
github_dir = fresh_repo("test_mixed_github_")
|
||||
gitea_dir = fresh_repo("test_mixed_gitea_")
|
||||
try:
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "github", "url": github_dir, "prefix": "ansible"},
|
||||
{"name": "gitea_admin", "url": gitea_dir},
|
||||
])
|
||||
clone.env = repo_helper.env
|
||||
|
||||
repo_path = clone.progress()
|
||||
repo = git.Repo(repo_path)
|
||||
|
||||
branches = set(clone.get_branches())
|
||||
# Prefixed: only ansible/master.
|
||||
assert "github/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "github/feature_y" not in branches, f"unwanted: {branches}"
|
||||
assert "github/master" not in branches, f"unwanted: {branches}"
|
||||
# Unprefixed: all branches visible.
|
||||
assert "gitea_admin/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/feature_y" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/master" in branches, f"missing: {branches}"
|
||||
finally:
|
||||
shutil.rmtree(github_dir, ignore_errors=True)
|
||||
shutil.rmtree(gitea_dir, ignore_errors=True)
|
||||
|
||||
def test_git_clone_remotes_prefix_validation(self) -> None:
|
||||
# `prefix` must be a string when set; non-string raises ValueError.
|
||||
with pytest.raises(ValueError, match="'prefix' must be a string"):
|
||||
GitClone(remotes=[
|
||||
{"name": "github", "url": "git@example.com:a/b.git", "prefix": 123},
|
||||
])
|
||||
with pytest.raises(ValueError, match="'prefix' must be a string"):
|
||||
GitClone(remotes=[
|
||||
{"name": "github", "url": "git@example.com:a/b.git", "prefix": ["ansible"]},
|
||||
])
|
||||
# Empty string / None: accepted, treated as no prefix.
|
||||
c1 = GitClone(remotes=[{"name": "github", "url": "git@example.com:a/b.git", "prefix": ""}])
|
||||
assert c1.remotes[0]["prefix"] == ""
|
||||
c2 = GitClone(remotes=[{"name": "github", "url": "git@example.com:a/b.git"}])
|
||||
assert c2.remotes[0]["prefix"] == ""
|
||||
|
||||
def test_checkout_merged_one_branch(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
# Create main branch with initial commit
|
||||
commit1 = repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1",
|
||||
|
||||
@@ -144,6 +144,14 @@ class RemoteRepoHelper:
|
||||
repo.index.add([filename])
|
||||
return repo.index.commit(message)
|
||||
|
||||
def delete_branch(self, branch_name: str) -> None:
|
||||
if not self.repo.head.is_detached and self.repo.active_branch.name == branch_name:
|
||||
remaining_heads = [head for head in self.repo.heads if head.name != branch_name]
|
||||
if not remaining_heads:
|
||||
raise ValueError(f"Cannot delete the only branch: {branch_name}")
|
||||
remaining_heads[0].checkout()
|
||||
self.repo.delete_head(branch_name, force=True)
|
||||
|
||||
def verify_working_directory_files(self, expected_files: List[Tuple[str, str]]) -> None:
|
||||
"""Verify that working directory contains exactly the expected files with correct content.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user