Skip to content

Commit e50edc1

Browse files
committed
Trigger ELN scratch builds from rawhide
Signed-off-by: Nikola Forró <[email protected]>
1 parent 847c185 commit e50edc1

File tree

7 files changed

+130
-10
lines changed

7 files changed

+130
-10
lines changed

packit_service/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
)
3737
TESTING_FARM_ARTIFACTS_KEY = "artifacts"
3838

39+
ELN_PACKAGE_LIST = "https://tiny.distro.builders/view-all-source-package-name-list--view-eln.txt"
40+
ELN_EXTRAS_PACKAGE_LIST = (
41+
"https://tiny.distro.builders/view-all-source-package-name-list--view-eln-extras.txt"
42+
)
43+
3944
MSG_DOWNSTREAM_JOB_ERROR_HEADER = (
4045
"Packit failed on creating {object} in dist-git "
4146
"({dist_git_url}):\n\n"

packit_service/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33

44
import logging
55
import os
6-
from datetime import datetime, timezone
6+
import tempfile
7+
from datetime import datetime, timedelta, timezone
78
from io import StringIO
89
from logging import StreamHandler
910
from pathlib import Path
1011
from re import search
1112
from typing import Optional
1213

1314
import requests
15+
from cachetools.func import ttl_cache
1416
from ogr.abstract import PullRequest
1517
from packit.config import JobConfig, PackageConfig
1618
from packit.schema import JobConfigSchema, PackageConfigSchema
1719
from packit.utils import PackitFormatter
1820

1921
from packit_service import __version__ as ps_version
22+
from packit_service.constants import ELN_EXTRAS_PACKAGE_LIST, ELN_PACKAGE_LIST
2023

2124
logger = logging.getLogger(__name__)
2225

@@ -298,3 +301,13 @@ def download_file(url: str, path: Path):
298301
return False
299302

300303
return True
304+
305+
306+
@ttl_cache(maxsize=1, ttl=timedelta(hours=12).seconds)
307+
def get_eln_packages():
308+
packages = []
309+
for url in (ELN_PACKAGE_LIST, ELN_EXTRAS_PACKAGE_LIST):
310+
with tempfile.NamedTemporaryFile() as tmp:
311+
if download_file(url, tmp.name):
312+
packages.extend(Path(tmp.name).read_text().splitlines())
313+
return packages

packit_service/worker/checker/distgit.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import re
66

77
from packit.config.aliases import get_branches
8+
from packit.utils import commands
89

10+
from packit_service import utils
911
from packit_service.constants import MSG_GET_IN_TOUCH
1012
from packit_service.events import (
1113
anitya,
@@ -155,6 +157,20 @@ def pre_check(self) -> bool:
155157
return True
156158

157159

160+
class PackageNeedsELNBuildFromRawhide(Checker, GetPagurePullRequestMixin):
161+
def pre_check(self) -> bool:
162+
if (
163+
self.pull_request.target_branch == "rawhide"
164+
and self.project.repo in utils.get_eln_packages()
165+
):
166+
repo_url = self.project.get_git_urls().get("git")
167+
return not commands.run_command(
168+
["git", "ls-remote", repo_url, "eln"], output=True
169+
).stdout.strip()
170+
171+
return False
172+
173+
158174
class HasIssueCommenterRetriggeringPermissions(ActorChecker):
159175
"""To be able to retrigger a koji-build the issue commenter should
160176
have write permission on the project.

packit_service/worker/handlers/abstract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ class TaskName(str, enum.Enum):
250250
openscanhub_task_started = "task.openscanhub_task_started"
251251
downstream_koji_scratch_build = "task.run_downstream_koji_scratch_build_handler"
252252
downstream_koji_scratch_build_report = "task.run_downstream_koji_scratch_build_report_handler"
253+
downstream_koji_eln_scratch_build = "task.run_downstream_koji_eln_scratch_build_handler"
253254
downstream_log_detective_results = "task.run_downstream_log_detective_results_handler"
254255

255256

packit_service/worker/handlers/distgit.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
IsProjectOk,
8181
IsUpstreamTagMatchingConfig,
8282
LabelsOnDistgitPR,
83+
PackageNeedsELNBuildFromRawhide,
8384
PermissionOnDistgit,
8485
PermissionOnDistgitForFedoraCI,
8586
TaggedBuildIsNotABuildOfSelf,
@@ -792,7 +793,6 @@ def __init__(
792793
job_config: JobConfig,
793794
event: dict,
794795
celery_task: Task,
795-
koji_group_model_id: Optional[int] = None,
796796
):
797797
super().__init__(
798798
package_config=package_config,
@@ -802,7 +802,6 @@ def __init__(
802802
)
803803
self._project_url = self.data.project_url
804804
self._packit_api = None
805-
self._koji_group_model_id = koji_group_model_id
806805
self._ci_helper: Optional[FedoraCIHelper] = None
807806

808807
@property
@@ -966,6 +965,21 @@ def run_koji_build(
966965
).stdout
967966

968967

968+
@run_for_comment_as_fedora_ci(command="scratch-build")
969+
@reacts_to_as_fedora_ci(event=pagure.pr.Action)
970+
@reacts_to_as_fedora_ci(event=pagure.pr.Comment)
971+
class DownstreamKojiELNScratchBuildHandler(DownstreamKojiScratchBuildHandler):
972+
task_name = TaskName.downstream_koji_eln_scratch_build
973+
974+
@property
975+
def dist_git_branch(self) -> str:
976+
return "eln"
977+
978+
@staticmethod
979+
def get_checkers() -> tuple[type[Checker], ...]:
980+
return (PermissionOnDistgitForFedoraCI, PackageNeedsELNBuildFromRawhide)
981+
982+
969983
class AbstractDownstreamKojiBuildHandler(
970984
abc.ABC,
971985
RetriableJobHandler,

packit_service/worker/tasks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
)
7575
from packit_service.worker.handlers.distgit import (
7676
DownstreamKojiBuildHandler,
77+
DownstreamKojiELNScratchBuildHandler,
7778
DownstreamKojiScratchBuildHandler,
7879
PullFromUpstreamHandler,
7980
RetriggerDownstreamKojiBuildHandler,
@@ -464,6 +465,24 @@ def run_downstream_koji_scratch_build_handler(
464465
return get_handlers_task_results(handler.run_job(), event)
465466

466467

468+
@celery_app.task(
469+
bind=True,
470+
name=TaskName.downstream_koji_eln_scratch_build,
471+
base=TaskWithRetry,
472+
queue="long-running",
473+
)
474+
def run_downstream_koji_eln_scratch_build_handler(
475+
self, event: dict, package_config: dict, job_config: dict
476+
):
477+
handler = DownstreamKojiELNScratchBuildHandler(
478+
package_config=load_package_config(package_config),
479+
job_config=load_job_config(job_config),
480+
event=event,
481+
celery_task=self,
482+
)
483+
return get_handlers_task_results(handler.run_job(), event)
484+
485+
467486
@celery_app.task(
468487
name=TaskName.sync_from_downstream,
469488
base=TaskWithRetry,

tests/integration/test_dg_pr.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from packit.local_project import LocalProjectBuilder
1515
from packit.utils import commands
1616

17+
from packit_service import utils
1718
from packit_service.config import ServiceConfig
1819
from packit_service.constants import SANDCASTLE_WORK_DIR
1920
from packit_service.models import (
@@ -28,6 +29,7 @@
2829
from packit_service.worker.jobs import SteveJobs
2930
from packit_service.worker.monitoring import Pushgateway
3031
from packit_service.worker.tasks import (
32+
run_downstream_koji_eln_scratch_build_handler,
3133
run_downstream_koji_scratch_build_handler,
3234
)
3335
from tests.spellbook import DATA_DIR, first_dict_value, get_parameters_from_results
@@ -39,30 +41,47 @@ def distgit_pr_event():
3941

4042

4143
@pytest.mark.parametrize(
42-
"target_branch, uid, check_name",
44+
"target_branch, uid, check_name, eln",
4345
[
4446
pytest.param(
4547
"rawhide",
4648
"e0091d5fbcb20572cbf2e6442af9bed5",
4749
"Packit - scratch build - rawhide",
50+
False,
4851
id="rawhide target branch",
4952
),
53+
pytest.param(
54+
"rawhide",
55+
"8edd48272efe6aff7d1d92bdffcaf9a0",
56+
"Packit - scratch build - eln",
57+
True,
58+
id="rawhide branch, rawhide + eln target",
59+
),
5060
pytest.param(
5161
"f42",
5262
"6f08c3bbb20660dc8c597bc7dbe4f056",
5363
"Packit - scratch build - f42",
64+
False,
5465
id="f42 target branch",
5566
),
5667
],
5768
)
58-
def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, check_name):
69+
def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, check_name, eln):
5970
distgit_pr_event["pullrequest"]["branch"] = target_branch
6071
pr_object = (
61-
flexmock()
72+
flexmock(target_branch=target_branch)
6273
.should_receive("set_flag")
6374
.with_args(username=check_name, comment=str, url=str, status=CommitStatus, uid=uid)
6475
.mock()
6576
)
77+
if eln:
78+
check_name = "Packit - scratch build - rawhide"
79+
uid = "e0091d5fbcb20572cbf2e6442af9bed5"
80+
(
81+
pr_object.should_receive("set_flag")
82+
.with_args(username=check_name, comment=str, url=str, status=CommitStatus, uid=uid)
83+
.mock()
84+
)
6685
dg_project = (
6786
flexmock(
6887
PagureProject(namespace="rpms", repo="optee_os", service=flexmock(read_only=False))
@@ -73,6 +92,9 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
7392
.should_receive("get_pr")
7493
.and_return(pr_object)
7594
.mock()
95+
.should_receive("get_git_urls")
96+
.and_return({"git": "https://src.fedoraproject.org/rpms/optee_os.git"})
97+
.mock()
7698
)
7799
service_config = (
78100
flexmock(
@@ -112,6 +134,13 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
112134
)
113135
flexmock(PipelineModel).should_receive("create")
114136

137+
flexmock(utils).should_receive("get_eln_packages").and_return(["optee_os"] if eln else [])
138+
if eln:
139+
flexmock(commands).should_receive("run_command").with_args(
140+
["git", "ls-remote", "https://src.fedoraproject.org/rpms/optee_os.git", "eln"],
141+
output=True,
142+
).and_return(flexmock(stdout=""))
143+
115144
koji_build = flexmock(
116145
id=123,
117146
target="main",
@@ -130,8 +159,8 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
130159
)
131160

132161
flexmock(LocalProjectBuilder, _refresh_the_state=lambda *args: None)
133-
flexmock(Signature).should_receive("apply_async").once()
134-
flexmock(Pushgateway).should_receive("push").times(2).and_return()
162+
flexmock(Signature).should_receive("apply_async").times(2 if eln else 1)
163+
flexmock(Pushgateway).should_receive("push").times(3 if eln else 2).and_return()
135164
flexmock(commands).should_receive("run_command_remote").with_args(
136165
cmd=[
137166
"koji",
@@ -145,15 +174,29 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
145174
output=True,
146175
print_live=True,
147176
).and_return(flexmock(stdout="some output"))
177+
if eln:
178+
flexmock(commands).should_receive("run_command_remote").with_args(
179+
cmd=[
180+
"koji",
181+
"build",
182+
"--scratch",
183+
"--nowait",
184+
"eln",
185+
"git+https://src.fedoraproject.org/forks/zbyszek/rpms/optee_os.git#889f07af35d27bbcaf9c535c17a63b974aa42ee3",
186+
],
187+
cwd=Path,
188+
output=True,
189+
print_live=True,
190+
).and_return(flexmock(stdout="some output"))
148191
flexmock(PackitAPI).should_receive("init_kerberos_ticket")
149192

150193
flexmock(distgit).should_receive("get_koji_task_id_and_url_from_stdout").and_return(
151194
(123, "koji-web-url")
152-
).once()
195+
).times(2 if eln else 1)
153196

154197
processing_results = SteveJobs().process_message(distgit_pr_event)
155198
event_dict, _, job_config, package_config = get_parameters_from_results(
156-
processing_results,
199+
processing_results[:1],
157200
)
158201
assert json.dumps(event_dict)
159202
results = run_downstream_koji_scratch_build_handler(
@@ -163,3 +206,12 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
163206
)
164207

165208
assert first_dict_value(results["job"])["success"]
209+
210+
if eln:
211+
results = run_downstream_koji_eln_scratch_build_handler(
212+
package_config=package_config,
213+
event=event_dict,
214+
job_config=job_config,
215+
)
216+
217+
assert first_dict_value(results["job"])["success"]

0 commit comments

Comments
 (0)