Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mw/release scripting #1526

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Month> <Day>, <Year> (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 <Month> <Day>, <Year> (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)
Expand Down
3 changes: 0 additions & 3 deletions control-plane/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
163 changes: 92 additions & 71 deletions control-plane/build-support/functions/10-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
112 changes: 0 additions & 112 deletions control-plane/build-support/scripts/dev.sh

This file was deleted.