Skip to content

Instantly share code, notes, and snippets.

@rnewson
Created June 10, 2015 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnewson/6e7bad37dd8a85d9de05 to your computer and use it in GitHub Desktop.
Save rnewson/6e7bad37dd8a85d9de05 to your computer and use it in GitHub Desktop.
scan deps for updates
#!/usr/bin/env escript
-mode(compile).
main(_) ->
lists:foreach(fun({Dep, Vsn}) ->
fetch_dep(Dep),
show_dep(Dep, Vsn)
end, load_deps()).
load_deps() ->
{ok, Config} = file:consult(locate_rebar_config()),
Deps = proplists:get_value(deps, Config),
lists:sort(lists:flatmap(fun
({Dep, ".*", {git, _Url, Vsn}}) -> [{Dep, Vsn}];
({_, _, _, [raw]}) -> []
end, Deps)).
fetch_dep(Dep) ->
Cmd = [
"cd ",
dep_dir(Dep),
"; git fetch origin"
],
os:cmd(Cmd).
show_dep(Dep, Spec) ->
Cmd = mk_cmd(Dep, Spec),
Out = os:cmd(Cmd),
Stripped = string:strip(Out),
if Stripped == "" -> ok; true ->
io:format("~s :: ~p~n", [Dep, Spec]),
io:format("~s~n~n", [Out])
end.
mk_cmd(Dep, {tag, Tag}) ->
[
"cd ",
dep_dir(Dep),
"; git log --format=\"%h %s\" ",
Tag,
"..origin/master"
];
mk_cmd(Dep, {branch, Branch}) ->
[
"cd ",
dep_dir(Dep),
"; git log --format=\"%h %s\" ",
io_lib:format("~s", [Branch]),
"..origin/master"
].
locate_rebar_config() ->
filename:join(the_root(), "rebar.config").
dep_dir(Dep) ->
filename:join([the_root(), "deps", atom_to_list(Dep)]).
the_root() ->
ESName = escript:script_name(),
AbsESName = filename:absname(ESName),
filename:dirname(filename:dirname(AbsESName)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment