emqx/apps/emqx_management/rebar.config.script

69 lines
2.8 KiB
Erlang

%%-*- mode: erlang -*-
DEPS = case lists:keyfind(deps, 1, CONFIG) of
{_, Deps} -> Deps;
_ -> []
end,
ComparingFun = fun
_Fun([C1|R1], [C2|R2]) when is_list(C1), is_list(C2);
is_integer(C1), is_integer(C2) -> C1 < C2 orelse _Fun(R1, R2);
_Fun([C1|R1], [C2|R2]) when is_integer(C1), is_list(C2) -> _Fun(R1, R2);
_Fun([C1|R1], [C2|R2]) when is_list(C1), is_integer(C2) -> true;
_Fun(_, _) -> false
end,
SortFun = fun(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))
end,
VTags = string:tokens(os:cmd("git tag -l \"v*\" --points-at $(git rev-parse $(git describe --abbrev=0 --tags))"), "\n"),
Tags = case VTags of
[] -> string:tokens(os:cmd("git tag -l \"e*\" --points-at $(git rev-parse $(git describe --abbrev=0 --tags))"), "\n");
_ -> VTags
end,
LatestTag = lists:last(lists:sort(SortFun, Tags)),
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,
GitDescribe = case re:run(Branch, "master|^dev/|^hotfix/", [{capture, none}]) of
match -> {branch, Branch};
_ -> {tag, LatestTag}
end,
UrlPrefix = "https://github.com/emqx/",
NewDeps = [{emqx, {git, UrlPrefix ++ "emqx", GitDescribe}} | DEPS],
CONFIG1 = lists:keystore(deps, 1, CONFIG, {deps, NewDeps}),
{_,Profiles} = lists:keyfind(profiles, 1, CONFIG1),
{_, Test} = lists:keyfind(test, 1, Profiles),
{_, TestDeps} = lists:keyfind(deps, 1, Test),
NewTestDeps = [{emqx_enterprise_dashboard, {git, UrlPrefix ++ "emqx-enterprise-dashboard", GitDescribe}},
{emqx_conf, {git, UrlPrefix ++ "emqx-conf", GitDescribe}},
{emqx_modules_spec, {git, UrlPrefix ++ "emqx-modules-spec", GitDescribe}},
{emqx_modules, {git, UrlPrefix ++ "emqx-modules", GitDescribe}},
{emqx_reloader, {git, UrlPrefix ++ "emqx-reloader", GitDescribe}},
{emqx_rule_engine, {git, UrlPrefix ++ "emqx-rule-engine", GitDescribe}},
{emqx_schema_registry, {git, UrlPrefix ++ "emqx-schema-registry", GitDescribe}}
],
NewTest = lists:keystore(deps, 1, Test, {deps, lists:append(NewTestDeps, TestDeps)}),
NewProfiles = lists:keystore(test, 1, Profiles, {test, NewTest}),
CONFIG2 = lists:keystore(profiles, 1, CONFIG1, {profiles, NewProfiles}),
CONFIG2.