diff --git a/Makefile b/Makefile index 9d30251581..323bfc96b3 100644 --- a/Makefile +++ b/Makefile @@ -143,13 +143,27 @@ prepare-release: ## Sets the versions, updates changelog to prepare this reposit 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) +ifndef RELEASE_DATE + $(error RELEASE_DATE is required, use format , (ex. October 4, 2022)) +endif + source $(CURDIR)/control-plane/build-support/scripts/functions.sh; prepare_release $(CURDIR) $(RELEASE_VERSION) "$(RELEASE_DATE)" $(PRERELEASE_VERSION) +prepare-dev: +ifndef RELEASE_VERSION + $(error RELEASE_VERSION is required) +endif +ifndef RELEASE_DATE + $(error RELEASE_DATE is required, use format , (ex. October 4, 2022)) +endif +ifndef NEXT_RELEASE_VERSION + $(error NEXT_RELEASE_VERSION is required) +endif + source $(CURDIR)/control-plane/build-support/scripts/functions.sh; prepare_dev $(CURDIR) $(RELEASE_VERSION) "$(RELEASE_DATE)" $(NEXT_RELEASE_VERSION) $(PRERELEASE_VERSION) # ===========> Makefile config .DEFAULT_GOAL := help -.PHONY: gen-helm-docs copy-crds-to-chart bats-tests help ci.aws-acceptance-test-cleanup version cli-dev +.PHONY: gen-helm-docs copy-crds-to-chart bats-tests help ci.aws-acceptance-test-cleanup version cli-dev prepare-dev prepare-release SHELL = bash GOOS?=$(shell go env GOOS) GOARCH?=$(shell go env GOARCH) diff --git a/control-plane/Makefile b/control-plane/Makefile index c2177b722f..7dd5ef80d3 100644 --- a/control-plane/Makefile +++ b/control-plane/Makefile @@ -24,9 +24,6 @@ CI_DEV_DOCKER_WORKDIR?=. CONSUL_K8S_IMAGE_VERSION?=latest ################ -ci.dev-tree: - @$(SHELL) $(CURDIR)/build-support/scripts/dev.sh $(DEV_PUSH_ARG) - # TODO: Remove this ci.dev-docker target once we move the acceptance tests to Github Actions. # In CircleCI, the linux binary will be attached from a previous step at pkg/bin/linux_amd64/. This make target # should only run in CI and not locally. diff --git a/control-plane/build-support/functions/10-util.sh b/control-plane/build-support/functions/10-util.sh index fac66227c3..90cfd9660e 100644 --- a/control-plane/build-support/functions/10-util.sh +++ b/control-plane/build-support/functions/10-util.sh @@ -772,7 +772,86 @@ function add_unreleased_to_changelog { return $ret } -function set_release_mode { +function set_version { + # Arguments: + # $1 - Path to top level Consul source + # $2 - The version of the release + # $3 - The release date + # $4 - The pre-release version + # + # + # Returns: + # 0 - success + # * - error + + if ! test -d "$1" + then + err "ERROR: '$1' is not a directory. prepare_release must be called with the path to a git repo as the first argument" + return 1 + fi + + if test -z "$2" + then + err "ERROR: The version specified was empty" + return 1 + fi + + local sdir="$1" + local vers="$2" + + status_stage "==> Updating control-plane version/version.go with version info: ${vers} "$4"" + 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 with version info: ${vers} "$4"" + if ! update_version "${sdir}/cli/version/version.go" "${vers}" "$4" + then + unset_changelog_version "${sdir}" + return 1 + fi + + status_stage "==> Updating Helm chart versions with version info: ${vers} "$4"" + if ! update_version_helm "${sdir}/charts/consul" "${vers}" "$4" + then + unset_changelog_version "${sdir}" + return 1 + fi + + return 0 +} + +function set_changelog { + # Arguments: + # $1 - Path to top level Consul source + # $2 - The version of the release + # $3 - The release date + # $4 - The pre-release version + # + # + # Returns: + # 0 - success + # * - error + local sdir="$1" + local vers="$2" + local rel_date="$(date +"%B %d, %Y")" + if test -n "$3" + then + rel_date="$3" + fi + + local changelog_vers="${vers}" + if test -n "$4" + then + changelog_vers="${vers}-$4" + fi + status_stage "==> Updating CHANGELOG.md with release info: ${changelog_vers} (${rel_date})" + set_changelog_version "${sdir}" "${changelog_vers}" "${rel_date}" || return 1 +} + +function prepare_release { # Arguments: # $1 - Path to top level Consul source # $2 - The version of the release @@ -783,90 +862,32 @@ function set_release_mode { # Returns: # 0 - success # * - error - - if ! test -d "$1" - then - err "ERROR: '$1' is not a directory. set_release_mode must be called with the path to a git repo as the first argument" - return 1 - fi - - echo "release version: " $1 $2 $3 $4 - - if test -z "$2" - then - err "ERROR: The version specified was empty" - return 1 - fi - - local sdir="$1" - local vers="$2" - local rel_date="$(date +"%B %d, %Y")" - - if test -n "$3" - then - rel_date="$3" - fi - - local changelog_vers="${vers}" - if test -n "$4" - then - changelog_vers="${vers}-$4" - fi - - 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 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 - fi - - return 0 + echo "release version: " $1 $2 $3 $4 + set_version "$1" "$2" "$3" "$4" + set_changelog "$1" "$2" "$3" "$4" } -function set_dev_mode { +function prepare_dev { # Arguments: # $1 - Path to top level Consul source + # $2 - The version of the release + # $3 - The release date + # $4 - The version of the next release + # $5 - The pre-release version (for setting beta in changelog) # # Returns: # 0 - success # * - error - if ! test -d "$1" - then - err "ERROR: '$1' is not a directory. set_dev_mode must be called with the path to a git repo as the first argument'" - return 1 - fi + echo "dev version: " $1 $4 $3 "dev" local sdir="$1" - local vers="$(parse_version "${sdir}" false false)" - - status_stage "==> Setting VersionPreRelease back to 'dev' for Control Plane" - update_version "${sdir}/version/version.go" "${vers}" dev || return 1 - # This function has been modified for Consul-K8s monorepo. It now sets dev mode - # for the CLI module as well. - status_stage "==> Setting VersionPreRelease back to 'dev' for CLI" - update_version "${sdir}/../cli/version/version.go" "${vers}" dev || return 1 + set_changelog "$1" "$2" "$3" "$5" + set_version "$1" "$4" "$3" "dev" status_stage "==> Adding new UNRELEASED label in CHANGELOG.md" - add_unreleased_to_changelog "${sdir}/.." || return 1 + add_unreleased_to_changelog "${sdir}" || return 1 return 0 } diff --git a/control-plane/build-support/scripts/dev.sh b/control-plane/build-support/scripts/dev.sh deleted file mode 100755 index 7cb79d01e1..0000000000 --- a/control-plane/build-support/scripts/dev.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash -SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})" -pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null -SCRIPT_DIR=$(pwd) -pushd ../.. > /dev/null -SOURCE_DIR=$(pwd) -popd > /dev/null -pushd ../functions > /dev/null -FN_DIR=$(pwd) -popd > /dev/null -popd > /dev/null - -source "${SCRIPT_DIR}/functions.sh" - -function usage { -cat <<-EOF -Usage: ${SCRIPT_NAME} [] - -Description: - - This script will put the source back into dev mode after a release. - -Options: - - -s | --source DIR Path to source to build. - Defaults to "${SOURCE_DIR}" - - --no-git Do not commit or attempt to push - the changes back to the upstream. - - -h | --help Print this help text. -EOF -} - -function err_usage { - err "$1" - err "" - err "$(usage)" -} - -function main { - declare sdir="${SOURCE_DIR}" - declare build_os="" - declare build_arch="" - declare -i do_git=1 - declare -i do_push=1 - - - while test $# -gt 0 - do - case "$1" in - -h | --help ) - usage - return 0 - ;; - -s | --source ) - if test -z "$2" - then - err_usage "ERROR: option -s/--source requires an argument" - return 1 - fi - - if ! test -d "$2" - then - err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source" - return 1 - fi - - sdir="$2" - shift 2 - ;; - --no-git ) - do_git=0 - shift - ;; - --no-push ) - do_push=0 - shift - ;; - * ) - err_usage "ERROR: Unknown argument: '$1'" - return 1 - ;; - esac - done - - # Set dev mode for both CLI and Control Plane modules - set_dev_mode "${sdir}" || return 1 - - - if is_set "${do_git}" - then - status_stage "==> Commiting Dev Mode Changes" - # Currently ${sdir} is consul-k8s/control-plane, but for git functions we should be in top-level, so we pass in "${sdir}/..". - # This will commit `version.go` for both CLI and Control Plane modules as well as the CHANGELOG.md. - commit_dev_mode "${sdir}/.." || return 1 - - if is_set "${do_push}" - then - status_stage "==> Confirming Git Changes" - confirm_git_push_changes "${sdir}/.." || return 1 - - status_stage "==> Pushing to Git" - git_push_ref "${sdir}/.." || return 1 - fi - fi - - return 0 -} - -main "$@" -exit $?