From 2e1bb89499a61f59ca7f99144cd72e288af94564 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 4 Oct 2023 16:11:02 -0700 Subject: [PATCH] refactor: remove yq dependency --- MODULE.bazel | 4 ++-- bazel/container_structure_test.bzl | 10 +++++----- bazel/test/WORKSPACE.bazel | 3 --- defs.bzl | 2 +- repositories.bzl | 4 +++- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 15bb810a..ce4649e0 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,7 +6,7 @@ module( version = "0.0.0", ) -# To run yq +# To run jq bazel_dep(name = "aspect_bazel_lib", version = "1.28.0") bazel_dep(name = "bazel_skylib", version = "1.4.1") bazel_dep(name = "platforms", version = "0.0.5") @@ -17,4 +17,4 @@ use_repo(ext, "structure_test_toolchains") register_toolchains("@structure_test_toolchains//:all") # 0.5.4 is the first version with bzlmod support -bazel_dep(name = "stardoc", version = "0.5.4", repo_name = "io_bazel_stardoc") +bazel_dep(name = "stardoc", version = "0.5.4", repo_name = "io_bazel_stardoc", dev_dependency = True) diff --git a/bazel/container_structure_test.bzl b/bazel/container_structure_test.bzl index 7ce5f676..8e5ac863 100644 --- a/bazel/container_structure_test.bzl +++ b/bazel/container_structure_test.bzl @@ -27,12 +27,12 @@ CMD_HEAD = [ CMD = """\ readonly st=$(rlocation {st_path}) -readonly yq=$(rlocation {yq_path}) +readonly jq=$(rlocation {jq_path}) readonly image=$(rlocation {image_path}) # When the image points to a folder, we can read the index.json file inside if [[ -d "$image" ]]; then - readonly DIGEST=$("$yq" eval '.manifests[0].digest | sub(":"; "-")' "$image/index.json") + readonly DIGEST=$("$jq" -r '.manifests[0].digest | sub(":"; "-")' "$image/index.json") exec "$st" test --driver {driver} {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@ else exec "$st" test --driver {driver} {fixed_args} $@ @@ -42,7 +42,7 @@ fi def _structure_test_impl(ctx): fixed_args = [] test_bin = ctx.toolchains["@container_structure_test//bazel:structure_test_toolchain_type"].st_info.binary - yq_bin = ctx.toolchains["@aspect_bazel_lib//lib:yq_toolchain_type"].yqinfo.bin + jq_bin = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"].jqinfo.bin image_path = to_rlocation_path(ctx, ctx.file.image) @@ -64,7 +64,7 @@ def _structure_test_impl(ctx): bash_launcher, content = "\n".join(CMD_HEAD) + CMD.format( st_path = to_rlocation_path(ctx, test_bin), - yq_path = to_rlocation_path(ctx, yq_bin), + jq_path = to_rlocation_path(ctx, jq_bin), driver = ctx.attr.driver, image_path = image_path, fixed_args = " ".join(fixed_args), @@ -78,7 +78,7 @@ def _structure_test_impl(ctx): files = ctx.files.image + ctx.files.configs + [ bash_launcher, test_bin, - yq_bin, + jq_bin, ], ).merge(ctx.attr._runfiles.default_runfiles) diff --git a/bazel/test/WORKSPACE.bazel b/bazel/test/WORKSPACE.bazel index f155b516..90c57b1b 100644 --- a/bazel/test/WORKSPACE.bazel +++ b/bazel/test/WORKSPACE.bazel @@ -25,6 +25,3 @@ load("@container_structure_test//:repositories.bzl", "container_structure_test_r container_structure_test_register_toolchain(name = "cst") -load("@aspect_bazel_lib//lib:repositories.bzl", "register_yq_toolchains") - -register_yq_toolchains() diff --git a/defs.bzl b/defs.bzl index 978ea5c2..0b8e2e21 100644 --- a/defs.bzl +++ b/defs.bzl @@ -22,7 +22,7 @@ https://github.com/GoogleContainerTools/container-structure-test#running-file-te """, test = True, toolchains = [ - "@aspect_bazel_lib//lib:yq_toolchain_type", + "@aspect_bazel_lib//lib:jq_toolchain_type", "@bazel_tools//tools/sh:toolchain_type", "@container_structure_test//bazel:structure_test_toolchain_type", ], diff --git a/repositories.bzl b/repositories.bzl index b88f137a..0d8ebee8 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -1,5 +1,5 @@ """Repository rules for fetching pre-built container-test binaries""" - +load("@aspect_bazel_lib//lib:repositories.bzl", "register_jq_toolchains") load("//bazel:toolchains_repo.bzl", "PLATFORMS", "toolchains_repo") # TODO(alexeagle): automate updates when new releases @@ -68,6 +68,8 @@ def container_structure_test_register_toolchain(name, register = True): st_toolchain_name = "structure_test_toolchains" + register_jq_toolchains(register = register) + for platform in PLATFORMS.keys(): structure_test_repositories( name = "{name}_st_{platform}".format(name = name, platform = platform),