Пример #1
0
def srpm(
    config,
    output,
    path_or_url,
    upstream_ref,
    bump,
    release_suffix,
    default_release_suffix,
):
    """
    Create new SRPM (.src.rpm file) using content of the upstream repository.

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory
    """
    api = get_packit_api(config=config, local_project=path_or_url)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config,
        release_suffix,
        default_release_suffix,
    )

    srpm_path = api.create_srpm(
        output_file=output,
        upstream_ref=upstream_ref,
        bump_version=bump,
        release_suffix=release_suffix,
    )
    logger.info(f"SRPM: {srpm_path}")
Пример #2
0
def mock(
    config, upstream_ref, release_suffix, default_release_suffix, root, path_or_url
):
    """
    Build RPMs in mock using content of the upstream repository.

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory.
    """
    api = get_packit_api(config=config, local_project=path_or_url)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config, release_suffix, default_release_suffix
    )

    if not config.srpm_path:
        config.srpm_path = api.create_srpm(
            upstream_ref=upstream_ref,
            srpm_dir=api.up.local_project.working_dir,
            release_suffix=release_suffix,
        )

    rpm_paths = api.run_mock_build(root=root, srpm_path=config.srpm_path)
    logger.info("RPMs:")
    for path in rpm_paths:
        logger.info(f" * {path}")
Пример #3
0
def local(config, upstream_ref, release_suffix, default_release_suffix,
          path_or_url):
    """
    Create RPMs using content of the upstream repository.

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory
    """
    api = get_packit_api(config=config, local_project=path_or_url)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config, release_suffix, default_release_suffix)

    rpm_paths = api.create_rpms(
        upstream_ref=upstream_ref,
        release_suffix=release_suffix,
        # srpm_path=config.srpm_path,
    )
    logger.info("RPMs:")
    for path in rpm_paths:
        logger.info(f" * {path}")
Пример #4
0
def prepare_sources(
    config,
    path_or_url,
    job_config_index,
    upstream_ref,
    bump,
    release_suffix,
    default_release_suffix,
    result_dir,
    ref,
    pr_id,
    merge_pr,
    target_branch,
):
    """
    Prepare sources for a new SRPM build using content of the upstream repository.
    Determine version, create an archive or download upstream and create patches for sourcegit,
    fix/update the specfile to use the right archive, download the remote sources.
    Behaviour can be customized by specifying actions (post-upstream-clone, get-current-version,
    create-archive, create-patches, fix-spec-file) in the configuration.

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory
    """

    if not result_dir:
        result_dir = Path.cwd().joinpath("prepare_sources_result")
        logger.debug(f"Setting result_dir to the default one: {result_dir}")
    api = get_packit_api(config=config,
                         local_project=path_or_url,
                         job_config_index=job_config_index)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config, release_suffix, default_release_suffix)

    api.prepare_sources(
        upstream_ref=upstream_ref,
        bump_version=bump,
        release_suffix=release_suffix,
        result_dir=result_dir,
    )
Пример #5
0
def copr(
    config,
    nowait,
    owner,
    project,
    targets,
    description,
    instructions,
    list_on_homepage,
    preserve_project,
    upstream_ref,
    additional_repos,
    request_admin_if_needed,
    enable_net,
    release_suffix,
    default_release_suffix,
    path_or_url,
):
    """
    Build selected upstream project in Copr.

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory.
    """
    api = get_packit_api(config=config, local_project=path_or_url)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config, release_suffix, default_release_suffix
    )

    if not project:
        logger.debug("Copr project name was not passed via CLI.")

        if isinstance(api.package_config, PackageConfig):
            project = api.package_config.get_copr_build_project_value()

        if project:
            logger.debug("Using a first Copr project found in the job configuration.")
        else:
            logger.debug(
                "Copr project not found in the job configuration. "
                "Using the default one."
            )
            sanitized_ref = sanitize_branch_name(path_or_url.ref)
            project = f"packit-cli-{path_or_url.repo_name}-{sanitized_ref}"

    logger.info(f"Using Copr project name = {project}")

    targets_list = targets.split(",")
    for target in targets_list:
        if target in DEPRECATED_TARGET_MAP:
            logger.warning(
                f"Target '{target}' is deprecated. "
                f"Please use '{DEPRECATED_TARGET_MAP[target]}' instead."
            )
    targets_to_build = get_valid_build_targets(
        *targets_list, default="fedora-rawhide-x86_64"
    )

    logger.info(f"Targets to build: {targets_to_build}.")

    additional_repos_list: Optional[List[str]] = (
        additional_repos.split(",") if additional_repos else None
    )

    build_id, repo_url = api.run_copr_build(
        project=project,
        chroots=list(targets_to_build),
        owner=owner,
        description=description,
        instructions=instructions,
        upstream_ref=upstream_ref,
        list_on_homepage=list_on_homepage,
        preserve_project=preserve_project,
        additional_repos=additional_repos_list,
        request_admin_if_needed=request_admin_if_needed,
        enable_net=enable_net,
        release_suffix=release_suffix,
        srpm_path=config.srpm_path,
    )
    click.echo(f"Build id: {build_id}, repo url: {repo_url}")
    if not nowait:
        api.watch_copr_build(build_id=build_id, timeout=60 * 60 * 2)
Пример #6
0
def koji(
    config,
    dist_git_path,
    dist_git_branch,
    from_upstream,
    koji_target,
    scratch,
    nowait,
    release_suffix,
    default_release_suffix,
    path_or_url,
):
    """
    Build selected upstream project in Fedora.

    By default, packit checks out the respective dist-git repository and performs
    `fedpkg build` for the selected branch. With `--from-upstream`, packit creates a SRPM
    out of the current checkout and sends it to koji.

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory
    """
    api = get_packit_api(config=config,
                         dist_git_path=dist_git_path,
                         local_project=path_or_url)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config, release_suffix, default_release_suffix)

    default_dg_branch = api.dg.local_project.git_project.default_branch
    dist_git_branch = dist_git_branch or default_dg_branch
    branches_to_build = get_branches(*dist_git_branch.split(","),
                                     default_dg_branch=default_dg_branch)
    click.echo(
        f"Building from the following branches: {', '.join(branches_to_build)}"
    )

    if koji_target is None:
        targets_to_build = {None}
    else:
        targets_to_build = get_koji_targets(koji_target)

    if len(targets_to_build) > 1 and len(branches_to_build) > 1:
        raise PackitConfigException(
            "Parameters --dist-git-branch and --koji-target cannot have "
            "multiple values at the same time.")

    for target in targets_to_build:
        for branch in branches_to_build:
            try:
                out = api.build(
                    dist_git_branch=branch,
                    scratch=scratch,
                    nowait=nowait,
                    koji_target=target,
                    from_upstream=from_upstream,
                    release_suffix=release_suffix,
                    srpm_path=config.srpm_path,
                )
            except PackitCommandFailedError as ex:
                logs_stdout = "\n>>> ".join(
                    ex.stdout_output.strip().split("\n"))
                logs_stderr = "\n!!! ".join(
                    ex.stderr_output.strip().split("\n"))
                click.echo(
                    f"Build for branch '{branch}' failed. \n"
                    f">>> {logs_stdout}\n"
                    f"!!! {logs_stderr}\n",
                    err=True,
                )
            else:
                if out:
                    print(ensure_str(out))