Skip to content

Commit 1d0c869

Browse files
Allow retriggering builds/tests on ELN rawhide PRs independently (#3032)
Allow retriggering builds/tests on ELN rawhide PRs independently TODO: Write new tests or update the old ones to cover new functionality. Update doc-strings where appropriate. Update or write new documentation in packit/packit.dev. NOTE 1 When figuring out how to implement this PR, I noticed that separate handlers are run when running jobs for eln and rawhide. This implementation is based on discarding the one handler associated with the jobs that are not needed (removing it from the handlers_triggered_by_job variable). For example: /packit-ci test rpminspect eln Would lead to the handler corresponding with the rawhide target being removed from the list of handlers to be run. It's possible that there could be a better way of implementing this. NOTE 2 I implemented the retriggering comment syntax as was described in the issue. However, having it implemented as a positional argument means that comments like this are valid: /packit-ci test custom eln /packit-ci build rawhide But the following would be invalid and lead to a parsing error because of the missing positional argument before eln (the first positional argument cannot be missing if the second one is present): /packit-ci test eln If needed, I could instead turn the new argument into a keyword argument like this: /packit-ci test --target-branch eln EDIT: I've made it into a keyword argument in the second commit. I should probably write a new test to test the functionality of /packit-ci test --target-branch eln. Fixes #2958 RELEASE NOTES BEGIN In Fedora CI, it is now possible to retrigger builds and tests on ELN rawhide PRs with no dedicated eln branch independently. RELEASE NOTES END Reviewed-by: gemini-code-assist[bot] Reviewed-by: Alžběta Kučerová Reviewed-by: Nikola Forró Reviewed-by: Laura Barcziová
2 parents e3738cc + f2ccd9d commit 1d0c869

File tree

7 files changed

+512
-13
lines changed

7 files changed

+512
-13
lines changed

packit_service/utils.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,28 @@ def get_comment_parser_fedora_ci(
334334
)
335335
test_parser = subparsers.add_parser("test", help="Run tests in Testing Farm")
336336
test_parser.add_argument(
337-
"target",
337+
"test_identifier",
338338
nargs="?",
339339
choices=["installability", "rpmlint", "rpminspect", "custom"],
340340
help="Specific type of tests to run",
341341
)
342-
subparsers.add_parser("scratch-build", help="Build package in Koji")
342+
343+
test_parser.add_argument(
344+
"--target",
345+
dest="check_target",
346+
nargs="?",
347+
choices=["eln", "rawhide"],
348+
help="Target for which to trigger tests",
349+
)
350+
351+
scratch_build_parser = subparsers.add_parser("scratch-build", help="Build package in Koji")
352+
scratch_build_parser.add_argument(
353+
"--target",
354+
dest="check_target",
355+
nargs="?",
356+
choices=["eln", "rawhide"],
357+
help="Target for which to trigger a scratch build in Koji",
358+
)
343359

344360
return parser
345361

packit_service/worker/handlers/abstract.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,37 @@ class RateLimitRequeueException(Exception):
7070
MAP_COMMENT_TO_HANDLER_FEDORA_CI: dict[str, set[type["FedoraCIJobHandler"]]] = defaultdict(set)
7171
MAP_CHECK_PREFIX_TO_HANDLER: dict[str, set[type["JobHandler"]]] = defaultdict(set)
7272

73+
MAP_TARGET_TO_HANDLER: dict[type["FedoraCIJobHandler"], str] = defaultdict(str)
74+
75+
76+
def corresponds_to_check_target(check_target: str):
77+
"""
78+
[class decorator]
79+
Specify which target the handler corresponds to.
80+
81+
Normally, when retriggering jobs on ELN rawhide PRs with no
82+
existing eln branch, jobs would be run for both the rawhide
83+
and eln targets. When the check target is specified like this,
84+
85+
/packit-ci test installability rawhide
86+
87+
then only the handler corresponding to the specified target
88+
(rawhide in this example) will be run, resulting in jobs being run
89+
only for the desired target.
90+
91+
Example:
92+
```
93+
@corresponds_to_check_target(check_target="rawhide")
94+
class DownstreamKojiScratchBuildHandler(
95+
```
96+
"""
97+
98+
def _add_to_mapping(kls: type["FedoraCIJobHandler"]):
99+
MAP_TARGET_TO_HANDLER[kls] = check_target
100+
return kls
101+
102+
return _add_to_mapping
103+
73104

74105
def configured_as(job_type: JobType):
75106
"""

packit_service/worker/handlers/distgit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
RetriableJobHandler,
9696
TaskName,
9797
configured_as,
98+
corresponds_to_check_target,
9899
reacts_to,
99100
reacts_to_as_fedora_ci,
100101
run_for_check_rerun,
@@ -776,6 +777,7 @@ def _run(self) -> TaskResults:
776777

777778

778779
@run_for_comment_as_fedora_ci(command="scratch-build")
780+
@corresponds_to_check_target(check_target="rawhide")
779781
@reacts_to_as_fedora_ci(event=pagure.pr.Action)
780782
@reacts_to_as_fedora_ci(event=pagure.pr.Comment)
781783
class DownstreamKojiScratchBuildHandler(
@@ -1010,6 +1012,7 @@ def run_koji_build(
10101012

10111013

10121014
@run_for_comment_as_fedora_ci(command="scratch-build")
1015+
@corresponds_to_check_target(check_target="eln")
10131016
@reacts_to_as_fedora_ci(event=pagure.pr.Action)
10141017
@reacts_to_as_fedora_ci(event=pagure.pr.Comment)
10151018
class DownstreamKojiELNScratchBuildHandler(DownstreamKojiScratchBuildHandler):

packit_service/worker/handlers/testing_farm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
RetriableJobHandler,
6868
TaskName,
6969
configured_as,
70+
corresponds_to_check_target,
7071
reacts_to,
7172
reacts_to_as_fedora_ci,
7273
run_for_check_rerun,
@@ -360,6 +361,7 @@ def _run(self) -> TaskResults:
360361

361362

362363
@run_for_comment_as_fedora_ci(command="test")
364+
@corresponds_to_check_target(check_target="rawhide")
363365
@reacts_to_as_fedora_ci(event=koji.result.Task)
364366
@reacts_to_as_fedora_ci(event=pagure.pr.Comment)
365367
class DownstreamTestingFarmHandler(
@@ -520,6 +522,7 @@ def _run(self) -> TaskResults:
520522

521523

522524
@run_for_comment_as_fedora_ci(command="test")
525+
@corresponds_to_check_target(check_target="eln")
523526
@reacts_to_as_fedora_ci(event=pagure.pr.Comment)
524527
class DownstreamTestingFarmELNHandler(DownstreamTestingFarmHandler):
525528
"""

packit_service/worker/jobs.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
MAP_COMMENT_TO_HANDLER_FEDORA_CI,
6767
MAP_JOB_TYPE_TO_HANDLER,
6868
MAP_REQUIRED_JOB_TYPE_TO_HANDLER,
69+
MAP_TARGET_TO_HANDLER,
6970
SUPPORTED_EVENTS_FOR_HANDLER,
7071
SUPPORTED_EVENTS_FOR_HANDLER_FEDORA_CI,
7172
FedoraCIJobHandler,
@@ -112,6 +113,7 @@
112113
class ParsedComment:
113114
command: Optional[str] = None
114115
package: Optional[str] = None
116+
check_target: Optional[str] = None
115117

116118

117119
def parse_comment(
@@ -143,7 +145,8 @@ def parse_comment(
143145

144146
try:
145147
args = parser.parse_args(commands)
146-
return ParsedComment(command=args.command, package=args.package)
148+
check_target = getattr(args, "check_target", None)
149+
return ParsedComment(command=args.command, package=args.package, check_target=check_target)
147150
except SystemExit:
148151
# tests expect invalid syntax comments be ignored
149152
logger.debug(
@@ -176,12 +179,16 @@ def get_handlers_for_command(
176179

177180
def get_handlers_for_command_fedora_ci(
178181
command: str,
182+
check_target: Optional[str],
179183
) -> set[type[FedoraCIJobHandler]]:
180184
"""
181-
Get handlers for the given command.
185+
Get handlers for the given command. If check_target is specified
186+
(for example: eln), then only handlers relevant to this target
187+
will be returned.
182188
183189
Args:
184190
command: command to get handler to
191+
check_target: target for which to run jobs
185192
186193
Returns:
187194
Set of handlers for Fecora CI that are triggered by command.
@@ -192,6 +199,12 @@ def get_handlers_for_command_fedora_ci(
192199
handlers = MAP_COMMENT_TO_HANDLER_FEDORA_CI[command]
193200
if not handlers:
194201
logger.debug(f"Command {command} not supported by packit.")
202+
203+
if check_target:
204+
handlers = {
205+
handler for handler in handlers if MAP_TARGET_TO_HANDLER[handler] == check_target
206+
}
207+
195208
return handlers
196209

197210

@@ -552,7 +565,11 @@ def _post_fedora_ci_transition_comment(self) -> None:
552565
# Don't fail the job if we can't post the comment
553566
logger.warning(f"Failed to post CI transition comment: {ex}")
554567

555-
def report_task_accepted_for_fedora_ci(self, handler_kls: type[FedoraCIJobHandler]):
568+
def report_task_accepted_for_fedora_ci(
569+
self,
570+
handler_kls: type[FedoraCIJobHandler],
571+
user_specified_target_branch: Optional[str] = None,
572+
):
556573
"""
557574
For CI-related dist-git PR comment events report the initial status
558575
"Task was accepted" to inform user we are working on the request.
@@ -572,10 +589,12 @@ def report_task_accepted_for_fedora_ci(self, handler_kls: type[FedoraCIJobHandle
572589
if (target_branch := self.event.pull_request_object.target_branch) == "main":
573590
target_branch = "rawhide"
574591

592+
# target_branch determines the check's title such as:
593+
# "Packit - installability - rawhide [beaf90b]"
575594
helper = FedoraCIHelper(
576595
project=self.event.project,
577596
metadata=metadata,
578-
target_branch=target_branch,
597+
target_branch=user_specified_target_branch or target_branch,
579598
)
580599

581600
first_status_reported = False
@@ -683,9 +702,10 @@ def process_fedora_ci_jobs(self) -> list[TaskResults]:
683702
A list of task results for each task created.
684703
"""
685704
handlers_triggered_by_job = None
705+
check_target = None
706+
686707
# [XXX] if there are ever monorepos in Fedora CI…
687708
# monorepo_package = None
688-
689709
if isinstance(self.event, abstract.comment.CommentEvent):
690710
arguments = parse_comment(
691711
self.event.comment,
@@ -695,7 +715,8 @@ def process_fedora_ci_jobs(self) -> list[TaskResults]:
695715
# [XXX] if there are ever monorepos in Fedora CI…
696716
# monorepo_package = arguments.package
697717
command = arguments.command
698-
handlers_triggered_by_job = get_handlers_for_command_fedora_ci(command)
718+
check_target = getattr(arguments, "check_target", None)
719+
handlers_triggered_by_job = get_handlers_for_command_fedora_ci(command, check_target)
699720

700721
matching_handlers = {
701722
handler
@@ -726,7 +747,7 @@ def process_fedora_ci_jobs(self) -> list[TaskResults]:
726747
# if monorepo_package and handler_kls.job_config.package == monorepo_package:
727748
# continue
728749

729-
self.report_task_accepted_for_fedora_ci(handler_kls)
750+
self.report_task_accepted_for_fedora_ci(handler_kls, check_target)
730751

731752
celery_signature = celery.signature(
732753
handler_kls.task_name.value,

0 commit comments

Comments
 (0)