How to use the packit.actions.ActionName function in packit

To help you get started, we’ve selected a few packit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github packit-service / packit / tests / integration / test_actions.py View on Github external
        (ActionName.fix_spec, "true", {}, False),
        (ActionName.fix_spec, "git this-is-not-a-command", {}, True),
        (ActionName.fix_spec, "printenv E", {"E": "e"}, False),
        (ActionName.fix_spec, "printenv E", {"X": "e"}, True),
    ),
)
def test_with_action(
    upstream_instance, action: ActionName, command, env_vars: Dict, should_raise
):
    _, upstream = upstream_instance
    upstream.package_config.actions = {action: command}
    try:
        upstream.with_action(action, env=env_vars)
    except PackitException as ex:
        if should_raise:
            assert "Command " in str(ex)
            assert command.split(" ")[0] in str(ex)
github packit-service / packit / tests / unit / test_base_git.py View on Github external
def distgit_with_actions():
    return DistGit(
        config=flexmock(Config()),
        package_config=flexmock(
            PackageConfig(
                downstream_package_name="beer",
                actions={
                    ActionName.pre_sync: "command --a",
                    ActionName.get_current_version: "command --b",
                },
github packit-service / packit / tests / integration / test_base_git.py View on Github external
def test_run_in_sandbox():
    packit_repository_base = PackitRepositoryBase(
        config=Config(),
        package_config=PackageConfig(actions={ActionName.pre_sync: "ls -lha"}),
    )
    packit_repository_base.config.actions_handler = "sandcastle"

    result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
    assert "total 4.0K" in result
    assert "drwxr-xr-x. 1 root root" in result
github packit-service / packit / tests / integration / test_actions.py View on Github external
        (ActionName.post_upstream_clone, "printenv E", {"X": "e"}, True, ""),
    ),
)
def test_get_output_from_action(
    upstream_instance,
    action: ActionName,
    command,
    env_vars: Dict,
    should_raise,
    expected_output: str,
):
    _, upstream = upstream_instance
    upstream.package_config.actions = {action: command}
    try:
        out = upstream.get_output_from_action(action, env=env_vars)
    except PackitException as ex:
        if should_raise:
github packit-service / packit / packit / api.py View on Github external
if not full_version:
            raise PackitException(
                "Could not figure out version of latest upstream release."
            )
        current_up_branch = self.up.active_branch
        try:
            upstream_tag = self.up.package_config.upstream_tag_template.format(
                version=full_version
            )
            if not use_local_content:
                self.up.local_project.checkout_release(upstream_tag)

            self.dg.check_last_commit()

            self.up.run_action(actions=ActionName.pre_sync)
            self.dg.create_branch(
                dist_git_branch,
                base=f"remotes/origin/{dist_git_branch}",
                setup_tracking=True,
            )

            # fetch and reset --hard upstream/$branch?
            logger.info(f"Using {dist_git_branch!r} dist-git branch.")
            self.dg.update_branch(dist_git_branch)
            self.dg.checkout_branch(dist_git_branch)

            if create_pr:
                local_pr_branch = f"{full_version}-{dist_git_branch}-update"
                self.dg.create_branch(local_pr_branch)
                self.dg.checkout_branch(local_pr_branch)
github packit-service / packit / packit / api.py View on Github external
Path(self.up.local_project.working_dir),
                    Path(self.dg.local_project.working_dir),
                )
                sync_files(raw_sync_files)
                if upstream_ref:
                    if self.up.with_action(action=ActionName.create_patches):
                        patches = self.up.create_patches(
                            upstream=upstream_ref, destination=self.dg.specfile_dir
                        )
                        self.dg.add_patches_to_specfile(patches)

                self._handle_sources(
                    add_new_sources=True, force_new_sources=force_new_sources
                )

            if self.up.has_action(action=ActionName.prepare_files):
                raw_sync_files = self.package_config.synced_files.get_raw_files_to_sync(
                    Path(self.up.local_project.working_dir),
                    Path(self.dg.local_project.working_dir),
                )
                sync_files(raw_sync_files)

            self.dg.commit(title=f"{full_version} upstream release", msg=description)

            self.push_and_create_pr(
                pr_title=f"Update to upstream release {full_version}",
                pr_description=description,
                dist_git_branch=dist_git_branch,
            )
        finally:
            if not use_local_content:
                self.up.local_project.git_repo.git.checkout(current_up_branch)
github packit-service / packit / packit / upstream.py View on Github external
repository, only committed changes are present in the archive.
        """
        version = version or self.get_current_version()

        package_name = (
            self.package_config.upstream_package_name
            or self.package_config.downstream_package_name
        )
        dir_name = f"{package_name}-{version}"
        logger.debug(f"Name + version = {dir_name}")

        env = {
            "PACKIT_PROJECT_VERSION": version,
            "PACKIT_PROJECT_NAME_VERSION": dir_name,
        }
        if self.has_action(action=ActionName.create_archive):
            outputs = self.get_output_from_action(
                action=ActionName.create_archive, env=env
            )
            if not outputs:
                raise PackitException("No output from create-archive action.")

            archive_path = self._get_archive_path_from_output(outputs)
            if not archive_path:
                raise PackitException(
                    "The create-archive action did not output a path to the generated archive. "
                    "Please make sure that you have valid path in the single line of the output."
                )
            self._add_link_to_archive_from_specdir_if_needed(archive_path)
            return archive_path.name

        return self._create_archive_using_default_way(dir_name, env, version)
github packit-service / packit / packit / upstream.py View on Github external
def create_patches_and_update_specfile(self, upstream_ref) -> None:
        """
        Create patches for the sourcegit and add them to the specfile.

        :param upstream_ref: the base git ref for the source git
        """
        if self.with_action(action=ActionName.create_patches):
            patches = self.create_patches(
                upstream=upstream_ref, destination=str(self.absolute_specfile_dir)
            )
            self.specfile_add_patches(patches)
github packit-service / packit / packit / upstream.py View on Github external
def get_current_version(self) -> str:
        """
        Get version of the project in current state (hint `git describe`)

        :return: e.g. 0.1.1.dev86+ga17a559.d20190315 or 0.6.1.1.gce4d84e
        """
        action_output = self.get_output_from_action(
            action=ActionName.get_current_version
        )
        if action_output:
            return action_output[-1].strip()

        logger.debug(
            f"We're about to `git-describe` the upstream repository "
            f"{self.local_project.working_dir}."
        )
        logger.debug(f"Content: {os.listdir(self.local_project.working_dir)}")

        # let's inspect tags in the repo and log our findings
        cmd = ["git", "--no-pager", "tag", "--list"]
        tags = self.command_handler.run_command(
            cmd, return_output=True, cwd=self.local_project.working_dir
        ).strip()
        if tags: