Skip to content

Commit

Permalink
chore: update CI (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
javiergarea authored Apr 28, 2023
1 parent 61db368 commit 5c2baa6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 64 deletions.
51 changes: 0 additions & 51 deletions .github/workflows/build.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: nmaglev ci

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
OTP-VERSION: 25.2.3
REBAR3-VERSION: 3.20.0

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP-VERSION }}
rebar3-version: ${{ env.REBAR3-VERSION }}

- uses: actions/[email protected]
id: rebar3-cache
with:
path: |
~/.cache/rebar3
_build
key: ${{ runner.os }}-${{ env.OTP-VERSION }}-${{ env.REBAR3-VERSION }}-${{ hashFiles('rebar.lock') }}

- name: Compile
run: |
rebar3 clean
rebar3 compile
- run: rebar3 check

- run: rebar3 test

- name: Create test summary
uses: test-summary/action@v1
if: always()
with:
paths: '_build/test/logs/**/report.xml'
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# nmaglev

![nmaglev](https://github.com/nomasystems/nmaglev/actions/workflows/build.yml/badge.svg)
[![nmaglev ci](https://github.com/nomasystems/nmaglev/actions/workflows/ci.yml/badge.svg)](https://github.com/nomasystems/nmaglev/actions/workflows/ci.yml)

Erlang implementation of the consistent hashing algorithm used in the load balancing MagLev system.

Expand Down
13 changes: 8 additions & 5 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{erl_opts, []}.
{erl_opts, [
warnings_as_errors
]}.

{plugins, [
{erlfmt, {git, "[email protected]:nomasystems/erlfmt.git", {tag, "v1.0.0"}}}
{project_plugins, [
{erlfmt, {git, "[email protected]:WhatsApp/erlfmt.git", {branch, "main"}}},
{gradualizer, {git, "[email protected]:josefs/Gradualizer.git", {branch, "master"}}}
]}.
{erlfmt, [write]}.

{alias, [
{check, [
{fmt, "--check"},
xref,
dialyzer
dialyzer,
gradualizer
]},
{test, [
{ct, "--spec test/conf/test.spec --cover --readable true"}
Expand All @@ -30,7 +34,6 @@
{cover_opts, [verbose]}.
{cover_enabled, true}.

% Ignore xref warnings on public external exports
{xref_ignores, [
{nmaglev, create, 1},
{nmaglev, create, 2},
Expand Down
14 changes: 8 additions & 6 deletions src/nmaglev.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%%
-module(nmaglev).

%%% EXTERNAL EXPORTS
Expand All @@ -26,7 +25,6 @@
%%%-----------------------------------------------------------------------------
%%% EXTERNAL EXPORTS
%%%-----------------------------------------------------------------------------

-spec create(Outputs) -> MaglevTable when
Outputs :: list(),
MaglevTable :: maglev_table().
Expand All @@ -38,7 +36,6 @@ create(Outputs) ->
Outputs :: list(),
LookupSize :: non_neg_integer(),
MaglevTable :: maglev_table().

create(Outputs, LookupSize) ->
OutputsLen = erlang:length(Outputs),
PermutationsTable = permutations(Outputs, LookupSize),
Expand All @@ -47,10 +44,15 @@ create(Outputs, LookupSize) ->
-spec get(Key, MaglevTable) -> Output when
Key :: binary(),
MaglevTable :: maglev_table(),
Output :: term().
Output :: term() | {error, empty_maglev_table}.
get(Key, Lookup) ->
Offset = erlang:phash2(Key, maps:size(Lookup)),
maps:get(Offset, Lookup).
case maps:size(Lookup) of
0 ->
{error, empty_maglev_table};
Size ->
Offset = erlang:phash2(Key, Size),
maps:get(Offset, Lookup)
end.

%%%-----------------------------------------------------------------------------
%%% INTERNAL FUNCTIONS
Expand Down

0 comments on commit 5c2baa6

Please sign in to comment.