chore(versioning): detach package version from emqx app version

This commit is contained in:
Zaiming Shi 2021-03-04 16:33:57 +01:00
parent 059d9fcaeb
commit 9b3ab169ce
5 changed files with 58 additions and 14 deletions

36
include/emqx_release.hrl Normal file
View File

@ -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.

View File

@ -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:-}"

View File

@ -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]),

View File

@ -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]},

View File

@ -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