From a6566962e0e8b5005ca0cc13f694b2e6ef1f26c0 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Fri, 27 Nov 2020 00:11:49 +0100 Subject: [PATCH] refactor(build): simplify version resolution --- Makefile | 7 ------ get-lastest-tag.escript | 47 ----------------------------------------- mods/mod_project.erl | 2 +- 3 files changed, 1 insertion(+), 55 deletions(-) delete mode 100755 get-lastest-tag.escript diff --git a/Makefile b/Makefile index 21179c5ea..4fcabf260 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,6 @@ PROFILE ?= emqx PROFILES := emqx emqx-edge 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 default: $(REBAR) $(PROFILE) diff --git a/get-lastest-tag.escript b/get-lastest-tag.escript deleted file mode 100755 index 5eb942b79..000000000 --- a/get-lastest-tag.escript +++ /dev/null @@ -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. diff --git a/mods/mod_project.erl b/mods/mod_project.erl index df60cada1..ca5b23278 100644 --- a/mods/mod_project.erl +++ b/mods/mod_project.erl @@ -6,7 +6,7 @@ get_vsn(_Conf) -> PkgVsn = case os:getenv("PKG_VSN") of - false -> error({env_undefined, "PKG_VSN"}); + false -> os:cmd("git describe --tags"); Vsn -> Vsn end, re:replace(PkgVsn, "v", "", [{return ,list}]).