diff --git a/include/emqx_release.hrl b/include/emqx_release.hrl new file mode 100644 index 000000000..0adfd2e48 --- /dev/null +++ b/include/emqx_release.hrl @@ -0,0 +1,36 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2021 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- + +-ifndef(EMQX_RELEASE_HRL). +-define(EMQX_RELEASE_HRL, true). + +%% NOTE: this is the release version which is not always the same +%% as the emqx app version defined in emqx.app.src +%% App (plugin) versions are bumped independently. +%% e.g. EMQX_RELEASE being 4.3.1 does no always imply emqx app +%% should be 4.3.1, as it might be the case that only one of the +%% plugins had a bug to fix. So for a hot beam upgrade, only the app +%% with beam files changed needs an upgrade. + +%% NOTE: The version string prefix should be: +%% 'v' for opensource edition +%% 'e' for enterprise edition + +%% NOTE: This version number should be manually bumped for each release + +-define(EMQX_RELEASE, "v4.3-beta.1"). + +-endif. diff --git a/pkg-vsn.sh b/pkg-vsn.sh index 0c1c0cb33..02096e8ff 100755 --- a/pkg-vsn.sh +++ b/pkg-vsn.sh @@ -1,20 +1,15 @@ #!/usr/bin/env bash -set -e -u +set -euo pipefail # This script prints the release version for emqx # ensure dir cd -P -- "$(dirname -- "$0")" -case $(uname) in - *Darwin*) SED="sed -E";; - *) SED="sed -r";; -esac +RELEASE="$(grep -E 'define.+EMQX_RELEASE,' include/emqx_release.hrl | cut -d '"' -f2)" -# comment SUFFIX out when finalising RELEASE -RELEASE="$(grep -oE '\{vsn, (.*)\}' src/emqx.app.src | $SED 's/\{vsn, (.*)\}/\1/g' | $SED 's/\"//g')" -if [ -d .git ] && ! git describe --tags --match "v${RELEASE}" --exact >/dev/null 2>&1; then - SUFFIX="-$(git rev-parse HEAD | cut -b1-8)" +if [ -d .git ] && ! git describe --tags --match "${RELEASE}" --exact >/dev/null 2>&1; then + SUFFIX="-$(git rev-parse HEAD | cut -b1-8)" fi echo "${RELEASE}${SUFFIX:-}" diff --git a/rebar.config.erl b/rebar.config.erl index 6f839f16c..affe1d5b9 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -294,8 +294,7 @@ get_vsn() -> false -> os:cmd("./pkg-vsn.sh"); Vsn -> Vsn end, - Vsn2 = re:replace(PkgVsn, "v", "", [{return ,list}]), - re:replace(Vsn2, "\n", "", [{return ,list}]). + re:replace(PkgVsn, "\n", "", [{return ,list}]). maybe_dump(Config) -> is_debug() andalso file:write_file("rebar.config.rendered", [io_lib:format("~p.\n", [I]) || I <- Config]), diff --git a/src/emqx.app.src b/src/emqx.app.src index 70d64fff8..40c0ff955 100644 --- a/src/emqx.app.src +++ b/src/emqx.app.src @@ -1,7 +1,7 @@ {application, emqx, [{description, "EMQ X Broker"}, {id, "emqx"}, - {vsn, "4.3-beta.1"}, % strict semver, bump manually! + {vsn, "4.3.0"}, % strict semver, bump manually! {modules, []}, {registered, []}, {applications, [kernel,stdlib,gproc,gen_rpc,esockd,cowboy,sasl,os_mon]}, diff --git a/src/emqx_app.erl b/src/emqx_app.erl index cf4f8753d..8e0e51d25 100644 --- a/src/emqx_app.erl +++ b/src/emqx_app.erl @@ -20,10 +20,13 @@ -export([ start/2 , stop/1 + , get_release/0 ]). -define(APP, emqx). +-include("emqx_release.hrl"). + %%-------------------------------------------------------------------- %% Application callbacks %%-------------------------------------------------------------------- @@ -57,8 +60,19 @@ print_banner() -> print_vsn() -> {ok, Descr} = application:get_key(description), - {ok, Vsn} = application:get_key(vsn), - io:format("~s ~s is running now!~n", [Descr, Vsn]). + io:format("~s ~s is running now!~n", [Descr, get_release()]). + +-ifdef(TEST). +%% When testing, the 'cover' compiler stripps aways compile info +get_release() -> ?EMQX_RELEASE. +-else. +%% Otherwise print the build number, +%% which may have a git commit in its suffix. +get_release() -> + {_, Vsn} = lists:keyfind(emqx_vsn, 1, ?MODULE:module_info(compile)), + ?EMQX_RELEASE ++ _ = Vsn, %% assert + Vsn. +-endif. %%-------------------------------------------------------------------- %% Autocluster