rebar.config.script 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. %%-*- mode: erlang -*-
  2. DEPS = case lists:keyfind(deps, 1, CONFIG) of
  3. {_, Deps} -> Deps;
  4. _ -> []
  5. end,
  6. ComparingFun = fun
  7. _Fun([C1|R1], [C2|R2]) when is_list(C1), is_list(C2);
  8. is_integer(C1), is_integer(C2) -> C1 < C2 orelse _Fun(R1, R2);
  9. _Fun([C1|R1], [C2|R2]) when is_integer(C1), is_list(C2) -> _Fun(R1, R2);
  10. _Fun([C1|R1], [C2|R2]) when is_list(C1), is_integer(C2) -> true;
  11. _Fun(_, _) -> false
  12. end,
  13. SortFun = fun(T1, T2) ->
  14. C = fun(T) ->
  15. [case catch list_to_integer(E) of
  16. I when is_integer(I) -> I;
  17. _ -> E
  18. end || E <- re:split(string:sub_string(T, 2), "[.-]", [{return, list}])]
  19. end,
  20. ComparingFun(C(T1), C(T2))
  21. end,
  22. VTags = string:tokens(os:cmd("git tag -l \"v*\" --points-at $(git rev-parse $(git describe --abbrev=0 --tags))"), "\n"),
  23. Tags = case VTags of
  24. [] -> string:tokens(os:cmd("git tag -l \"e*\" --points-at $(git rev-parse $(git describe --abbrev=0 --tags))"), "\n");
  25. _ -> VTags
  26. end,
  27. LatestTag = lists:last(lists:sort(SortFun, Tags)),
  28. Branch = case os:getenv("GITHUB_RUN_ID") of
  29. false -> os:cmd("git branch | grep -e '^*' | cut -d' ' -f 2") -- "\n";
  30. _ -> re:replace(os:getenv("GITHUB_REF"), "^refs/heads/|^refs/tags/", "", [global, {return ,list}])
  31. end,
  32. GitDescribe = case re:run(Branch, "master|^dev/|^hotfix/", [{capture, none}]) of
  33. match -> {branch, Branch};
  34. _ -> {tag, LatestTag}
  35. end,
  36. UrlPrefix = "https://github.com/emqx/",
  37. %% EMQX_DEP = {emqx, {git, UrlPrefix ++ "emqx", GitDescribe}},
  38. EMQX_MGMT_DEP = {emqx_management, {git, UrlPrefix ++ "emqx-management", GitDescribe}},
  39. %% NewDeps = [EMQX_DEP, EMQX_MGMT_DEP | DEPS],
  40. NewDeps = [EMQX_MGMT_DEP | DEPS],
  41. CONFIG1 = lists:keystore(deps, 1, CONFIG, {deps, NewDeps}),
  42. CONFIG1.