Skip to content

Commit

Permalink
Add --without-docs option for publish task (#210)
Browse files Browse the repository at this point in the history
* Add --without-docs option for publish task

 - Add a --without-docs option for the publish task which defaults to
   false. If switched on, will only publish a package regardless of configuration.
  • Loading branch information
starbelly authored Mar 17, 2021
1 parent c139189 commit 15cbd43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/rebar3_hex_publish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ init(State) ->
{yes, $y, "yes", {boolean, false}, help(yes)},
{replace, undefined, "replace", {boolean, false}, help(replace)},
{package, $p, "package", string, help(package)},
{revert, undefined, "revert", string, help(revert)}]}]),
{revert, undefined, "revert", string, help(revert)},
{without_docs, undefined, "without-docs", {boolean, false}, help(without_docs)}]}]),
State1 = rebar_state:add_provider(State, Provider),
{ok, State1}.

Expand Down Expand Up @@ -114,7 +115,7 @@ format_error(no_write_key) ->
"No write key found for user. Be sure to authenticate first with:"
++ " rebar3 hex user auth";

format_error({publish, {error, {tarball, _} = Err}}) ->
format_error({publish, {error, {tarball, _} = Err}}) ->
hex_tarball:format_error(Err);
format_error({publish, {error, #{<<"errors">> := Errors, <<"message">> := Message}}}) ->
ErrorString = errors_to_string(Errors),
Expand Down Expand Up @@ -248,8 +249,14 @@ publish_package_and_docs(Name, Version, Metadata, PackageFiles, HexConfig, App,
case create_and_publish(HexOpts, Metadata, PackageFiles, HexConfig1) of
ok ->
rebar_api:info("Published ~s ~s", [Name, Version]),
rebar3_hex_docs:publish(App, State, HexConfig1),
{ok, State};
case proplists:get_bool(without_docs, Args) of
true ->
rebar_api:info("--without-docs is enabled : will not publish docs", []),
{ok, State};
false ->
rebar3_hex_docs:publish(App, State, HexConfig1),
{ok, State}
end;
Error={error, _} ->
Error
end;
Expand All @@ -270,14 +277,14 @@ maybe_say_coc(_) ->

create_and_publish(Opts, Metadata, PackageFiles, HexConfig) ->
case hex_tarball:create(Metadata, PackageFiles) of
{ok, #{tarball := Tarball, inner_checksum := _Checksum}} ->
{ok, #{tarball := Tarball, inner_checksum := _Checksum}} ->
case rebar3_hex_client:publish(HexConfig, Tarball, Opts) of
{ok, _Res} ->
ok;
Error ->
?PRV_ERROR({publish, Error})
end;
Error ->
Error ->
?PRV_ERROR({publish, Error})
end.

Expand Down Expand Up @@ -500,7 +507,9 @@ help(replace) ->
"packages can always be overwritten, publicpackages can only be "
"overwritten within one hour after they were initially published.";
help(yes) ->
"Publishes the package without any confirmation prompts".
"Publishes the package without any confirmation prompts";
help(without_docs) ->
"Publishing a package without publishing documentation that may be automatically generated".

support() ->
"Publishes a new version of a package with options to revert and replace existing packages~n~n"
Expand Down
8 changes: 8 additions & 0 deletions test/rebar3_hex_integration_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ all() ->
, publish_org_requires_repo_arg_test
, publish_error_test
, publish_unauthorized_test
, publish_without_docs_test
, key_list_test
, key_get_test
, key_add_test
Expand Down Expand Up @@ -548,6 +549,13 @@ publish_unauthorized_test(Config) ->
<<"account not authorized for this action">>}}}}},
?assertMatch(Exp, rebar3_hex_publish:do(PubState)).

publish_without_docs_test(Config) ->
P = #{app => "valid", mocks => [publish]},
{ok, #{rebar_state := State, repo := Repo}} = setup_state(P, Config),
RepoConfig = [{repos,[Repo]}],
{ok, PubState} = test_utils:mock_command(rebar3_hex_publish, ["--without-docs"], RepoConfig, State),
?assertMatch({ok, PubState}, rebar3_hex_publish:do(PubState)).

key_list_test(Config) ->
P = #{app => "valid", mocks => []},
{ok, #{rebar_state := State, repo := Repo}} = setup_state(P, Config),
Expand Down

0 comments on commit 15cbd43

Please sign in to comment.