Skip to content

Commit

Permalink
Merge pull request #121 from paulo-ferraz-oliveira/feature/modern_ci
Browse files Browse the repository at this point in the history
Modernize CI
  • Loading branch information
elbrujohalcon authored Nov 2, 2020
2 parents 2a71582 + 124179d commit 7f89758
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 37 deletions.
27 changes: 16 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
sudo: false
language: erlang

os:
- linux

otp_release:
- 20.1
- 19.3
before_install:
- ./ci before_install "${PWD:?}"/rebar3
install:
- ./ci install "${PWD:?}"/rebar3
- 19.3
- 20.3
- 21.3
- 22.3
- 23.0

script:
- ./ci script "${PWD:?}"/rebar3
cache:
directories:
- .plt
- rebar3 --version
- erl -version
- rebar3 xref
- rebar3 lint
- rebar3 dialyzer
- rebar3 ct
21 changes: 0 additions & 21 deletions ci

This file was deleted.

11 changes: 6 additions & 5 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

{profiles, [
{test, [
{deps, [ {katana_test, "1.0.0"}
{deps, [ {katana_test, "1.0.1"}
, {mixer, "1.0.0", {pkg, inaka_mixer}}
, {shotgun, "0.3.0"}
, {shotgun, "0.5.0"}
]}
]}
]}.
Expand Down Expand Up @@ -77,14 +77,15 @@
{cowboy_swagger, validate_metadata, 1},
{cowboy_swagger, filter_cowboy_swagger_handler, 1},
{cowboy_swagger_handler, trails, 1},
{cowboy_swagger_json_handler, handle_get, 2}]}.
{cowboy_swagger_json_handler, handle_get, 2},
{cowboy_swagger, add_definition_array, 2},
{cowboy_swagger, get_existing_definitions, 1}]}.

%% == Dialyzer ==

{dialyzer, [ {warnings, [ no_return
, unmatched_returns
, error_handling
, unknown
]}
, {plt_apps, top_level_deps}
, {plt_extra_apps, [cowboy, trails, ranch, jsx]}
Expand All @@ -95,4 +96,4 @@

%% == Shell ==

{plugins, [rebar3_auto]}.
{plugins, [rebar3_auto, {rebar3_lint, "0.2.0"}]}.
6 changes: 6 additions & 0 deletions test/example_default.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
]).

%% cowboy
-spec init(any(), any(), any()) -> {upgrade, protocol, cowboy_rest}.
init(_Transport, _Req, _Opts) ->
{upgrade, protocol, cowboy_rest}.

-spec rest_init(Req, any()) -> {ok, Req, #{}}.
rest_init(Req, _Opts) ->
{ok, Req, #{}}.

-spec content_types_accepted(Req, State) -> {[{binary(), handle_put}], Req, State}.
content_types_accepted(Req, State) ->
{[{<<"text/plain">>, handle_put}], Req, State}.

-spec content_types_provided(Req, State) -> {[{binary(), handle_get}], Req, State}.
content_types_provided(Req, State) ->
{[{<<"text/plain">>, handle_get}], Req, State}.

-spec forbidden(Req, State) -> {false, Req, State}.
forbidden(Req, State) ->
{false, Req, State}.

-spec resource_exists(Req, State) -> {true, Req, State}.
resource_exists(Req, State) ->
{true, Req, State}.
3 changes: 3 additions & 0 deletions test/example_description_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
-behaviour(trails_handler).
-export([trails/0]).

-spec trails() -> [trails:trail()].
trails() ->
Metadata =
#{get =>
Expand All @@ -42,10 +43,12 @@ trails() ->
[trails:trail("/description", example_description_handler, [], Metadata)].

%% cowboy
-spec allowed_methods(Req, State) -> {[binary(), ...], Req, State}.
allowed_methods(Req, State) ->
{[<<"GET">>], Req, State}.

%% internal
-spec handle_get(Req, State) -> {[trails:trail()], Req, State}.
handle_get(Req, State) ->
Body = trails:all(),
{io_lib:format("~p~n", [Body]), Req, State}.
4 changes: 4 additions & 0 deletions test/example_echo_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-behaviour(trails_handler).
-export([trails/0]).

-spec trails() -> [trails:trail()].
trails() ->
Metadata =
#{get =>
Expand Down Expand Up @@ -70,15 +71,18 @@ trails() ->
[trails:trail("/message/[:echo]", example_echo_handler, [], Metadata)].

%% cowboy
-spec allowed_methods(Req, State) -> {[binary(), ...], Req, State}.
allowed_methods(Req, State) ->
{[<<"GET">>, <<"PUT">>, <<"HEAD">>], Req, State}.

%% internal
-spec handle_get(Req, State) -> {[binary(), ...], Req, State}.
handle_get(Req, State) ->
Echo = application:get_env(example, echo, ""),
Body = [<<"You Get an echo!">> , Echo],
{Body, Req, State}.

-spec handle_put(cowboy_req:req(), State) -> {true, cowboy_req:req(), State}.
handle_put(Req, State) ->
{Echo, Req1} = cowboy_req:binding(echo, Req, ""),
application:set_env(example, echo, Echo),
Expand Down
2 changes: 2 additions & 0 deletions test/example_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
-export([init/1]).

%% admin api
-spec start_link() -> {ok, pid()}.
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, {}).

%% behaviour callbacks
-spec init({}) -> {ok, {{one_for_one, 5, 10}, []} }.
init({}) ->
{ok, {{one_for_one, 5, 10}, []} }.
3 changes: 3 additions & 0 deletions test/host1_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-behaviour(trails_handler).
-export([trails/0]).

-spec trails() -> [trails:trail()].
trails() ->
Metadata =
#{get =>
Expand All @@ -45,10 +46,12 @@ trails() ->
Metadata)].

%% cowboy
-spec allowed_methods(Req, State) -> {[binary(), ...], Req, State}.
allowed_methods(Req, State) ->
{[<<"GET">>], Req, State}.

%% internal
-spec handle_get(Req, State) -> {binary(), Req, State}.
handle_get(Req, State) ->
Host = cowboy_req:host(Req),
Body = <<"I am ", Host/binary>>,
Expand Down

0 comments on commit 7f89758

Please sign in to comment.