Merge pull request #3852 from zmstone/feat-add-build-stamp

Feat support build stamp and more fixes
This commit is contained in:
Zaiming Shi 2020-11-28 07:37:22 +01:00 committed by GitHub
commit 12d706a84c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 73 deletions

3
.gitignore vendored
View File

@ -32,3 +32,6 @@ xrefr
etc/emqx.conf.rendered etc/emqx.conf.rendered
Mnesia.*/ Mnesia.*/
*.DS_Store *.DS_Store
_checkouts
rebar.config.rendered
/rebar3

View File

@ -1,22 +1,22 @@
REBAR = $(CURDIR)/rebar3 REBAR_VERSION = 3.13.2-emqx-1
REBAR = ./rebar3
PROFILE ?= emqx PROFILE ?= emqx
PROFILES := emqx emqx-edge PROFILES := emqx emqx-edge
PKG_PROFILES := emqx-pkg emqx-edge-pkg PKG_PROFILES := emqx-pkg emqx-edge-pkg
export DEFAULT_VSN ?= $(shell ./get-lastest-tag.escript)
ifneq ($(shell echo $(DEFAULT_VSN) | grep -oE "^[ev0-9]+\.[0-9]+(\.[0-9]+)?"),)
export PKG_VSN := $(patsubst v%,%,$(patsubst e%,%,$(DEFAULT_VSN)))
else
export PKG_VSN := $(patsubst v%,%,$(DEFAULT_VSN))
endif
.PHONY: default .PHONY: default
default: $(REBAR) $(PROFILE) default: $(REBAR) $(PROFILE)
.PHONY: all .PHONY: all
all: $(REBAR) $(PROFILES) all: $(REBAR) $(PROFILES)
.PHONY: ensure-rebar3
ensure-rebar3:
@./ensure-rebar3.sh $(REBAR_VERSION)
$(REBAR): ensure-rebar3
.PHONY: distclean .PHONY: distclean
distclean: distclean:
@rm -rf _build @rm -rf _build
@ -34,11 +34,15 @@ endif
$(PROFILES:%=build-%): $(REBAR) $(PROFILES:%=build-%): $(REBAR)
$(REBAR) as $(@:build-%=%) compile $(REBAR) as $(@:build-%=%) compile
# rebar clean
.PHONY: clean $(PROFILES:%=clean-%) .PHONY: clean $(PROFILES:%=clean-%)
clean: $(PROFILES:%=clean-%) clean: $(PROFILES:%=clean-%) clean-stamps
$(PROFILES:%=clean-%): $(REBAR) $(PROFILES:%=clean-%): $(REBAR)
@rm -rf _build/$(@:clean-%=%) $(REBAR) as $(@:clean-%=%) clean
@rm -rf _build/$(@:clean-%=%)+test
.PHONY: clean-stamps
clean-stamps:
find -L _build -name '.stamp' -type f | xargs rm -f
.PHONY: deps-all .PHONY: deps-all
deps-all: $(REBAR) $(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%) deps-all: $(REBAR) $(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%)

View File

