From c7457bd9421099097437a6a31d17f44211ac91b8 Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Thu, 6 Jul 2023 08:46:06 +0200 Subject: [PATCH] bazel: fill microservice version on `devbuild` target (#1994) * wip: fill microservice version on devbuild * fill microservice versin on `devbuild` --- WORKSPACE.bazel | 3 +++ bazel/devbuild/BUILD.bazel | 3 +++ bazel/devbuild/prepare_developer_workspace.sh.in | 12 ++++++++++++ bazel/sh/def.bzl | 3 +++ 4 files changed, 21 insertions(+) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 29aead515..2c1b09e15 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -153,10 +153,13 @@ oci_register_toolchains( crane_version = LATEST_CRANE_VERSION, ) +load("@aspect_bazel_lib//lib:repositories.bzl", "register_yq_toolchains") load("//bazel/toolchains:container_images.bzl", "containter_image_deps") containter_image_deps() +register_yq_toolchains() + # Multirun load("//bazel/toolchains:multirun_deps.bzl", "multirun_deps") diff --git a/bazel/devbuild/BUILD.bazel b/bazel/devbuild/BUILD.bazel index 63411728c..dbd51a8b2 100644 --- a/bazel/devbuild/BUILD.bazel +++ b/bazel/devbuild/BUILD.bazel @@ -10,6 +10,7 @@ sh_template( "//cli:cli_edition_host", "//debugd/cmd/cdbg:cdbg_host", "//upgrade-agent/cmd:upgrade_agent_linux_amd64", + "@yq_toolchains//:resolved_toolchain", ], substitutions = { "@@BOOTSTRAPPER@@": "$(rootpath //bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64)", @@ -18,8 +19,10 @@ sh_template( "@@CONTAINER_SUMS@@": "$(rootpath //bazel/release:container_sums)", "@@EDITION@@": "$(rootpath :devbuild_cli_edition)", "@@UPGRADE_AGENT@@": "$(rootpath //upgrade-agent/cmd:upgrade_agent_linux_amd64)", + "@@YQ@@": "$(YQ_BIN)", }, template = "prepare_developer_workspace.sh.in", + toolchains = ["@yq_toolchains//:resolved_toolchain"], visibility = ["//visibility:public"], ) diff --git a/bazel/devbuild/prepare_developer_workspace.sh.in b/bazel/devbuild/prepare_developer_workspace.sh.in index 6a57dc96d..b1fed4b7c 100755 --- a/bazel/devbuild/prepare_developer_workspace.sh.in +++ b/bazel/devbuild/prepare_developer_workspace.sh.in @@ -8,6 +8,9 @@ lib=$(realpath @@BASE_LIB@@) || exit 1 stat "${lib}" >> /dev/null || exit 1 +yq=$(realpath @@YQ@@) +stat "${yq}" >> /dev/null + # shellcheck source=../sh/lib.bash if ! source "${lib}"; then echo "Error: could not find import" @@ -59,3 +62,12 @@ ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${upgrade_agent}")" ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cdbg}")" "${workdir}/cdbg" ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${container_sums}")" "${workdir}/container_sums.sha256" ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cli}")" "${workdir}/constellation" + +build_version=$("${workdir}"/constellation version | grep ^Version: | awk '{print $2}') +if [[ ! -f "${workdir}/constellation-conf.yaml" ]]; then + echo "constellation-conf.yaml not present in workspace" + echo "Build version: ${build_version}" +else + $yq -i eval ".microserviceVersion=\"${build_version}\"" ./constellation-conf.yaml + echo "Microservice version updated to ${build_version} in constellation-conf.yaml" +fi diff --git a/bazel/sh/def.bzl b/bazel/sh/def.bzl index 6376a7704..18e0a8074 100644 --- a/bazel/sh/def.bzl +++ b/bazel/sh/def.bzl @@ -8,6 +8,7 @@ def _sh_template_impl(ctx): substitutions = {} for k, v in ctx.attr.substitutions.items(): sub = ctx.expand_location(v, ctx.attr.data) + sub = ctx.expand_make_variables("substitutions", sub, {}) substitutions[k] = sub ctx.actions.expand_template( @@ -50,6 +51,7 @@ def sh_template(name, **kwargs): substitutions = kwargs.pop("substitutions", []) substitutions["@@BASE_LIB@@"] = "$(rootpath //bazel/sh:base_lib)" template = kwargs.pop("template", []) + toolchains = kwargs.pop("toolchains", []) _sh_template( name = script_name, @@ -57,6 +59,7 @@ def sh_template(name, **kwargs): data = data, substitutions = substitutions, template = template, + toolchains = toolchains, ) native.sh_binary(