Allow for building pre-releases/rcs/betas

This commit is contained in:
Matt Keeler 2018-06-18 17:01:20 -04:00
parent 9457468423
commit 12d14f6c54
4 changed files with 58 additions and 26 deletions

View File

@ -63,6 +63,12 @@ else
DIST_DATE_ARG=
endif
ifdef DIST_PRERELEASE
DIST_REL_ARG=-r "$(DIST_PRERELEASE)"
else
DIST_REL_ARG=
endif
PUB_GIT?=1
PUB_WEBSITE?=1
@ -117,7 +123,7 @@ linux:
# dist builds binaries for all platforms and packages them for distribution
dist:
@$(SHELL) $(CURDIR)/build-support/scripts/release.sh -t '$(DIST_TAG)' -b '$(DIST_BUILD)' -S '$(DIST_SIGN)' $(DIST_VERSION_ARG) $(DIST_DATE_ARG)
@$(SHELL) $(CURDIR)/build-support/scripts/release.sh -t '$(DIST_TAG)' -b '$(DIST_BUILD)' -S '$(DIST_SIGN)' $(DIST_VERSION_ARG) $(DIST_DATE_ARG) $(DIST_REL_ARG)
publish:
@$(SHELL) $(CURDIR)/build-support/scripts/publish.sh $(PUB_GIT_ARG) $(PUB_WEBSITE_ARG)

View File

@ -94,6 +94,7 @@ function parse_version {
# $1 - Path to the top level Consul source
# $2 - boolean value for whether the release version should be parsed from the source
# $3 - boolean whether to use GIT_DESCRIBE and GIT_COMMIT environment variables
# $4 - boolean whether to omit the version part of the version string. (optional)
#
# Return:
# 0 - success (will write the version to stdout)
@ -114,6 +115,7 @@ function parse_version {
local include_release="$2"
local use_git_env="$3"
local omit_version="$4"
local git_version=""
local git_commit=""
@ -152,18 +154,17 @@ function parse_version {
done
done
local version="${version_main}"
# override the version from source with the value of the GIT_DESCRIBE env var if present
if test -n "${git_version}"
then
version="${git_version}"
else
version="${version_main}"
fi
local rel_ver=""
if is_set "${include_release}"
then
# Get the release version out of the source file
# Default to pre-release from the source
rel_ver="${release_main}"
# When no GIT_DESCRIBE env var is present and no release is in the source then we
@ -174,21 +175,28 @@ function parse_version {
fi
# Add the release to the version
if test -n "${rel_ver}"
if test -n "${rel_ver}" -a -n "${git_commit}"
then
version="${version}-${rel_ver}"
# add the git commit to the version
if test -n "${git_commit}"
then
version="${version} (${git_commit})"
fi
rel_ver="${rel_ver} (${git_commit})"
fi
fi
# Output the version
echo "$version" | tr -d "'"
return 0
if test -n "${rel_ver}"
then
if is_set "${omit_version}"
then
echo "${rel_ver}" | tr -d "'"
else
echo "${version}-${rel_ver}" | tr -d "'"
fi
return 0
elif ! is_set "${omit_version}"
then
echo "${version}" | tr -d "'"
return 0
else
return 1
fi
}
function get_version {
@ -624,6 +632,7 @@ function set_release_mode {
# $1 - Path to top level Consul source
# $2 - The version of the release
# $3 - The release date
# $4 - The pre-release version
#
#
# Returns:
@ -651,11 +660,17 @@ function set_release_mode {
rel_date="$3"
fi
status_stage "==> Updating CHANGELOG.md with release info: ${vers} (${rel_date})"
set_changelog_version "${sdir}" "${vers}" "${rel_date}" || return 1
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 version/version.go"
if ! update_version "${sdir}/version/version.go" "${vers}"
if ! update_version "${sdir}/version/version.go" "${vers}" "$4"
then
unset_changelog_version "${sdir}"
return 1

View File

@ -349,7 +349,8 @@ function build_release {
# $4 - boolean whether to generate the sha256 sums
# $5 - version to set within version.go and the changelog
# $6 - release date to set within the changelog
# $7 - alternative gpg key to use for signing operations (optional)
# $7 - release version to set
# $8 - alternative gpg key to use for signing operations (optional)
#
# Returns:
# 0 - success
@ -361,7 +362,8 @@ function build_release {
debug "Sign Release: $4"
debug "Version: $5"
debug "Release Date: $6"
debug "GPG Key: $7"
debug "Release Vers: $7"
debug "GPG Key: $8"
if ! test -d "$1"
then
@ -379,7 +381,7 @@ function build_release {
local do_tag="$2"
local do_build="$3"
local do_sha256="$4"
local gpg_key="$7"
local gpg_key="$8"
if test -z "${gpg_key}"
then
@ -403,13 +405,15 @@ function build_release {
local set_vers="$5"
local set_date="$6"
local set_release="$7"
if test -z "${set_vers}"
then
set_vers=$(get_version "${sdir}" false false)
set_release=$(parse_version "${sdir}" true false true)
fi
if is_set "${do_tag}" && ! set_release_mode "${sdir}" "${set_vers}" "${set_date}"
if is_set "${do_tag}" && ! set_release_mode "${sdir}" "${set_vers}" "${set_date}" "${set_release}"
then
err "ERROR: Failed to put source into release mode"
return 1

View File

@ -53,6 +53,8 @@ Options:
the version will be parsed from the source.
-d | --date DATE The release date. Defaults to today.
-r | --release STRING The prerelease version. Defaults to an empty pre-release.
-h | --help Print this help text.
EOF
@ -81,6 +83,7 @@ function main {
declare -i do_sign=1
declare gpg_key="${HASHICORP_GPG_KEY}"
declare version=""
declare release_ver=""
declare release_date=$(date +"%B %d, %Y")
while test $# -gt 0
@ -128,11 +131,15 @@ function main {
shift 2
;;
-d | --date)
echo "$2"
ensure_arg "-d/--date" "$2" || return 1
release_date="$2"
shift 2
;;
-r | --release)
ensure_arg "-r/--release" "$2" || return 1
release_ver="$2"
shift 2
;;
*)
err_usage "ERROR: Unknown argument: '$1'"
return 1
@ -140,7 +147,7 @@ function main {
esac
done
build_release "${sdir}" "${do_tag}" "${do_build}" "${do_sign}" "${version}" "${release_date}" "${gpg_key}"
build_release "${sdir}" "${do_tag}" "${do_build}" "${do_sign}" "${version}" "${release_date}" "${release_ver}" "${gpg_key}"
return $?
}