From d7fc928e371d3cfcdeb2828d9e37210f2c7b2552 Mon Sep 17 00:00:00 2001 From: Iryna Shustava Date: Mon, 18 Jul 2022 18:40:50 -0600 Subject: [PATCH] Add makefile target to prepare release --- Makefile | 9 +++ .../build-support/functions/10-util.sh | 66 ++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c18927bcf1..1029cd5bf2 100644 --- a/Makefile +++ b/Makefile @@ -99,6 +99,15 @@ ci.aws-acceptance-test-cleanup: ## Deletes AWS resources left behind after faile version: @echo $(VERSION) +# ===========> Release Targets + +prepare-release: ## Sets the versions, updates changelog to prepare this repository to release +ifndef RELEASE_VERSION + $(error RELEASE_VERSION is required) +endif + source $(CURDIR)/control-plane/build-support/scripts/functions.sh; set_release_mode $(CURDIR) $(RELEASE_VERSION) "$(shell date +"%B %d, %Y")" $(PRERELEASE_VERSION) + + # ===========> Makefile config .DEFAULT_GOAL := help diff --git a/control-plane/build-support/functions/10-util.sh b/control-plane/build-support/functions/10-util.sh index a39b2307e7..31c8ce61ae 100644 --- a/control-plane/build-support/functions/10-util.sh +++ b/control-plane/build-support/functions/10-util.sh @@ -638,6 +638,52 @@ function update_version { return $? } +function update_version_helm { + # Arguments: + # $1 - Path to the directory where the root of the Helm chart is + # $2 - Version string + # $3 - PreRelease version (if unset will become an empty string) + # + # Returns: + # 0 - success + # * - error + + if ! test -d "$1" + then + err "ERROR: '$1' is not a directory. update_version_helm must be called with the path to the Helm chart" + return 1 + fi + + if test -z "$2" + then + err "ERROR: The version specified was empty" + return 1 + fi + + local vfile="$1/values.yaml" + local cfile="$1/Chart.yaml" + local version="$2" + local prerelease="$3" + local full_version="$2" + if ! test -z "$3" + then + full_version="$2-$3" + fi + local image_k8s="hashicorp\/consul-k8s-control-plane:$full_version" + + sed_i ${SED_EXT} -e "s/(imageK8S:[[:space:]]*)\"[^\"]*\"/\1${image_k8s}/g" "${vfile}" + sed_i ${SED_EXT} -e "s/(version:[[:space:]]*)[^\"]*/\1${full_version}/g" "${cfile}" + sed_i ${SED_EXT} -e "s/(image:[[:space:]]*hashicorp\/consul-k8s-control-plane:)[^\"]*/\1${full_version}/g" "${cfile}" + + if test -z "$3" + then + sed_i ${SED_EXT} -e "s/(artifacthub.io\/prerelease:[[:space:]]*)[^\"]*/\1false/g" "${cfile}" + else + sed_i ${SED_EXT} -e "s/(artifacthub.io\/prerelease:[[:space:]]*)[^\"]*/\1true/g" "${cfile}" + fi + return $? +} + function set_changelog_version { # Arguments: # $1 - Path to top level Consul source @@ -744,6 +790,8 @@ function set_release_mode { return 1 fi + echo "release version: " $1 $2 $3 $4 + if test -z "$2" then err "ERROR: The version specified was empty" @@ -768,8 +816,22 @@ function set_release_mode { status_stage "==> Updating CHANGELOG.md with release info: ${changelog_vers} (${rel_date})" set_changelog_version "${sdir}" "${changelog_vers}" "${rel_date}" || return 1 - status_stage "==> Updating version/version.go" - if ! update_version "${sdir}/version/version.go" "${vers}" "$4" + status_stage "==> Updating control-plane version/version.go" + if ! update_version "${sdir}/control-plane/version/version.go" "${vers}" "$4" + then + unset_changelog_version "${sdir}" + return 1 + fi + + status_stage "==> Updating cli version/version.go" + if ! update_version "${sdir}/cli/version/version.go" "${vers}" "$4" + then + unset_changelog_version "${sdir}" + return 1 + fi + + status_stage "==> Updating Helm chart versions" + if ! update_version_helm "${sdir}/charts/consul" "${vers}" "$4" then unset_changelog_version "${sdir}" return 1