Ejemplo n.º 1
0
def build(
    config,
    dist_git_path,
    dist_git_branch,
    from_upstream,
    scratch,
    nowait,
    path_or_url,
    koji_target,
):
    """
    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)

    branches_to_build = get_branches(*dist_git_branch.split(","),
                                     default="master")
    click.echo(
        f"Building for the following branches: {', '.join(branches_to_build)}")

    for branch in branches_to_build:
        try:
            out = api.build(
                dist_git_branch=branch,
                scratch=scratch,
                nowait=nowait,
                koji_target=koji_target,
                from_upstream=from_upstream,
            )
        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))
Ejemplo n.º 2
0
def test_ensure_str(inp, exp):
    assert ensure_str(inp) == exp
Ejemplo n.º 3
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))