diff options
author | Tristan Sloughter <[email protected]> | 2019-05-12 13:32:45 -0600 |
---|---|---|
committer | Tristan Sloughter <[email protected]> | 2019-05-17 10:15:50 -0600 |
commit | 441000c7b0730e96673dfe705a185b82229b30ea (patch) | |
tree | bca67891bc40d4e974a4035c2fc2a9bdbcfe115d /src/rlx_config.erl | |
parent | ffd657605bc3cd390c5bb3270ccb38c540226da0 (diff) | |
download | relx-441000c7b0730e96673dfe705a185b82229b30ea.tar.gz relx-441000c7b0730e96673dfe705a185b82229b30ea.tar.bz2 relx-441000c7b0730e96673dfe705a185b82229b30ea.zip |
add support for git ref and file content as app version
Diffstat (limited to 'src/rlx_config.erl')
-rw-r--r-- | src/rlx_config.erl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/rlx_config.erl b/src/rlx_config.erl index 4160bba..f86f593 100644 --- a/src/rlx_config.erl +++ b/src/rlx_config.erl @@ -346,6 +346,16 @@ merge_configs([{Key, Value} | CliTerms], ConfigTerms) -> merge_configs(CliTerms, lists:reverse(lists:keystore(Key, 1, lists:reverse(ConfigTerms), {Key, Value}))) end. +parse_vsn(Vsn) when Vsn =:= git ; Vsn =:= "git" -> + {ok, V} = ec_git_vsn:vsn(ec_git_vsn:new()), + V; +parse_vsn({git, short}) -> + git_ref("--short"); +parse_vsn({git, long}) -> + git_ref(""); +parse_vsn({file, File}) -> + {ok, Vsn} = file:read_file(File), + binary_to_list(rlx_string:trim(Vsn, both, "\n")); parse_vsn(Vsn) when Vsn =:= semver ; Vsn =:= "semver" -> {ok, V} = ec_git_vsn:vsn(ec_git_vsn:new()), V; @@ -357,3 +367,20 @@ parse_vsn({cmd, Command}) -> V; parse_vsn(Vsn) -> Vsn. + +git_ref(Arg) -> + case os:cmd("git rev-parse " ++ Arg ++ " HEAD") of + String -> + Vsn = rlx_string:trim(String, both, "\n"), + case length(Vsn) =:= 40 orelse length(Vsn) =:= 7 of + true -> + Vsn; + false -> + %% if the result isn't exactly either 40 or 7 characters then + %% it must have failed + {ok, Dir} = file:get_cwd(), + ec_cmd_log:warn("Getting ref of git repo failed in ~ts. " + "Falling back to version 0", [Dir]), + {plain, "0"} + end + end. |