Пример #1
0
def test_srpm_commits(upstream, downstream):
    package_config = upstream.package_config
    ChangelogHelper(upstream, downstream,
                    package_config).prepare_upstream_locally(
                        "0.1.0", "abc123a", True, None)
    with upstream._specfile.sections() as sections:
        assert "- Development snapshot (abc123a)" in sections.changelog
Пример #2
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}")
Пример #3
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}")
Пример #4
0
    def fix_spec(
        self,
        archive: str,
        version: str,
        commit: str,
        bump_version: bool = True,
        release_suffix: Optional[str] = None,
    ):
        """
        In order to create a SRPM from current git checkout, we need to have the spec reference
        the tarball and unpack it. This method updates the spec so it's possible.

        Args:
            archive: Relative path to the archive, used as `Source0`.
            version: Version to be set in the spec-file.
            commit: Commit to be set in the changelog.
            bump_version: Specifies whether version should be changed in the spec-file.

                Defaults to `True`.
            release_suffix: Specifies local release suffix.

                Defaults to `None`, which means default generated suffix is used.
        """
        self._fix_spec_source(archive)
        self._fix_spec_prep(archive)

        ChangelogHelper(self).prepare_upstream_locally(
            version, commit, bump_version, release_suffix
        )
Пример #5
0
    def _prepare_files_to_sync(self, synced_files: List[SyncFilesItem],
                               full_version: str,
                               upstream_tag: str) -> List[SyncFilesItem]:
        """Update the spec-file by setting the version and updating the changelog

        Skip everything if the changelog should be synced from upstream.

        Args:
            synced_files: A list of SyncFilesItem.
            full_version: Version to be set in the spec-file.
            upstream_tag: The commit message of this commit is going to be used
                to update the changelog in the spec-file.

        Returns:
            The list of synced files with the spec-file removed if it was updated.
        """
        if self.package_config.sync_changelog:
            return synced_files

        # add entry to changelog
        ChangelogHelper(self.up, self.dg, self.package_config).update_dist_git(
            full_version=full_version, upstream_tag=upstream_tag)

        # exclude spec, we have special plans for it
        return list(
            filter(None, [
                x.drop_src(self.up.absolute_specfile_path)
                for x in synced_files
            ]))
Пример #6
0
def test_srpm_no_bump(upstream, downstream):
    package_config = upstream.package_config
    flexmock(upstream).should_receive("get_last_tag").and_return(None).once()

    ChangelogHelper(upstream, downstream,
                    package_config).prepare_upstream_locally(
                        "0.1.0", "abc123a", False, None)
    with upstream._specfile.sections() as sections:
        assert "- Development snapshot (abc123a)" not in sections.changelog
Пример #7
0
def test_srpm_no_tags(upstream, downstream):
    package_config = upstream.package_config
    flexmock(upstream).should_receive("get_last_tag").and_return(None).once()

    ChangelogHelper(upstream, downstream,
                    package_config).prepare_upstream_locally(
                        "0.1.0", "abc123a", True, None)
    assert ("- Development snapshot (abc123a)"
            in upstream._specfile.spec_content.section("%changelog"))
Пример #8
0
def test_do_not_update_distgit_with_autochangelog(
        upstream, distgit_instance_with_autochangelog):
    _, downstream = distgit_instance_with_autochangelog
    package_config = upstream.package_config

    ChangelogHelper(upstream, downstream,
                    package_config).update_dist_git(upstream_tag="0.1.0",
                                                    full_version="0.1.0")

    with downstream._specfile.sections() as sections:
        assert "%autochangelog" in sections.changelog
Пример #9
0
    def _prepare_upstream_using_source_git(
        self, bump_version: bool, release_suffix: Optional[str]
    ) -> None:
        """
        Fetch the tarball and don't check out the upstream ref.
        """
        self.upstream.fetch_upstream_archive()
        self.upstream.create_patches_and_update_specfile(self.upstream_ref)

        ChangelogHelper(self.upstream).prepare_upstream_using_source_git(
            bump_version, release_suffix
        )
Пример #10
0
def test_srpm_action(upstream, downstream):
    package_config = upstream.package_config
    package_config.actions = {
        ActionName.changelog_entry: [
            "echo - hello from test_srpm_action   ",
        ]
    }

    ChangelogHelper(upstream, downstream,
                    package_config).prepare_upstream_locally(
                        "0.1.0", "abc123a", True, None)
    with upstream._specfile.sections() as sections:
        assert "- hello from test_srpm_action" in sections.changelog
Пример #11
0
def test_update_distgit_when_copy_upstream_release_description(
        upstream, distgit_instance):
    _, downstream = distgit_instance
    package_config = upstream.package_config
    package_config.copy_upstream_release_description = True
    upstream.local_project.git_project = (
        flexmock().should_receive("get_release").with_args(
            tag_name="0.1.0", name="0.1.0").and_return(
                flexmock(body="Some release 0.1.0")).mock())

    ChangelogHelper(upstream, downstream,
                    package_config).update_dist_git(upstream_tag="0.1.0",
                                                    full_version="0.1.0")

    with downstream._specfile.sections() as sections:
        assert "Some release 0.1.0" in sections.changelog
Пример #12
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}")
Пример #13
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,
    )
Пример #14
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)
Пример #15
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))