async def do(package: Package, build: Build, token: Optional[str]): try: if build.mbs: task_id = await mbs_client.build(token, package.name, build.import_commit.branch, build.import_commit.commit) build.mbs_id = task_id build.status = BuildStatus.BUILDING await build.save() else: default_target = tags.base() if package.repo == Repo.EXTRAS: default_target = tags.extras() target = default_target if not build.force_tag else build.force_tag host = f"git+https://{settings.gitlab_host}{settings.repo_prefix}" source = f"{host}/rpms/{gitlabify(package.name)}.git?#{build.import_commit.commit}" opts = {} if build.scratch: opts["scratch"] = True if build.arch_override: opts["arch_override"] = koji.parse_arches(build.arch_override) task_id = koji_session.build(source, target, opts) build.koji_id = task_id build.status = BuildStatus.BUILDING await build.save() except MBSConflictException: build.status = BuildStatus.CANCELLED await build.save() except Exception: raise
async def sign_mbs_build(build: Build, mbs_build): tasks = mbs_build.get("tasks") if not tasks: return rpms = tasks.get("rpms") if not rpms: return for rpm_name in rpms.keys(): if rpm_name == "module-build-macros": continue rpm = rpms[rpm_name] if rpm["state"] != 1: continue build_rpms = koji_session.listBuildRPMs(rpm["nvr"]) if len(build_rpms) > 0: await sign_build_rpms(build_rpms) package_modules = await PackageModule.filter( module_parent_package_id=build.package.id).prefetch_related( "package").all() for package_module in package_modules: package_module_package = await Package.filter(id=package_module.package.id).first() package_module_package.last_build = datetime.datetime.now() await package_module_package.save() name = mbs_build["name"] name_devel = f"{name}-devel" koji_session.packageListAdd(tags.module_compose(), name, "distrobuild") koji_session.packageListAdd(tags.module_compose(), name_devel, "distrobuild") koji_tag = mbs_build["koji_tag"] context = mbs_build["context"] nvr = koji_tag.replace("module-", "").replace(f"-{context}", f".{context}") nvr_devel = nvr.replace(name, name_devel) koji_session.tagBuild(tags.module_compose(), nvr) koji_session.tagBuild(tags.module_compose(), nvr_devel) build.signed = True await build.save()
async def atomic_sign_unsigned_builds(build: Build): if build.koji_id: koji_session.packageListAdd(tags.compose(), build.package.name, "distrobuild") build_tasks = koji_session.listBuilds(taskID=build.koji_id) for build_task in build_tasks: build_history = koji_session.queryHistory(build=build_task["build_id"]) tag_if_not_tagged(build_history, build_task["nvr"], tags.compose()) build_rpms = koji_session.listBuildRPMs(build_task["build_id"]) await sign_build_rpms(build_rpms) build.signed = True await build.save() elif build.mbs_id: mbs_build = await mbs_client.get_build(build.mbs_id) await sign_mbs_build(build, mbs_build) siblings = mbs_build.get("siblings") if siblings: for sibling in siblings: n_mbs_build = await mbs_client.get_build(sibling) await sign_mbs_build(build, n_mbs_build)
async def atomic_check_build_status(build: Build): if build.koji_id: task_info = koji_session.getTaskInfo(build.koji_id, request=True) if task_info["state"] == koji.TASK_STATES["CLOSED"]: build.status = BuildStatus.SUCCEEDED await build.save() package = await Package.filter(id=build.package_id).get() package.last_build = datetime.datetime.now() await package.save() elif task_info["state"] == koji.TASK_STATES["CANCELED"]: build.status = BuildStatus.CANCELLED await build.save() elif task_info["state"] == koji.TASK_STATES["FAILED"]: try: task_result = koji_session.getTaskResult(build.koji_id) logger.debug(task_result) except (koji.BuildError, xmlrpc.client.Fault): build.status = BuildStatus.FAILED except koji.GenericError: build.status = BuildStatus.CANCELLED finally: await build.save() elif build.mbs_id: build_info = await mbs_client.get_build(build.mbs_id) state = build_info["state_name"] if state == "ready": build.status = BuildStatus.SUCCEEDED await build.save() package = await Package.filter(id=build.package_id).get() package.last_build = datetime.datetime.now() await package.save() elif state == "failed": build.status = BuildStatus.FAILED await build.save()
async def do(build: Build): if build.koji_id and build.scratch and not build.scratch_merged and build.status == BuildStatus.SUCCEEDED: koji_session.mergeScratch(build.koji_id) build.scratch_merged = True await build.save()
async def get_build(build_id: int): return await Build_Pydantic.from_queryset_single( Build.filter(id=build_id).prefetch_related("package", "import_commit").first())
async def list_builds(): return await paginate(Build.all().order_by("-created_at").prefetch_related( "package", "import_commit"))