Skip to content

Instantly share code, notes, and snippets.

@RJ
Created September 18, 2010 14:19
Show Gist options
  • Save RJ/585714 to your computer and use it in GitHub Desktop.
Save RJ/585714 to your computer and use it in GitHub Desktop.
% Check some stuff, write the .rel file, generate boot scripts and relup, make tar
-module(release_helper).
-export([go/1]).
-define(RELAPPS, [ kernel,
stdlib,
sasl,
crypto,
ssl,
inets,
public_key,
compiler,
syntax_tools,
edoc,
eunit,
xmerl,
epgsql,
mochiweb]).
appver(A) when is_atom(A) ->
application:load(A),
io:format("Version of '~p'..", [A]),
{value, {A, _, Ret}} = lists:keysearch(A, 1, application:loaded_applications()),
io:format("~p~n", [Ret]),
Ret.
check_appfile_version(File, AppName, ExpectedVer) ->
io:format("Verifying .app file contains correct version..",[]),
{ok, [{application, AppName, Props}]} = file:consult(File),
case proplists:get_value(vsn, Props) of
ExpectedVer -> io:format("ok~n",[]), ok;
FoundVer -> io:format("FAIL~nApp file contains ver: ~s but expected: ~s~n",
[FoundVer, ExpectedVer]),
halt(1)
end.
go(Args) ->
[Name, Version, Ebin, PVersion, _PEbin] = Args,
io:format("release_helper running for: ~p, oldversion: ~s, new version: ~s~n",
[Name, PVersion, Version]),
ok = check_appfile_version(Ebin ++ "/" ++ Name ++ ".app",
list_to_atom(Name), Version),
Erts = erlang:system_info(version),
Vsn = io_lib:format("~s-~s", [Name, Version]),
PrevVsn = io_lib:format("~s-~s", [Name, PVersion]),
io:format("version: '~s'~n", [Version]),
AppVers = [{A,appver(A)} || A <- ?RELAPPS],
Rel =
"{release,
{\"~s\", \"~s\"},
{erts, \"~s\"},
[ {~w, \"~s\"},~n "
++
string:join([io_lib:format("{~w, \"~s\"}",[A,AV]) || {A,AV} <- AppVers],
",\n ")
++
"\n ]\n}.\n",
RelText = io_lib:format(Rel, [Name, Version, Erts, list_to_atom(Name), Version]),
Relfile = io_lib:format("~s.rel", [Vsn]),
io:format("Writing ~s~n", [Relfile]),
{ok, Fs} = file:open(Relfile, [write]),
io:format(Fs, RelText, []),
file:close(Fs),
io:format("make_script(~s)..~n", [Vsn]),
ok = systools:make_script(Vsn),
case PVersion of
"0" -> io:format("Previous version 0, not generating relup!~n", []);
_ -> ok = systools:make_relup(Vsn, [PrevVsn], [PrevVsn])
end,
ok = systools:make_tar(Vsn),
halt().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment