Skip to content

Commit be4eae7

Browse files
MagicRBMic92
authored andcommitted
Copy authentication files in GitLocalPrMerge
Signed-off-by: magic_rb <richard@brezak.sk>
1 parent 9da4555 commit be4eae7

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

buildbot_nix/buildbot_nix/__init__.py

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ async def run_vc(
988988
pr_head = build_props.getProperty("github.head.sha") or build_props.getProperty(
989989
"head_sha"
990990
)
991+
auth_workdir = self._get_auth_data_workdir()
991992

992993
# Not a PR, fallback to default behavior
993994
if merge_base is None or pr_head is None:
@@ -1007,33 +1008,42 @@ async def run_vc(
10071008
self.build.path_module.join(self.workdir, ".git")
10081009
)
10091010

1010-
if not has_git:
1011-
await self._dovccmd(["clone", "--recurse-submodules", self.repourl, "."])
1011+
try:
1012+
await self._git_auth.download_auth_files_if_needed(auth_workdir)
10121013

1013-
patched = await self.sourcedirIsPatched()
1014+
if not has_git:
1015+
await self._dovccmd(
1016+
["clone", "--recurse-submodules", self.repourl, "."]
1017+
)
10141018

1015-
if patched:
1016-
await self._dovccmd(["clean", "-f", "-f", "-d", "-x"])
1019+
patched = await self.sourcedirIsPatched()
10171020

1018-
await self._dovccmd(["fetch", "-f", "-t", self.repourl, merge_base, pr_head])
1021+
if patched:
1022+
await self._dovccmd(["clean", "-f", "-f", "-d", "-x"])
10191023

1020-
await self._dovccmd(["checkout", "--detach", "-f", pr_head])
1024+
await self._dovccmd(
1025+
["fetch", "-f", "-t", self.repourl, merge_base, pr_head]
1026+
)
10211027

1022-
await self._dovccmd(
1023-
[
1024-
"-c",
1025-
"user.email=buildbot@example.com",
1026-
"-c",
1027-
"user.name=buildbot",
1028-
"merge",
1029-
"--no-ff",
1030-
"-m",
1031-
f"Merge {merge_base} into {pr_head}",
1032-
merge_base,
1033-
]
1034-
)
1035-
self.updateSourceProperty("got_revision", pr_head)
1036-
return await self.parseCommitDescription()
1028+
await self._dovccmd(["checkout", "--detach", "-f", pr_head])
1029+
1030+
await self._dovccmd(
1031+
[
1032+
"-c",
1033+
"user.email=buildbot@example.com",
1034+
"-c",
1035+
"user.name=buildbot",
1036+
"merge",
1037+
"--no-ff",
1038+
"-m",
1039+
f"Merge {merge_base} into {pr_head}",
1040+
merge_base,
1041+
]
1042+
)
1043+
self.updateSourceProperty("got_revision", pr_head)
1044+
return await self.parseCommitDescription()
1045+
finally:
1046+
await self._git_auth.remove_auth_files_if_needed(auth_workdir)
10371047

10381048

10391049
def nix_eval_config(
@@ -1060,8 +1070,12 @@ def nix_eval_config(
10601070
submodules=True,
10611071
haltOnFailure=True,
10621072
logEnviron=False,
1063-
sshPrivateKey=project.private_key_path.read_text() if project.private_key_path else None,
1064-
sshKnownHosts=project.known_hosts_path.read_text() if project.known_hosts_path else None,
1073+
sshPrivateKey=project.private_key_path.read_text()
1074+
if project.private_key_path
1075+
else None,
1076+
sshKnownHosts=project.known_hosts_path.read_text()
1077+
if project.known_hosts_path
1078+
else None,
10651079
),
10661080
)
10671081
drv_gcroots_dir = util.Interpolate(
@@ -1370,6 +1384,8 @@ def nix_skipped_build_config(
13701384
collapseRequests=False,
13711385
env={},
13721386
factory=factory,
1387+
do_build_if=lambda build: do_register_gcroot_if(build, branch_config_dict)
1388+
and outputs_path is not None,
13731389
)
13741390

13751391

@@ -1419,8 +1435,12 @@ def buildbot_effects_config(
14191435
method="clean",
14201436
submodules=True,
14211437
haltOnFailure=True,
1422-
sshPrivateKey=project.private_key_path.read_text() if project.private_key_path else None,
1423-
sshKnownHosts=project.known_hosts_path.read_text() if project.known_hosts_path else None,
1438+
sshPrivateKey=project.private_key_path.read_text()
1439+
if project.private_key_path
1440+
else None,
1441+
sshKnownHosts=project.known_hosts_path.read_text()
1442+
if project.known_hosts_path
1443+
else None,
14241444
),
14251445
)
14261446
secrets_list = []

buildbot_nix/buildbot_nix/gitea_projects.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def get_project_url(self) -> str:
6363
url = urlparse(self.config.instance_url)
6464
if self.config.ssh_private_key_file:
6565
return self.data.ssh_url
66-
else:
67-
return f"{url.scheme}://git:%(secret:{self.config.token_file})s@{url.hostname}/{self.name}"
66+
return f"{url.scheme}://git:%(secret:{self.config.token_file})s@{url.hostname}/{self.name}"
6867

6968
def create_change_source(self) -> ChangeSource | None:
7069
return None
@@ -125,7 +124,6 @@ def known_hosts_path(self) -> Path | None:
125124
return self.config.ssh_known_hosts_file
126125

127126

128-
129127
class GiteaBackend(GitBackend):
130128
config: GiteaConfig
131129
webhook_secret: str

buildbot_nix/buildbot_nix/projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC, abstractmethod
2-
from typing import Any
32
from pathlib import Path
3+
from typing import Any
44

55
from buildbot.changes.base import ChangeSource
66
from buildbot.config.builder import BuilderConfig

buildbot_nix/buildbot_nix/pull_based/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from pathlib import Path
12
from typing import Any
23
from urllib.parse import ParseResult, urlparse
3-
from pathlib import Path
44

55
from buildbot.changes.base import ChangeSource
66
from buildbot.changes.gitpoller import GitPoller

0 commit comments

Comments
 (0)