def st2_pack_archive(**kwargs):
    """Create a makeself_archive using files from the given dependencies.

    This macro should be used in the same BUILD file as the pack_metadata target.
    """
    build_file_path = build_file_dir()  # noqa: F821
    if "st2tests" == build_file_path.parts[0]:
        # avoid creating duplicate archive for the core pack
        # which is also located under st2tests/st2tests/fixtures/packs
        return
    pack_name = build_file_path.name  # noqa: F821

    dependencies = kwargs.pop("dependencies", [])
    if ":metadata" not in dependencies:
        dependencies = [":metadata", *dependencies]

    # This is basically a "wrap_as_files" target (which does not exist yet)
    shell_command(  # noqa: F821
        name="files",
        execution_dependencies=dependencies,
        command="true",
        output_directories=["."],
        root_output_directory=".",
    )

    # https://www.pantsbuild.org/stable/docs/shell/self-extractable-archives
    # https://www.pantsbuild.org/stable/reference/targets/makeself_archive
    makeself_archive(  # noqa: F821
        name="archive",
        label=f"{pack_name} StackStorm pack",
        files=[
            ":files",  # archive contents
            "//:license",  # LICENSE file included in archive header, excluded from contents
        ],
        args=(  # see: https://makeself.io/#usage
            # Makeself expects '--arg value' (space) not '--arg=value' (equals) for cmdline
            "--license",
            "__archive/LICENSE",
            "--target",
            f"/opt/stackstorm/packs/{pack_name}",
            # reproducibility flags:
            "--tar-extra",  # extra tar args: '--arg=value' (equals delimited) space separated
            f"--owner=root --group={ST2_PACKS_GROUP} --mtime={MTIME} --exclude=LICENSE",
            "--packaging-date",
            MTIME,
        ),
        output_path=f"packaging/packs/{pack_name}.tgz.run",
    )

    nfpm_content_file(  # noqa: F821
        name="archive_for_nfpm",
        dependencies=[":archive"],
        src=f"packaging/packs/{pack_name}.tgz.run",
        dst=f"/opt/stackstorm/install/packs/{pack_name}.tgz.run",
        file_owner="root",
        file_group=ST2_PACKS_GROUP,
        file_mode="rwxr-x---",
    )
Create a makeself_archive using files from the given dependencies.

    This macro should be used in the same BUILD file as the pack_metadata target.
    
pants-plugins/macros.py