From 53c225b1987cafaddbd80e29edf3d1a439417944 Mon Sep 17 00:00:00 2001 From: John Murret Date: Thu, 22 Aug 2024 09:59:33 -0600 Subject: [PATCH] add build support script to print out the submodule versions required in other submodules (#21635) * add build support script to print out the submodule versions required in other submodules * update help and usage. exclude current submodule in output. --- build-support/functions/10-util.sh | 18 +++++++ .../consul-module-versions-in-consul.sh | 54 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 build-support/scripts/consul-module-versions-in-consul.sh diff --git a/build-support/functions/10-util.sh b/build-support/functions/10-util.sh index 4bb9f35a9f..8cbcb11c68 100644 --- a/build-support/functions/10-util.sh +++ b/build-support/functions/10-util.sh @@ -667,3 +667,21 @@ function go_mod_assert { fi return 0 } + +function get_consul_module_versions { + local module_directories + module_directories=( "." "api" "envoyextensions" "proto-public" "sdk" "troubleshoot") + for module_dir in "${module_directories[@]}"; do + echo "Module versions for directory: '$module_dir':" + echo "--------------" + (cd "$module_dir" && go list -m all | grep -e github.com/hashicorp/consul/api \ + -e github.com/hashicorp/consul/envoyextensions \ + -e github.com/hashicorp/consul/proto-public \ + -e github.com/hashicorp/consul/sdk \ + -e github.com/hashicorp/consul/troubleshoot \ + | if [ "$module_dir" != "." ]; then grep -v "consul/$module_dir"; else cat; fi) + echo "--------------" + echo "" + done + return 0 +} diff --git a/build-support/scripts/consul-module-versions-in-consul.sh b/build-support/scripts/consul-module-versions-in-consul.sh new file mode 100755 index 0000000000..46941d2413 --- /dev/null +++ b/build-support/scripts/consul-module-versions-in-consul.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + + +readonly SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" +readonly SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" +readonly SOURCE_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")" +readonly FN_DIR="$(dirname "${SCRIPT_DIR}")/functions" + +source "${SCRIPT_DIR}/functions.sh" + +function usage { +cat <<-EOF +Usage: ${SCRIPT_NAME} [] + +Description: + + This script reports the consul module versions in each of the go.mod files in the Consul repository. + +Options: + -h | --help Print this help text. +EOF +} + +function err_usage { + err "$1" + err "" + err "$(usage)" +} + +function main { + while test $# -gt 0 + do + case "$1" in + -h | --help ) + usage + return 0 + ;; + *) + err_usage "ERROR: Unknown argument: '$1'" + return 1 + ;; + esac + done + + get_consul_module_versions || return 1 + + return 0 +} + +main "$@" +exit $? +