diff --git a/README.md b/README.md index a651b83..cff44d0 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Help Usage: rebar3 relflow [-u ] [-x []] [-g []] - [-f []] + [-f []] [-s [semver]] -u, --upfrom Git revision/tag to upgrade from (for appup generation) @@ -144,9 +144,10 @@ Help [default: true] -f, --force Force relflow to run even with uncommitted local changes [default: false] + -s, --semver Compare the versions as semantic versions (0.0.9 < 0.0.10) + [default: false] -v, --version Print relflow version and exit - License ------- diff --git a/src/relflow.erl b/src/relflow.erl index fd92b21..4cb4558 100644 --- a/src/relflow.erl +++ b/src/relflow.erl @@ -46,7 +46,9 @@ opts() -> {force, $f, "force", {boolean, false}, "Force relflow to run even with uncommitted local changes"}, {version, $v, "version", undefined, - "Print relflow version and exit"} + "Print relflow version and exit"}, + {semver, $s, "semver", {boolean, false}, + "Uses semantic versioning to compare versions"} ]. relflow_version() -> @@ -152,11 +154,28 @@ exec(Map, State, Next) -> exec_1(Map, State, Next) -> NewRelVsn = relflow_state:nextver(State), - case NewRelVsn > relflow_state:oldrelver(State) of + OldRelVsn = relflow_state:oldrelver(State), + case greater_than(NewRelVsn, OldRelVsn, relflow_state:semver(State)) of true -> Next(Map, State, NewRelVsn); - false -> ?PRV_ERROR({relvsn_ordering, relflow_state:oldrelver(State), NewRelVsn}) + false -> ?PRV_ERROR({relvsn_ordering, OldRelVsn, NewRelVsn}) end. +greater_than(NewVersion, OldVersion, true) -> + [NewMajor, NewMinor, NewPatch] = lists:map(fun string:to_integer/1, string:tokens(NewVersion, ".")), + [OldMajor, OldMinor, OldPatch] = lists:map(fun string:to_integer/1, string:tokens(OldVersion, ".")), + if + NewMajor > OldMajor -> true; + NewMajor < OldMajor -> false; + NewMajor == OldMajor -> + if + NewMinor > OldMinor -> true; + NewMinor < OldMinor -> false; + NewMinor == OldMinor -> NewPatch > OldPatch + end + end; +greater_than(NewVersion, OldVersion, false) -> NewVersion > OldVersion. + + exec_2(Map, State, NewRelVsn) -> lists:foreach(fun({_AppName, #{appup_path := Path, appup_term := T, diff --git a/src/relflow_state.erl b/src/relflow_state.erl index 8399689..dcc5967 100644 --- a/src/relflow_state.erl +++ b/src/relflow_state.erl @@ -20,6 +20,7 @@ profile/1, force/1, autogit/1, + semver/1, rebar_state/1, nextver/1, set_default_nextver/2, @@ -45,6 +46,8 @@ upfrom(State) -> parg(upfrom, State). autogit(State) -> parg(autogit, State) == true. +semver(State) -> parg(semver, State) == true. + profile(State) -> lists:last(filename:split(build_dir(State))). nextappver(#relflow_st{nextappver=V}) -> V.