2023-03-28 22:48:58 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
function err {
|
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput bold
|
|
|
|
tput setaf 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
echo "$@" 1>&2
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput sgr0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function status {
|
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput bold
|
|
|
|
tput setaf 4
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
echo "$@"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput sgr0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function status_stage {
|
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput bold
|
|
|
|
tput setaf 2
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
echo "$@"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput sgr0
|
2018-10-19 16:04:07 +00:00
|
|
|
fi
|
2018-06-12 20:55:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
function debug {
|
|
|
|
if is_set "${BUILD_DEBUG}"
|
|
|
|
then
|
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput setaf 6
|
|
|
|
fi
|
|
|
|
echo "$@"
|
|
|
|
if test "${COLORIZE}" -eq 1
|
|
|
|
then
|
|
|
|
tput sgr0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-09-20 18:37:22 +00:00
|
|
|
function debug_run {
|
|
|
|
debug "$@"
|
2019-10-08 17:42:29 +00:00
|
|
|
"$@"
|
2019-09-20 18:37:22 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2022-04-05 16:58:07 +00:00
|
|
|
function print_run {
|
|
|
|
echo "$@"
|
|
|
|
"$@"
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2018-06-25 14:01:20 +00:00
|
|
|
function sed_i {
|
|
|
|
if test "$(uname)" == "Darwin"
|
|
|
|
then
|
|
|
|
sed -i '' "$@"
|
|
|
|
return $?
|
|
|
|
else
|
|
|
|
sed -i "$@"
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
function is_set {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - string value to check its truthiness
|
|
|
|
#
|
|
|
|
# Return:
|
|
|
|
# 0 - is truthy (backwards I know but allows syntax like `if is_set <var>` to work)
|
|
|
|
# 1 - is not truthy
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
local val=$(tr '[:upper:]' '[:lower:]' <<< "$1")
|
|
|
|
case $val in
|
|
|
|
1 | t | true | y | yes)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
function have_gpg_key {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - GPG Key id to check if we have installed
|
|
|
|
#
|
|
|
|
# Return:
|
|
|
|
# 0 - success (we can use this key for signing)
|
|
|
|
# * - failure (key cannot be used)
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
gpg --list-secret-keys $1 > /dev/null 2>&1
|
2018-06-12 20:55:52 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function parse_version {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to the top level Consul source
|
2018-06-13 19:10:02 +00:00
|
|
|
# $2 - boolean value for whether the release version should be parsed from the source
|
2020-07-14 19:17:45 +00:00
|
|
|
# $3 - boolean whether to use GIT_COMMIT environment variable
|
2018-06-18 21:01:20 +00:00
|
|
|
# $4 - boolean whether to omit the version part of the version string. (optional)
|
2018-06-12 20:55:52 +00:00
|
|
|
#
|
|
|
|
# Return:
|
|
|
|
# 0 - success (will write the version to stdout)
|
|
|
|
# * - error (no version output)
|
|
|
|
#
|
|
|
|
# Notes:
|
|
|
|
# If the GOTAGS environment variable is present then it is used to determine which
|
|
|
|
# version file to use for parsing.
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
local vfile="${1}/version/version.go"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
# ensure the version file exists
|
|
|
|
if ! test -f "${vfile}"
|
|
|
|
then
|
|
|
|
err "Error - File not found: ${vfile}"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
local include_release="$2"
|
|
|
|
local use_git_env="$3"
|
2018-06-18 21:01:20 +00:00
|
|
|
local omit_version="$4"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
local git_commit=""
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
if test -z "${include_release}"
|
|
|
|
then
|
|
|
|
include_release=true
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
if test -z "${use_git_env}"
|
|
|
|
then
|
|
|
|
use_git_env=true
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
if is_set "${use_git_env}"
|
|
|
|
then
|
|
|
|
git_commit="${GIT_COMMIT}"
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
# Get the main version out of the source file
|
|
|
|
version_main=$(awk '$1 == "Version" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile})
|
|
|
|
release_main=$(awk '$1 == "VersionPrerelease" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile})
|
2018-06-18 15:57:35 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
# try to determine the version if we have build tags
|
|
|
|
for tag in "$GOTAGS"
|
|
|
|
do
|
2018-06-18 14:07:29 +00:00
|
|
|
for vfile in $(find "${1}/version" -name "version_*.go" 2> /dev/null| sort)
|
2018-06-12 20:55:52 +00:00
|
|
|
do
|
2018-06-18 14:07:29 +00:00
|
|
|
if grep -q "// +build $tag" "${vfile}"
|
2018-06-12 20:55:52 +00:00
|
|
|
then
|
|
|
|
version_main=$(awk '$1 == "Version" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile})
|
|
|
|
release_main=$(awk '$1 == "VersionPrerelease" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < ${vfile})
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
2018-06-18 15:57:35 +00:00
|
|
|
|
2018-06-18 21:01:20 +00:00
|
|
|
local version="${version_main}"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
|
|
|
local rel_ver=""
|
2018-06-13 19:10:02 +00:00
|
|
|
if is_set "${include_release}"
|
2018-06-12 20:55:52 +00:00
|
|
|
then
|
2018-06-18 21:01:20 +00:00
|
|
|
# Default to pre-release from the source
|
2018-06-18 15:57:35 +00:00
|
|
|
rel_ver="${release_main}"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2020-07-14 19:17:45 +00:00
|
|
|
# When no release is in the source then we are definitely in dev mode
|
|
|
|
if test -z "${rel_ver}" && is_set "${use_git_env}"
|
2018-06-12 20:55:52 +00:00
|
|
|
then
|
2018-06-18 15:57:35 +00:00
|
|
|
rel_ver="dev"
|
2018-06-12 20:55:52 +00:00
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
# Add the release to the version
|
2018-06-18 21:01:20 +00:00
|
|
|
if test -n "${rel_ver}" -a -n "${git_commit}"
|
2018-06-12 20:55:52 +00:00
|
|
|
then
|
2018-06-18 21:01:20 +00:00
|
|
|
rel_ver="${rel_ver} (${git_commit})"
|
2018-06-12 20:55:52 +00:00
|
|
|
fi
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 21:01:20 +00:00
|
|
|
if test -n "${rel_ver}"
|
|
|
|
then
|
|
|
|
if is_set "${omit_version}"
|
|
|
|
then
|
|
|
|
echo "${rel_ver}" | tr -d "'"
|
|
|
|
else
|
2018-10-19 16:04:07 +00:00
|
|
|
echo "${version}-${rel_ver}" | tr -d "'"
|
2018-06-18 21:01:20 +00:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
elif ! is_set "${omit_version}"
|
|
|
|
then
|
|
|
|
echo "${version}" | tr -d "'"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2018-06-12 20:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_version {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to the top level Consul source
|
|
|
|
# $2 - Whether the release version should be parsed from source (optional)
|
2020-07-14 19:17:45 +00:00
|
|
|
# $3 - Whether to use GIT_COMMIT environment variable
|
2018-06-12 20:55:52 +00:00
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success (the version is also echoed to stdout)
|
|
|
|
# 1 - error
|
|
|
|
#
|
|
|
|
# Notes:
|
|
|
|
# If a VERSION environment variable is present it will override any parsing of the version from the source
|
|
|
|
# In addition to processing the main version.go, version_*.go files will be processed if they have
|
|
|
|
# a Go build tag that matches the one in the GOTAGS environment variable. This tag processing is
|
|
|
|
# primitive though and will not match complex build tags in the files with negation etc.
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
local vers="$VERSION"
|
|
|
|
if test -z "$vers"
|
|
|
|
then
|
2023-08-23 16:53:44 +00:00
|
|
|
# parse the CE version from version.go
|
2018-06-13 19:10:02 +00:00
|
|
|
vers="$(parse_version ${1} ${2} ${3})"
|
2018-06-12 20:55:52 +00:00
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-12 20:55:52 +00:00
|
|
|
if test -z "$vers"
|
|
|
|
then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
echo $vers
|
|
|
|
return 0
|
|
|
|
fi
|
2018-06-13 19:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function git_branch {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to the git repo (optional - assumes pwd is git repo otherwise)
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - failure
|
|
|
|
#
|
|
|
|
# Notes:
|
|
|
|
# Echos the current branch to stdout when successful
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
local gdir="$(pwd)"
|
|
|
|
if test -d "$1"
|
|
|
|
then
|
|
|
|
gdir="$1"
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
pushd "${gdir}" > /dev/null
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
local ret=0
|
2018-06-13 19:10:02 +00:00
|
|
|
local head="$(git status -b --porcelain=v2 | awk '{if ($1 == "#" && $2 =="branch.head") { print $3 }}')" || ret=1
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
popd > /dev/null
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
test ${ret} -eq 0 && echo "$head"
|
|
|
|
return ${ret}
|
|
|
|
}
|
|
|
|
|
2022-03-24 01:26:42 +00:00
|
|
|
|
|
|
|
function git_date {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to the git repo (optional - assumes pwd is git repo otherwise)
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - failure
|
|
|
|
#
|
|
|
|
# Notes:
|
|
|
|
# Echos the date of the last git commit in
|
|
|
|
|
|
|
|
local gdir="$(pwd)"
|
|
|
|
if test -d "$1"
|
|
|
|
then
|
|
|
|
gdir="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
pushd "${gdir}" > /dev/null
|
|
|
|
|
|
|
|
local ret=0
|
|
|
|
|
|
|
|
# it's tricky to do an RFC3339 format in a cross platform way, so we hardcode UTC
|
|
|
|
local date_format="%Y-%m-%dT%H:%M:%SZ"
|
|
|
|
# we're using this for build date because it's stable across platform builds
|
2022-06-02 18:52:30 +00:00
|
|
|
local date="$(TZ=UTC0 git show -s --format=%cd --date=format-local:"$date_format" HEAD)" || ret=1
|
2022-03-24 01:26:42 +00:00
|
|
|
|
|
|
|
##local head="$(git status -b --porcelain=v2 | awk '{if ($1 == "#" && $2 =="branch.head") { print $3 }}')" || ret=1
|
|
|
|
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
test ${ret} -eq 0 && echo "$date"
|
|
|
|
return ${ret}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
function is_git_clean {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to git repo
|
|
|
|
# $2 - boolean whether the git status should be output when not clean
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - error
|
|
|
|
#
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
if ! test -d "$1"
|
|
|
|
then
|
2018-10-19 16:04:07 +00:00
|
|
|
err "ERROR: '$1' is not a directory. is_git_clean must be called with the path to a git repo as the first argument'"
|
2018-06-13 19:10:02 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
local output_status="$2"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
pushd "${1}" > /dev/null
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
local ret=0
|
|
|
|
test -z "$(git status --porcelain=v2 2> /dev/null)" || ret=1
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-13 19:10:02 +00:00
|
|
|
if is_set "${output_status}" && test "$ret" -ne 0
|
|
|
|
then
|
|
|
|
err "Git repo is not clean"
|
|
|
|
# --porcelain=v1 is the same as --short except uncolorized
|
|
|
|
git status --porcelain=v1
|
|
|
|
fi
|
|
|
|
popd > /dev/null
|
|
|
|
return ${ret}
|
2018-06-15 01:25:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 19:23:26 +00:00
|
|
|
function update_git_env {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to git repo
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - error
|
|
|
|
#
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 19:23:26 +00:00
|
|
|
if ! test -d "$1"
|
|
|
|
then
|
2018-10-19 16:04:07 +00:00
|
|
|
err "ERROR: '$1' is not a directory. is_git_clean must be called with the path to a git repo as the first argument'"
|
2018-06-15 19:23:26 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 19:23:26 +00:00
|
|
|
export GIT_COMMIT=$(git rev-parse --short HEAD)
|
|
|
|
export GIT_DIRTY=$(test -n "$(git status --porcelain)" && echo "+CHANGES")
|
|
|
|
export GIT_IMPORT=github.com/hashicorp/consul/version
|
2022-03-24 01:26:42 +00:00
|
|
|
export GIT_DATE=$(git_date "$1")
|
|
|
|
export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X ${T}.BuildDate=${GIT_DATE}"
|
2018-06-15 19:23:26 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
function update_version {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to the version file
|
|
|
|
# $2 - Version string
|
|
|
|
# $3 - PreRelease version (if unset will become an empty string)
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - error
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if ! test -f "$1"
|
|
|
|
then
|
2018-10-19 16:04:07 +00:00
|
|
|
err "ERROR: '$1' is not a regular file. update_version must be called with the path to a go version file"
|
2018-06-15 01:25:59 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if test -z "$2"
|
|
|
|
then
|
|
|
|
err "ERROR: The version specified was empty"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
local vfile="$1"
|
|
|
|
local version="$2"
|
|
|
|
local prerelease="$3"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-22 21:21:42 +00:00
|
|
|
sed_i ${SED_EXT} -e "s/(Version[[:space:]]*=[[:space:]]*)\"[^\"]*\"/\1\"${version}\"/g" -e "s/(VersionPrerelease[[:space:]]*=[[:space:]]*)\"[^\"]*\"/\1\"${prerelease}\"/g" "${vfile}"
|
2018-06-15 01:25:59 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_changelog_version {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to top level Consul source
|
|
|
|
# $2 - Version to put into the Changelog
|
|
|
|
# $3 - Release Date
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - error
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
local changelog="${1}/CHANGELOG.md"
|
|
|
|
local version="$2"
|
|
|
|
local rel_date="$3"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if ! test -f "${changelog}"
|
|
|
|
then
|
|
|
|
err "ERROR: File not found: ${changelog}"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if test -z "${version}"
|
|
|
|
then
|
|
|
|
err "ERROR: Must specify a version to put into the changelog"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if test -z "${rel_date}"
|
|
|
|
then
|
|
|
|
rel_date=$(date +"%B %d, %Y")
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-22 21:21:42 +00:00
|
|
|
sed_i ${SED_EXT} -e "s/## UNRELEASED/## ${version} (${rel_date})/" "${changelog}"
|
2018-06-15 01:25:59 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2019-01-28 19:51:49 +00:00
|
|
|
function set_website_version {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to top level Consul source
|
|
|
|
# $2 - Version to put into the website
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - error
|
|
|
|
|
|
|
|
local config_rb="${1}/website/config.rb"
|
|
|
|
local version="$2"
|
|
|
|
|
|
|
|
if ! test -f "${config_rb}"
|
|
|
|
then
|
|
|
|
err "ERROR: File not found: '${config_rb}'"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -z "${version}"
|
|
|
|
then
|
|
|
|
err "ERROR: Must specify a version to put into ${config_rb}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed_i ${SED_EXT} -e "s/(h.version[[:space:]]*=[[:space:]]*)\"[^\"]*\"/\1\"${version}\"/g" "${config_rb}"
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
function unset_changelog_version {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to top level Consul source
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - error
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
local changelog="${1}/CHANGELOG.md"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if ! test -f "${changelog}"
|
|
|
|
then
|
|
|
|
err "ERROR: File not found: ${changelog}"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-22 21:21:42 +00:00
|
|
|
sed_i ${SED_EXT} -e "1 s/^## [0-9]+\.[0-9]+\.[0-9]+ \([^)]*\)/## UNRELEASED/" "${changelog}"
|
2018-06-15 01:25:59 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_release_mode {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to top level Consul source
|
|
|
|
# $2 - The version of the release
|
|
|
|
# $3 - The release date
|
2018-06-18 21:01:20 +00:00
|
|
|
# $4 - The pre-release version
|
2018-10-19 16:04:07 +00:00
|
|
|
#
|
2018-06-15 01:25:59 +00:00
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - error
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if ! test -d "$1"
|
|
|
|
then
|
2018-10-19 16:04:07 +00:00
|
|
|
err "ERROR: '$1' is not a directory. set_release_mode must be called with the path to a git repo as the first argument"
|
2018-06-15 01:25:59 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if test -z "$2"
|
|
|
|
then
|
|
|
|
err "ERROR: The version specified was empty"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
local sdir="$1"
|
|
|
|
local vers="$2"
|
|
|
|
local rel_date="$(date +"%B %d, %Y")"
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
if test -n "$3"
|
|
|
|
then
|
|
|
|
rel_date="$3"
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 21:01:20 +00:00
|
|
|
local changelog_vers="${vers}"
|
|
|
|
if test -n "$4"
|
|
|
|
then
|
|
|
|
changelog_vers="${vers}-$4"
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 21:01:20 +00:00
|
|
|
status_stage "==> Updating CHANGELOG.md with release info: ${changelog_vers} (${rel_date})"
|
|
|
|
set_changelog_version "${sdir}" "${changelog_vers}" "${rel_date}" || return 1
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-15 01:25:59 +00:00
|
|
|
status_stage "==> Updating version/version.go"
|
2018-06-18 21:01:20 +00:00
|
|
|
if ! update_version "${sdir}/version/version.go" "${vers}" "$4"
|
2018-06-15 01:25:59 +00:00
|
|
|
then
|
|
|
|
unset_changelog_version "${sdir}"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2019-01-28 19:51:49 +00:00
|
|
|
# Only update the website when allowed and there is no pre-release version
|
|
|
|
if ! is_set "${CONSUL_NO_WEBSITE_UPDATE}" && test -z "$4"
|
|
|
|
then
|
|
|
|
status_stage "==> Updating website/config.rb"
|
|
|
|
if ! set_website_version "${sdir}" "${vers}"
|
|
|
|
then
|
|
|
|
unset_changelog_version "${sdir}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
return 0
|
2018-06-15 01:25:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-18 15:23:32 +00:00
|
|
|
function gpg_detach_sign {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - File to sign
|
|
|
|
# $2 - Alternative GPG key to use for signing
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - failure
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 15:23:32 +00:00
|
|
|
# determine whether the gpg key to use is being overridden
|
|
|
|
local gpg_key=${HASHICORP_GPG_KEY}
|
|
|
|
if test -n "$2"
|
|
|
|
then
|
|
|
|
gpg_key=$2
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 15:23:32 +00:00
|
|
|
gpg --default-key "${gpg_key}" --detach-sig --yes -v "$1"
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function shasum_directory {
|
|
|
|
# Arguments:
|
|
|
|
# $1 - Path to directory containing the files to shasum
|
|
|
|
# $2 - File to output sha sums to
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - failure
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 15:23:32 +00:00
|
|
|
if ! test -d "$1"
|
|
|
|
then
|
|
|
|
err "ERROR: '$1' is not a directory and shasum_release requires passing a directory as the first argument"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 15:23:32 +00:00
|
|
|
if test -z "$2"
|
|
|
|
then
|
|
|
|
err "ERROR: shasum_release requires a second argument to be the filename to output the shasums to but none was given"
|
2018-10-19 16:04:07 +00:00
|
|
|
return 1
|
2018-06-18 15:23:32 +00:00
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 15:23:32 +00:00
|
|
|
pushd $1 > /dev/null
|
|
|
|
shasum -a256 * > "$2"
|
|
|
|
ret=$?
|
|
|
|
popd >/dev/null
|
2018-10-19 16:04:07 +00:00
|
|
|
|
2018-06-18 15:23:32 +00:00
|
|
|
return $ret
|
|
|
|
}
|
2018-06-26 15:21:37 +00:00
|
|
|
|
2019-04-12 19:17:13 +00:00
|
|
|
function ui_version {
|
2018-06-26 15:21:37 +00:00
|
|
|
# Arguments:
|
|
|
|
# $1 - path to index.html
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * -failure
|
|
|
|
#
|
|
|
|
# Notes: echoes the version to stdout upon success
|
|
|
|
if ! test -f "$1"
|
|
|
|
then
|
|
|
|
err "ERROR: No such file: '$1'"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-10-19 16:04:07 +00:00
|
|
|
|
ui: modify content path (#5950)
* Add ui-content-path flag
* tests complete, regex validator on string, index.html updated
* cleaning up debugging stuff
* ui: Enable ember environment configuration to be set via the go binary at runtime (#5934)
* ui: Only inject {{.ContentPath}} if we are makeing a prod build...
...otherwise we just use the current rootURL
This gets injected into a <base /> node which solves the assets path
problem but not the ember problem
* ui: Pull out the <base href=""> value and inject it into ember env
See previous commit:
The <base href=""> value is 'sometimes' injected from go at index
serve time. We pass this value down to ember by overwriting the ember
config that is injected via a <meta> tag. This has to be done before
ember bootup.
Sometimes (during testing and development, basically not production)
this is injected with the already existing value, in which case this
essentially changes nothing.
The code here is slightly abstracted away from our specific usage to
make it easier for anyone else to use, and also make sure we can cope
with using this same method to pass variables down from the CLI through
to ember in the future.
* ui: We can't use <base /> move everything to javascript (#5941)
Unfortuantely we can't seem to be able to use <base> and rootURL
together as URL paths will get doubled up (`ui/ui/`).
This moves all the things that we need to interpolate with .ContentPath
to the `startup` javascript so we can conditionally print out
`{{.ContentPath}}` in lots of places (now we can't use base)
* fixed when we serve index.html
* ui: For writing a ContentPath, we also need to cope with testing... (#5945)
...and potentially more environments
Testing has more additional things in a separate index.html in `tests/`
This make the entire thing a little saner and uses just javascriopt
template literals instead of a pseudo handbrake synatx for our
templating of these files.
Intead of just templating the entire file this way, we still only
template `{{content-for 'head'}}` and `{{content-for 'body'}}`
in this way to ensure we support other plugins/addons
* build: Loosen up the regex for retrieving the CONSUL_VERSION (#5946)
* build: Loosen up the regex for retrieving the CONSUL_VERSION
1. Previously the `sed` replacement was searching for the CONSUL_VERSION
comment at the start of a line, it no longer does this to allow for
indentation.
2. Both `grep` and `sed` where looking for the omment at the end of the
line. We've removed this restriction here. We don't need to remove it
right now, but if we ever put the comment followed by something here the
searching would break.
3. Added `xargs` for trimming the resulting version string. We aren't
using this already in the rest of the scripts, but we are pretty sure
this is available on most systems.
* ui: Fix erroneous variable, and also force an ember cache clean on build
1. We referenced a variable incorrectly here, this fixes that.
2. We also made sure that every `make` target clears ember's `tmp` cache
to ensure that its not using any caches that have since been edited
everytime we call a `make` target.
* added docs, fixed encoding
* fixed go fmt
* Update agent/config/config.go
Co-Authored-By: R.B. Boyer <public@richardboyer.net>
* Completed Suggestions
* run gofmt on http.go
* fix testsanitize
* fix fullconfig/hcl by setting correct 'want'
* ran gofmt on agent/config/runtime_test.go
* Update website/source/docs/agent/options.html.md
Co-Authored-By: Hans Hasselberg <me@hans.io>
* Update website/source/docs/agent/options.html.md
Co-Authored-By: kaitlincarter-hc <43049322+kaitlincarter-hc@users.noreply.github.com>
* remove contentpath from redirectFS struct
2019-06-26 16:43:30 +00:00
|
|
|
local ui_version="$(grep '<!-- CONSUL_VERSION: .* -->' "$1" | sed 's/<!-- CONSUL_VERSION: \(.*\) -->/\1/' | xargs)" || return 1
|
2018-06-26 15:21:37 +00:00
|
|
|
echo "$ui_version"
|
|
|
|
return 0
|
2019-04-12 19:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ui_logo_type {
|
2018-07-30 16:59:43 +00:00
|
|
|
# Arguments:
|
|
|
|
# $1 - path to index.html
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * -failure
|
|
|
|
#
|
|
|
|
# Notes: echoes the 'logo type' to stdout upon success
|
|
|
|
# the 'logo' can be one of 'enterprise' or 'oss'
|
|
|
|
# and doesn't necessarily correspond to the binary type of consul
|
|
|
|
# the logo is 'enterprise' if the binary type is anything but 'oss'
|
|
|
|
if ! test -f "$1"
|
|
|
|
then
|
|
|
|
err "ERROR: No such file: '$1'"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
grep -q "data-enterprise-logo" < "$1"
|
|
|
|
|
|
|
|
if test $? -eq 0
|
|
|
|
then
|
|
|
|
echo "enterprise"
|
|
|
|
else
|
2023-08-23 16:53:44 +00:00
|
|
|
# TODO(spatel): CE refactor
|
2018-07-30 16:59:43 +00:00
|
|
|
echo "oss"
|
|
|
|
fi
|
|
|
|
return 0
|
2019-04-12 19:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function go_mod_assert {
|
|
|
|
# Returns:
|
|
|
|
# 0 - success
|
|
|
|
# * - failure
|
|
|
|
#
|
|
|
|
# Notes: will ensure all the necessary go modules are cached
|
|
|
|
# and if the CONSUL_MOD_VERIFY env var is set will force
|
|
|
|
# reverification of all modules.
|
|
|
|
if ! go mod download >/dev/null
|
|
|
|
then
|
|
|
|
err "ERROR: Failed to populate the go module cache"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if is_set "${CONSUL_MOD_VERIFY}"
|
|
|
|
then
|
|
|
|
if ! go mod verify
|
|
|
|
then
|
|
|
|
err "ERROR: Failed to verify go module checksums"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|