Просмотр исходного кода

Merge pull request #4287 from zmstone/fix-versioning

Fix versioning
Zaiming Shi 4 лет назад
Родитель
Сommit
b846ae5e30
5 измененных файлов с 58 добавлено и 14 удалено
  1. 36 0
      include/emqx_release.hrl
  2. 4 9
      pkg-vsn.sh
  3. 1 2
      rebar.config.erl
  4. 1 1
      src/emqx.app.src
  5. 16 2
      src/emqx_app.erl

+ 36 - 0
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.

+ 4 - 9
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:-}"

+ 1 - 2
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]),

+ 1 - 1
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]},

+ 16 - 2
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