Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Aug 31, 2024
1 parent 7255bd2 commit 0cdd007
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 59 deletions.
53 changes: 33 additions & 20 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
---
name: build
name: ci/cd

on:
workflow_dispatch:
push:
branches:
- master
branches: [ main, 'release/*' ]
pull_request:
branches:
- master
branches: [ main, 'release/*' ]
# Build once a month, just to be sure things are still working
schedule:
- cron: "19 3 26 * *"

jobs:
ci:
name: Run checks and tests over ${{matrix.otp_vsn}} and ${{matrix.os}}
runs-on: ${{matrix.os}}
container:
image: erlang:${{matrix.otp_vsn}}

builds:
name: Erlang ${{ matrix.otp_version }} build
runs-on: ubuntu-latest

strategy:
matrix:
otp_vsn: [20.3, 21.3, 22.3, 23.0]
os: [ubuntu-latest]
otp_version: ['26', '25', '24', '25', '26', '27']

steps:
- uses: actions/checkout@v2
- run: rebar3 --version
- run: rebar3 as test xref
- run: rebar3 as test dialyzer
- run: rebar3 lint
- run: rebar3 ct
- run: rebar3 cover
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp_version }}
rebar3-version: '3.22'
- name: Compile
run: rebar3 compile
- name: Xref Checks
run: rebar3 xref
#- name: Dialyzer
# run: rebar3 dialyzer
#- name: Proper Tests
# run: rebar3 as test do compile, proper --regressions
#- name: Run Unit Tests
# run: rebar3 as test lfe ltest -tall
- name: Run Common Tests
run: rebar3 ct -v
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ deleting log files, you should be able to use a single build tool.

This is a very simple and straightforward plugin. Simply describe your
command in `rebar.config` and execute (just like you would Linux aliases)
with `rebar3 cmd <command>`.
with `rebar3 oscmd <command>`.

## Usage

Add the plugin to your `rebar.config`:

```erlang
{plugins, [
{rebar3_oscmd, "0.4.1"}
{rebar3_oscmd, "0.5.0"}
]}.

{commands, [
Expand Down
10 changes: 5 additions & 5 deletions src/r3_oscmd_prv.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(rebar_cmd_prv).
-module(r3_oscmd_prv).

-export([
init/1,
Expand All @@ -17,7 +17,7 @@
{providers, create, 1}
]).

-define(PROVIDER, cmd).
-define(PROVIDER, oscmd).
-define(DEPS, [app_discovery]).
-define(DEFAULT_OPT_TIMEOUT, 15000).
-define(DEFAULT_OPT_VERBOSE, false).
Expand All @@ -44,10 +44,10 @@ init(State) ->
{module, ?MODULE},
{bare, true},
{deps, ?DEPS},
{example, "rebar3 cmd <command>"},
{example, "rebar3 oscmd <command>"},
{opts, []},
{short_desc, "A rebar3 plugin to run custom shell commands 'cmd <command>'."},
{desc, "A rebar3 plugin to run custom shell commands 'cmd <command>'"}
{short_desc, "A rebar3 plugin to run custom shell commands 'oscmd <shell command>'."},
{desc, "A rebar3 plugin to run custom shell commands 'oscmd <shell command>'"}
]),
{ok, rebar_state:add_provider(State, Provider)}.

Expand Down
9 changes: 4 additions & 5 deletions src/rebar3_oscmd.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, rebar_cmd,
[{description, "Run custom shell commands with rebar3 cmd <command>"},
{vsn, "0.4.0"},
{application, rebar3_oscmd,
[{description, "Run custom shell commands with rebar3 oscmd <shell command>"},
{vsn, "0.5.0"},
{registered, []},
{applications,
[kernel,
Expand All @@ -9,7 +9,6 @@
{env,[]},
{modules, []},

{maintainers, ["Sasan Hezarkhani", "Matheus Mendes", "Ahmad Mokhtar", "Paulo F. Oliveira"]},
{licenses, ["MIT"]},
{links, [{"Github", "https://github.com/gootik/rebar_cmd"}]}
{links, [{"Github", "https://github.com/erlsci/rebar3_oscmd"}]}
]}.
4 changes: 2 additions & 2 deletions src/rebar3_oscmd.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-module(rebar_cmd).
-module(rebar3_oscmd).

-export([init/1]).

-ignore_xref([init/1]).

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
{ok, State1} = rebar_cmd_prv:init(State),
{ok, State1} = r3_oscmd_prv:init(State),
{ok, State1}.
50 changes: 25 additions & 25 deletions test/rebar3_oscmd_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(rebar_cmd_SUITE).
-module(rebar3_oscmd_SUITE).

-include_lib("stdlib/include/assert.hrl").

Expand Down Expand Up @@ -33,89 +33,89 @@ all() ->
].

command_not_atom(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(not_tuple, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(not_tuple, _FoundInSuiteConfig = true),
?assertMatch(
{error, _},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_tuple_1(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(tuple_1, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(tuple_1, _FoundInSuiteConfig = true),
?assertMatch(
{error, _},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_tuple_4(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(tuple_4, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(tuple_4, _FoundInSuiteConfig = true),
?assertMatch(
{error, _},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_not_in_commands(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(not_in_commands, _FoundInSuiteConfig = false),
{Cmd, CmdFound} = as_rebar3_oscmd(not_in_commands, _FoundInSuiteConfig = false),
?assertMatch(
{error, _},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_timeout_0(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(timeout_0, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(timeout_0, _FoundInSuiteConfig = true),
?assertMatch(
{error, _},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_timeout_1999(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(timeout_1999, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(timeout_1999, _FoundInSuiteConfig = true),
?assertMatch(
{error, _},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_verbose_false(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(non_verbose_ls, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(non_verbose_ls, _FoundInSuiteConfig = true),
?assertMatch(
{ok, no_state},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_verbose_true(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(verbose_ls, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(verbose_ls, _FoundInSuiteConfig = true),
?assertMatch(
{ok, no_state},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_not_string(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(not_string, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(not_string, _FoundInSuiteConfig = true),
?assertEqual(
{ok, no_state},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_timeout_not_integer(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(timeout_not_int, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(timeout_not_int, _FoundInSuiteConfig = true),
?assertMatch(
{ok, no_state},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

command_ok(_Config) ->
{Cmd, CmdFound} = as_rebar3_cmd(ok, _FoundInSuiteConfig = true),
{Cmd, CmdFound} = as_rebar3_oscmd(ok, _FoundInSuiteConfig = true),
?assertMatch(
{ok, no_state},
rebar_cmd_prv:do_internal({Cmd, CmdFound}, no_state)
r3_oscmd_prv:do_internal({Cmd, CmdFound}, no_state)
).

%% Internal

as_rebar3_cmd(Cmd, FoundInSuiteConfig) ->
as_rebar3_oscmd(Cmd, FoundInSuiteConfig) ->
FoundInSuiteConfig andalso
begin
true =
lists:keyfind(Cmd, 1, ?CONFIG) =/= false orelse
lists:member(Cmd, ?CONFIG)
end,
{atom_to_list(Cmd), rebar_cmd_prv:find_command_in(atom_to_list(Cmd), ?CONFIG)}.
{atom_to_list(Cmd), r3_oscmd_prv:find_command_in(atom_to_list(Cmd), ?CONFIG)}.

0 comments on commit 0cdd007

Please sign in to comment.