def test_copr_and_koji_build_for_one_trigger(clean_before_and_after): pr1 = PullRequestModel.get_or_create( pr_id=1, namespace="the-namespace", repo_name="the-repo-name" ) pr1_trigger = JobTriggerModel.get_or_create( type=JobTriggerModelType.pull_request, trigger_id=pr1.id ) srpm_build = SRPMBuildModel.create("asd\nqwe\n") copr_build = CoprBuildModel.get_or_create( build_id="123456", commit_sha="687abc76d67d", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target=TARGET, status="pending", srpm_build=srpm_build, trigger_model=pr1, ) koji_build = KojiBuildModel.get_or_create( build_id="987654", commit_sha="687abc76d67d", web_url="https://copr.something.somewhere/123456", target=TARGET, status="pending", srpm_build=srpm_build, trigger_model=pr1, ) assert copr_build in pr1_trigger.copr_builds assert koji_build in pr1_trigger.koji_builds assert copr_build.job_trigger.get_trigger_object() == pr1 assert koji_build.job_trigger.get_trigger_object() == pr1
def copr_builds_with_different_triggers( pr_model, branch_model, release_model, srpm_build_model ): yield [ # pull request trigger CoprBuildModel.get_or_create( build_id=SampleValues.build_id, commit_sha=SampleValues.ref, project_name=SampleValues.project, owner=SampleValues.owner, web_url=SampleValues.copr_web_url, target=SampleValues.target, status=SampleValues.status_success, srpm_build=srpm_build_model, trigger_model=pr_model, ), # branch push trigger CoprBuildModel.get_or_create( build_id=SampleValues.different_build_id, commit_sha=SampleValues.ref, project_name=SampleValues.project, owner=SampleValues.owner, web_url=SampleValues.copr_web_url, target=SampleValues.target, status=SampleValues.status_success, srpm_build=srpm_build_model, trigger_model=branch_model, ), # release trigger CoprBuildModel.get_or_create( build_id=SampleValues.another_different_build_id, commit_sha=SampleValues.ref, project_name=SampleValues.project, owner=SampleValues.owner, web_url=SampleValues.copr_web_url, target=SampleValues.target, status=SampleValues.status_success, srpm_build=srpm_build_model, trigger_model=release_model, ), ]
def a_copr_build_for_release(release_model, srpm_build_model): yield CoprBuildModel.get_or_create( build_id=SampleValues.build_id, commit_sha=SampleValues.commit_sha, project_name=SampleValues.project, owner=SampleValues.owner, web_url=SampleValues.copr_web_url, target=SampleValues.target, status=SampleValues.status_pending, srpm_build=srpm_build_model, trigger_model=release_model, )
def copr_builds_with_different_triggers(pr_model, branch_model, release_model): srpm_build = SRPMBuildModel.create("asd\nqwe\n") yield [ # pull request trigger CoprBuildModel.get_or_create( build_id="123456", commit_sha="687abc76d67d", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-42-x86_64", status="pending", srpm_build=srpm_build, trigger_model=pr_model, ), # branch push trigger CoprBuildModel.get_or_create( build_id="123456", commit_sha="687abc76d67d", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, trigger_model=branch_model, ), # release trigger CoprBuildModel.get_or_create( build_id="987654", commit_sha="987def76d67e", project_name="SomeUser-random-text-7", owner="cockpit-project", web_url="https://copr.something.somewhere/987654", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, trigger_model=release_model, ), ]
def multiple_copr_builds(pr_model, different_pr_model): srpm_build = SRPMBuildModel.create("asd\nqwe\n") yield [ CoprBuildModel.get_or_create( build_id="123456", commit_sha="687abc76d67d", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-42-x86_64", status="pending", srpm_build=srpm_build, trigger_model=pr_model, ), # Same build_id but different chroot CoprBuildModel.get_or_create( build_id="123456", commit_sha="687abc76d67d", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, trigger_model=pr_model, ), # Completely different build CoprBuildModel.get_or_create( build_id="987654", commit_sha="987def76d67e", project_name="SomeUser-random-text-7", owner="cockpit-project", web_url="https://copr.something.somewhere/987654", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, trigger_model=different_pr_model, ), ]
def a_copr_build_for_release(release_model): srpm_build = SRPMBuildModel.create("asd\nqwe\n") yield CoprBuildModel.get_or_create( build_id="123456", commit_sha="687abc76d67d", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target=TARGET, status="pending", srpm_build=srpm_build, trigger_model=release_model, )
def run_copr_build(self) -> HandlerResults: if not (self.job_build or self.job_tests): msg = "No copr_build or tests job defined." # we can't report it to end-user at this stage return HandlerResults(success=False, details={"msg": msg}) self.report_status_to_all(description="Building SRPM ...", state=CommitStatus.pending) build_metadata = self._run_copr_build_and_save_output() srpm_build_model = SRPMBuildModel.create(build_metadata.srpm_logs) if build_metadata.srpm_failed: msg = "SRPM build failed, check the logs for details." self.report_status_to_all( state=CommitStatus.failure, description=msg, url=get_srpm_log_url(srpm_build_model.id), ) return HandlerResults(success=False, details={"msg": msg}) for chroot in self.build_chroots: copr_build = CoprBuildModel.get_or_create( build_id=str(build_metadata.copr_build_id), commit_sha=self.event.commit_sha, project_name=self.job_project, owner=self.job_owner, web_url=build_metadata.copr_web_url, target=chroot, status="pending", srpm_build=srpm_build_model, trigger_model=self.event.db_trigger, ) url = get_log_url(id_=copr_build.id) self.report_status_to_all_for_chroot( state=CommitStatus.pending, description="Building RPM ...", url=url, chroot=chroot, ) # release the hounds! celery_app.send_task( "task.babysit_copr_build", args=(build_metadata.copr_build_id, ), countdown=120, # do the first check in 120s ) return HandlerResults(success=True, details={})
def multiple_copr_builds(pr_model, different_pr_model, srpm_build_model): yield [ CoprBuildModel.get_or_create( build_id=SampleValues.build_id, commit_sha=SampleValues.ref, project_name=SampleValues.project, owner=SampleValues.owner, web_url=SampleValues.copr_web_url, target=SampleValues.target, status=SampleValues.status_success, srpm_build=srpm_build_model, trigger_model=pr_model, ), CoprBuildModel.get_or_create( build_id=SampleValues.build_id, commit_sha=SampleValues.ref, project_name=SampleValues.project, owner=SampleValues.owner, web_url=SampleValues.copr_web_url, target=SampleValues.different_target, status=SampleValues.status_pending, srpm_build=srpm_build_model, trigger_model=pr_model, ), CoprBuildModel.get_or_create( build_id=SampleValues.different_build_id, commit_sha=SampleValues.different_commit_sha, project_name=SampleValues.different_project_name, owner=SampleValues.owner, web_url=SampleValues.copr_web_url, target=SampleValues.target, status=SampleValues.status_success, srpm_build=srpm_build_model, trigger_model=different_pr_model, ), ]
def packit_build_752(): pr_model = PullRequestModel.get_or_create(pr_id=752, namespace="packit-service", repo_name="packit") srpm_build = SRPMBuildModel.create("asd\nqwe\n") yield CoprBuildModel.get_or_create( build_id=str(BUILD_ID), commit_sha="687abc76d67d", project_name="packit-service-packit-752", owner="packit", web_url=("https://download.copr.fedorainfracloud.org/" "results/packit/packit-service-packit-752"), target="fedora-rawhide-x86_64", status="pending", srpm_build=srpm_build, trigger_model=pr_model, )
def run_copr_build(self) -> HandlerResults: if not (self.job_build or self.job_tests): msg = "No copr_build or tests job defined." # we can't report it to end-user at this stage return HandlerResults(success=False, details={"msg": msg}) self.report_status_to_all( description="Building SRPM ...", state=CommitStatus.pending, # pagure requires "valid url" url="", ) self.create_srpm_if_needed() if not self.srpm_model.success: msg = "SRPM build failed, check the logs for details." self.report_status_to_all( state=CommitStatus.failure, description=msg, url=get_srpm_log_url_from_flask(self.srpm_model.id), ) return HandlerResults(success=False, details={"msg": msg}) try: build_id, web_url = self.run_build() except Exception as ex: sentry_integration.send_to_sentry(ex) # TODO: Where can we show more info about failure? # TODO: Retry self.report_status_to_all( state=CommitStatus.error, description=f"Submit of the build failed: {ex}", ) return HandlerResults(success=False, details={"error": str(ex)}) for chroot in self.build_targets: copr_build = CoprBuildModel.get_or_create( build_id=str(build_id), commit_sha=self.event.commit_sha, project_name=self.job_project, owner=self.job_owner, web_url=web_url, target=chroot, status="pending", srpm_build=self.srpm_model, trigger_model=self.event.db_trigger, ) url = get_copr_build_log_url_from_flask(id_=copr_build.id) self.report_status_to_all_for_chroot( state=CommitStatus.pending, description="Starting RPM build...", url=url, chroot=chroot, ) # release the hounds! celery_app.send_task( "task.babysit_copr_build", args=(build_id,), countdown=120, # do the first check in 120s ) return HandlerResults(success=True, details={})
def run_copr_build(self) -> TaskResults: if not (self.job_build or self.job_tests): msg = "No copr_build or tests job defined." # we can't report it to end-user at this stage return TaskResults(success=False, details={"msg": msg}) self.report_status_to_all( description="Building SRPM ...", state=CommitStatus.pending, # pagure requires "valid url" url="", ) self.create_srpm_if_needed() if not self.srpm_model.success: msg = "SRPM build failed, check the logs for details." self.report_status_to_all( state=CommitStatus.failure, description=msg, url=get_srpm_log_url_from_flask(self.srpm_model.id), ) return TaskResults(success=False, details={"msg": msg}) try: build_id, web_url = self.run_build() Pushgateway().push_copr_build_created() except Exception as ex: sentry_integration.send_to_sentry(ex) # TODO: Where can we show more info about failure? # TODO: Retry self.report_status_to_all( state=CommitStatus.error, description=f"Submit of the build failed: {ex}", ) return TaskResults( success=False, details={"msg": "Submit of the Copr build failed.", "error": str(ex)}, ) unprocessed_chroots = [] for chroot in self.build_targets: if chroot not in self.available_chroots: self.report_status_to_all_for_chroot( state=CommitStatus.error, description=f"Not supported target: {chroot}", url=get_srpm_log_url_from_flask(self.srpm_model.id), chroot=chroot, ) unprocessed_chroots.append(chroot) continue copr_build = CoprBuildModel.get_or_create( build_id=str(build_id), commit_sha=self.metadata.commit_sha, project_name=self.job_project, owner=self.job_owner, web_url=web_url, target=chroot, status="pending", srpm_build=self.srpm_model, trigger_model=self.db_trigger, ) url = get_copr_build_info_url_from_flask(id_=copr_build.id) self.report_status_to_all_for_chroot( state=CommitStatus.pending, description="Starting RPM build...", url=url, chroot=chroot, ) if unprocessed_chroots: unprocessed = "\n".join(sorted(unprocessed_chroots)) available = "\n".join(sorted(self.available_chroots)) self.project.pr_comment( pr_id=self.metadata.pr_id, body="There are build targets that are not supported by COPR.\n" "<details>\n<summary>Unprocessed build targets</summary>\n\n" f"```\n{unprocessed}\n```\n</details>\n" "<details>\n<summary>Available build targets</summary>\n\n" f"```\n{available}\n```\n</details>", ) # release the hounds! celery_app.send_task( "task.babysit_copr_build", args=(build_id,), countdown=120, # do the first check in 120s ) return TaskResults(success=True, details={})