def storeArtifacts(args, workspace_info):
    directory = args.artifacts_directory
    if not os.path.exists(directory):
        os.makedirs(directory)
    shutil.copy(
        "bazel-bin/packages/{}/tar-package-symbol.tar.xz".format(args.variant),
        os.path.join(directory, version.tarFileName(workspace_info,
                                                    symbol=True)),
    )
    shutil.copy(
        "bazel-bin/packages/{}/tar-package-stripped.tar.xz".format(
            args.variant),
        os.path.join(directory, version.tarFileName(workspace_info)),
    )
    if args.build_deb_package:
        shutil.copy(
            "bazel-bin/packages/{}/deb-package.deb".format(args.variant),
            os.path.join(directory, version.debFileName(workspace_info)),
        )
    if args.build_rpm_package:
        shutil.copy(
            "bazel-bin/packages/{}/rpm-package.rpm".format(args.variant),
            os.path.join(directory, version.rpmFileName(workspace_info)),
        )
    if args.build_distroless_docker:
        docker_image_tar = os.path.join(
            directory, version.distrolessFileName(workspace_info))
        shutil.copy(
            "bazel-bin/packages/{}/distroless-package.tar".format(
                args.variant),
            docker_image_tar,
        )
        subprocess.check_call(["xz", "-f", docker_image_tar])
    if args.build_istio_compat:
        shutil.copy(
            "bazel-bin/packages/{}/istio-tar-package-symbol.tar.gz".format(
                args.variant),
            os.path.join(directory,
                         version.istioTarFileName(workspace_info,
                                                  symbol=True)),
        )
        shutil.copy(
            "bazel-bin/packages/{}/istio-tar-package-stripped.tar.gz".format(
                args.variant),
            os.path.join(directory, version.istioTarFileName(workspace_info)),
        )
def uploadArtifacts(args, workspace_info):
    directory = args.artifacts_directory
    override_args = []
    if args.override:
        override_args = ['--override']
    exists = subprocess.call([
        './bintray_uploader.py', '--version',
        version.debVersion(workspace_info),
        os.path.join(directory, version.tarFileName(workspace_info))
    ] + override_args)
    if exists != 0:
        return
    exists = subprocess.call([
        './bintray_uploader.py',
        '--version',
        version.debVersion(workspace_info),
        os.path.join(directory, version.tarFileName(workspace_info,
                                                    symbol=True)),
    ] + override_args)
    if exists != 0:
        return
    if args.build_deb_package:
        subprocess.check_call([
            './bintray_uploader_deb.py',
            '--variant',
            workspace_info['variant'],
            '--deb_version',
            version.debVersion(workspace_info),
            '--release_level',
            args.release_level,
            os.path.join(directory, version.debFileName(workspace_info)),
        ])
    if args.build_rpm_package:
        subprocess.check_call([
            './bintray_uploader_rpm.py',
            '--variant',
            workspace_info['variant'],
            '--rpm_version',
            workspace_info['source_version'],
            '--rpm_release',
            workspace_info['getenvoy_release'],
            '--release_level',
            args.release_level,
            os.path.join(directory, version.rpmFileName(workspace_info)),
        ])
    if args.build_distroless_docker:
        docker_image_tar = os.path.join(
            directory, version.distrolessFileName(workspace_info))
        load_cmd = 'xzcat "{}.xz" | docker load'.format(docker_image_tar)
        subprocess.check_call(load_cmd, shell=True)
        subprocess.check_call([
            './docker_upload.py', '--docker_version',
            version.dockerVersion(workspace_info), '--variant',
            workspace_info['variant'],
            version.dockerTag(workspace_info)
        ])
    if args.build_istio_compat:
        subprocess.call([
            './bintray_uploader.py',
            '--version',
            version.debVersion(workspace_info),
            os.path.join(directory,
                         version.istioTarFileName(workspace_info,
                                                  symbol=True)),
        ] + override_args)
        # Istio doesn't have a concept of debug stripped builds.
        if workspace_info["release_level"] == "stable":
            subprocess.call([
                './bintray_uploader.py',
                '--version',
                version.debVersion(workspace_info),
                os.path.join(directory, version.istioTarFileName(
                    workspace_info)),
            ] + override_args)
def uploadArtifacts(args, workspace_info):
    directory = args.artifacts_directory
    override_args = []
    if args.override:
        override_args = ["--override"]
    for filename in [
            os.path.join(directory, version.tarFileName(workspace_info)),
            os.path.join(directory,
                         version.tarFileName(workspace_info, symbol=True)),
    ]:
        exists = subprocess.call([
            "./cloudsmith_uploader.py",
            "--raw",
            "--version",
            version.debVersion(workspace_info),
            filename,
        ] + override_args)
        if exists != 0:
            return
    if args.build_deb_package:
        subprocess.check_call([
            "./cloudsmith_uploader.py",
            "--deb",
            "--variant",
            workspace_info["variant"],
            "--version",
            version.debVersion(workspace_info),
            "--release_level",
            args.release_level,
            os.path.join(directory, version.debFileName(workspace_info)),
        ])
    if args.build_rpm_package:
        subprocess.check_call([
            "./cloudsmith_uploader_rpm.py",
            "--rpm",
            "--variant",
            workspace_info["variant"],
            "--version",
            workspace_info["source_version"],
            "--release_level",
            args.release_level,
            os.path.join(directory, version.rpmFileName(workspace_info)),
        ])
    if args.build_distroless_docker:
        docker_image_tar = os.path.join(
            directory, version.distrolessFileName(workspace_info))
        load_cmd = 'xzcat "{}.xz" | docker load'.format(docker_image_tar)
        subprocess.check_call(load_cmd, shell=True)
        subprocess.check_call([
            "./docker_upload.py",
            "--docker_version",
            version.dockerVersion(workspace_info),
            "--variant",
            workspace_info["variant"],
            version.dockerTag(workspace_info),
        ])
    if args.build_istio_compat:
        subprocess.call([
            "./cloudsmith_uploader.py",
            "--raw",
            "--version",
            version.debVersion(workspace_info),
            os.path.join(directory,
                         version.istioTarFileName(workspace_info,
                                                  symbol=True)),
        ] + override_args)
        # Istio doesn't have a concept of debug stripped builds.
        if workspace_info["release_level"] == "stable":
            subprocess.call([
                "./cloudsmith_uploader.py",
                "--raw",
                "--version",
                version.debVersion(workspace_info),
                os.path.join(directory, version.istioTarFileName(
                    workspace_info)),
            ] + override_args)