@ -1,7 +1,7 @@
%%-*- mode: erlang -*- %%-*- mode: erlang -*-
{plugins, {plugins,
[rebar3_proper, [rebar3_proper,
{grpcbox_plugin, {git, "https://github.com/HJianBo/grpcbox_plugin", {branch, "master"}}} {grpcbox_plugin, {git, "https://github.com/zmstone/grpcbox_plugin", {branch, "master"}}}
]}. ]}.
{deps, {deps,

View File

@ -9,7 +9,7 @@
{parse_transform}]}. {parse_transform}]}.
{plugins, {plugins,
[{grpcbox_plugin, {git, "https://github.com/HJianBo/grpcbox_plugin", {branch, "master"}}} [{grpcbox_plugin, {git, "https://github.com/zmstone/grpcbox_plugin", {branch, "master"}}}
]}. ]}.
{deps, {deps,

20
ensure-rebar3.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
set -euo pipefail
VERSION="$1"
download() {
curl -L "https://s3-us-west-2.amazonaws.com/packages.emqx/rebar/rebar3-${VERSION}" -o ./rebar3
}
version() {
./rebar3 -v | grep -v '===' | grep 'rebar.*Erlang' | awk '{print $2}'
}
if [ -f 'rebar3' ] && [ "$(version)" == "$VERSION" ]; then
exit 0
fi
download
chmod +x ./rebar3

View File

@ -1,47 +0,0 @@
#!/usr/bin/env escript
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
%% -------------------------------------------------------------------
%%
%% nodetool: Helper Script for interacting with live nodes
%%
%% -------------------------------------------------------------------
main(_Args) ->
io:format(getRef()).
comparingFun([C1|R1], [C2|R2]) when is_list(C1), is_list(C2);
is_integer(C1), is_integer(C2) -> C1 < C2 orelse comparingFun(R1, R2);
comparingFun([C1|R1], [C2|R2]) when is_integer(C1), is_list(C2) -> comparingFun(R1, R2);
comparingFun([C1|_R1], [C2|_R2]) when is_list(C1), is_integer(C2) -> true;
comparingFun(_, _) -> false.
sortFun(T1, T2) ->
C = fun(T) ->
[case catch list_to_integer(E) of
I when is_integer(I) -> I;
_ -> E
end || E <- re:split(string:sub_string(T, 2), "[.-]", [{return, list}])]
end,
comparingFun(C(T1), C(T2)).
latestTag(BranchName) ->
Tag = os:cmd("git describe --abbrev=1 --tags --always") -- "\n",
LatestTagCommitId = os:cmd(io_lib:format("git rev-parse --short ~s", [Tag])) -- "\n",
case string:tokens(os:cmd(io_lib:format("git tag -l \"v*\" --points-at ~s", [LatestTagCommitId])), "\n") of
[] -> BranchName ++ "-" ++ LatestTagCommitId;
Tags ->
lists:last(lists:sort(fun(T1, T2) -> sortFun(T1, T2) end, Tags))
end.
branch() ->
case os:getenv("GITHUB_RUN_ID") of
false -> os:cmd("git branch | grep -e '^*' | cut -d' ' -f 2") -- "\n";
_ -> re:replace(os:getenv("GITHUB_REF"), "^refs/heads/|^refs/tags/", "", [global, {return ,list}])
end.
getRef() ->
case re:run(branch(), "master|^dev/|^hotfix/", [{capture, none}]) of
match -> branch();
_ -> latestTag(branch())
end.

View File

@ -6,7 +6,7 @@
get_vsn(_Conf) -> get_vsn(_Conf) ->
PkgVsn = case os:getenv("PKG_VSN") of PkgVsn = case os:getenv("PKG_VSN") of
false -> error({env_undefined, "PKG_VSN"}); false -> os:cmd("git describe --tags");
Vsn -> Vsn Vsn -> Vsn
end, end,
re:replace(PkgVsn, "v", "", [{return ,list}]). re:replace(PkgVsn, "v", "", [{return ,list}]).

View File

@ -1,6 +1,7 @@
{minimum_otp_vsn, "21.3"}. {minimum_otp_vsn, "21.3"}.
{plugins,[{relup_helper,{git,"https://github.com/emqx/relup_helper", {plugins,[ {relup_helper,{git,"https://github.com/emqx/relup_helper", {branch,"master"}}}
{branch,"master"}}}]}. , {coveralls, {git, "https://github.com/emqx/coveralls-erl", {branch, "github"}}}
]}.
{edge_relx_overlay,[]}. {edge_relx_overlay,[]}.
{edoc_opts,[{preprocess,true}]}. {edoc_opts,[{preprocess,true}]}.
{erl_opts,[warn_unused_vars,warn_shadow_vars,warn_unused_import, {erl_opts,[warn_unused_vars,warn_shadow_vars,warn_unused_import,
@ -51,13 +52,7 @@
{overlay, ["${BASIC_OVERLAYS}", "${EDGE_OVERLAYS}"]}, {overlay, ["${BASIC_OVERLAYS}", "${EDGE_OVERLAYS}"]},
{overlay_vars,["vars/vars-edge.config","vars/vars-pkg.config"]}]}]}, {overlay_vars,["vars/vars-edge.config","vars/vars-pkg.config"]}]}]},
{test, {test,
[ [{deps,
{plugins, [
rebar3_proper,
{coveralls,
{git, "https://github.com/emqx/coveralls-erl",
{branch, "github"}}}]},
{deps,
[ {bbmustache, "1.7.0"}, [ {bbmustache, "1.7.0"},
{emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.0"}}}, {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.0"}}},
{emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "1.3.0"}}}, {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "1.3.0"}}},
@ -167,11 +162,11 @@
, {template, "data/loaded_plugins.tmpl", "data/loaded_plugins"} , {template, "data/loaded_plugins.tmpl", "data/loaded_plugins"}
, {template, "data/loaded_modules.tmpl", "data/loaded_modules"} , {template, "data/loaded_modules.tmpl", "data/loaded_modules"}
, {template,"data/emqx_vars","releases/emqx_vars"} , {template,"data/emqx_vars","releases/emqx_vars"}
, {copy,"{{lib_dirs}}/cuttlefish/cuttlefish","bin/"} , {copy,"_checkouts/cuttlefish/cuttlefish","bin/"}
, {copy,"bin/*","bin/"} , {copy,"bin/*","bin/"}
, {template,"etc/*.conf","etc/"} , {template,"etc/*.conf","etc/"}
, {template,"etc/emqx.d/*.conf","etc/emqx.d/"} , {template,"etc/emqx.d/*.conf","etc/emqx.d/"}
, {copy,"{{lib_dirs}}/emqx/priv/emqx.schema","releases/{{rel_vsn}}/"} , {copy,"_checkouts/emqx/priv/emqx.schema","releases/{{rel_vsn}}/"}
, {copy, "etc/certs","etc/"} , {copy, "etc/certs","etc/"}
, "${RELUP_OVERLAYS}" , "${RELUP_OVERLAYS}"
] ]
@ -184,7 +179,7 @@
, {copy,"bin/emqx_ctl","bin/emqx_ctl-{{rel_vsn}}"} , {copy,"bin/emqx_ctl","bin/emqx_ctl-{{rel_vsn}}"}
, {copy,"bin/install_upgrade.escript", "bin/install_upgrade.escript-{{rel_vsn}}"} , {copy,"bin/install_upgrade.escript", "bin/install_upgrade.escript-{{rel_vsn}}"}
, {copy,"bin/nodetool","bin/nodetool-{{rel_vsn}}"} , {copy,"bin/nodetool","bin/nodetool-{{rel_vsn}}"}
, {copy,"{{lib_dirs}}/cuttlefish/cuttlefish","bin/cuttlefish-{{rel_vsn}}"} , {copy,"_checkouts/cuttlefish/cuttlefish","bin/cuttlefish-{{rel_vsn}}"}
] ]
}, },

BIN
rebar3

Binary file not shown.