Skip to content

Commit

Permalink
chore: add dialyzer to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed Jun 13, 2023
1 parent da51387 commit 94b739a
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 109 deletions.
66 changes: 37 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,35 @@ jobs:
MIX_ENV: test
EVENTSTORE_HOST: localhost
EVENTSTORE_VERSION: nightly

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Spawn docker-compose EventStoreDB container
run: docker-compose up --detach eventstore

- name: Determine the elixir version
run: echo "ELIXIR_VERSION=$(grep -h elixir .tool-versions | awk '{ print $2 }' | awk -F - '{print $1}')" >> $GITHUB_ENV

- name: Determine the otp version
run: echo "OTP_VERSION=$(grep -h erlang .tool-versions | awk '{ print $2 }')" >> $GITHUB_ENV

- name: Setup Elixir and Erlang versions
uses: erlef/setup-beam@v1
id: beam
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
version-file: .tool-versions
version-type: strict

- name: Restore the deps cache
uses: actions/cache@v3
id: deps-cache
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps
path: deps
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-

- name: Restore the _build cache
uses: actions/cache@v3
id: build-cache
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ env.MIX_ENV }}-build
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ env.MIX_ENV }}-build
path: _build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-

- name: Fetch mix dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
Expand All @@ -75,6 +67,29 @@ jobs:
- name: Credo
run: mix credo

- name: Restore PLT cache
uses: actions/cache/restore@v3
id: plt-cache
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
path: priv/plts

- name: Create PLTs
shell: sh
if: steps.plt-cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt

- name: Save PLT cache
uses: actions/cache/save@v3
if: steps.plt-cache.outputs.cache-hit != 'true'
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
path: priv/plts

- name: Run dialyzer
run: mix dialyzer --format github

publish-hex-package:
name: Publish Hex Package ⬆️☁️
runs-on: ubuntu-20.04
Expand All @@ -88,35 +103,28 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Determine the elixir version
run: echo "ELIXIR_VERSION=$(grep -h elixir .tool-versions | awk '{ print $2 }' | awk -F - '{print $1}')" >> $GITHUB_ENV

- name: Determine the otp version
run: echo "OTP_VERSION=$(grep -h erlang .tool-versions | awk '{ print $2 }')" >> $GITHUB_ENV

- name: Setup Elixir and Erlang versions
uses: erlef/setup-beam@v1
id: beam
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}
version-file: .tool-versions
version-type: strict

- name: Restore the deps cache
uses: actions/cache@v3
id: deps-cache
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps
path: deps
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-

- name: Restore the _build cache
uses: actions/cache@v3
id: build-cache
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ env.MIX_ENV }}-build
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ env.MIX_ENV }}-build
path: _build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-

- name: Fetch mix dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
Expand Down
27 changes: 9 additions & 18 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ jobs:
strategy:
fail-fast: false
matrix:
beam:
- elixir: "1.7.4"
otp: "21.3"
- elixir: "1.12.3"
otp: "24.0"
eventstore:
- 20.10.2
- 22.6.0
Expand All @@ -34,27 +29,26 @@ jobs:

- name: Setup Elixir and Erlang versions
uses: erlef/setup-beam@v1
id: beam
with:
otp-version: ${{ matrix.beam.otp }}
elixir-version: ${{ matrix.beam.elixir }}
version-file: .tool-versions
version-type: strict

- name: Restore the deps cache
uses: actions/cache@v1
uses: actions/cache@v3
id: deps-cache
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps
path: deps
key: ${{ runner.os }}-${{ matrix.beam.elixir }}-${{ matrix.beam.otp }}-${{ env.MIX_ENV }}-deps-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ matrix.beam.elixir }}-${{ matrix.beam.otp }}-${{ env.MIX_ENV }}-deps-

- name: Restore the _build cache
uses: actions/cache@v1
uses: actions/cache@v3
id: build-cache
with:
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ env.MIX_ENV }}-build
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-${{ env.MIX_ENV }}-build
path: _build
key: ${{ runner.os }}-${{ matrix.beam.elixir }}-${{ matrix.beam.otp }}-${{ env.MIX_ENV }}-build-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ matrix.beam.elixir }}-${{ matrix.beam.otp }}-${{ env.MIX_ENV }}-build-

- name: Fetch mix dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
Expand All @@ -72,6 +66,3 @@ jobs:

- name: Run tests
run: mix test --exclude version_incompatible

- name: Credo
run: mix credo
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ erl_crash.dump
# Ignore package tarball (built via "mix hex.build").
spear-*.tar


# Temporary files for e.g. tests
/tmp

/priv/plts/*.plt
/priv/plts/*.plt.hash
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.12.3-otp-24
erlang 24.0
elixir 1.14.5-otp-26
erlang 26.0
14 changes: 12 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
use Mix.Config
import Config

import_config "#{Mix.env()}.exs"
config :spear, Spear.Test.ClientFixture, connection_string: "esdb://localhost:2113"

host = System.get_env("EVENTSTORE_HOST") || "localhost"

config :spear, :config,
connection_string: "esdb://admin:changeit@#{host}:2113?tls=true",
mint_opts: [
transport_opts: [
cacertfile: Path.join([__DIR__ | ~w(.. eventstoredb certs ca ca.crt)])
]
]
1 change: 0 additions & 1 deletion config/dev.exs

This file was deleted.

1 change: 0 additions & 1 deletion config/prod.exs

This file was deleted.

13 changes: 0 additions & 13 deletions config/test.exs

This file was deleted.

2 changes: 1 addition & 1 deletion lib/spear.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ defmodule Spear do
stream_name :: String.t() | :all,
group_name :: String.t(),
opts :: Keyword.t()
) :: {:ok, Spear.PersistentSubcription.Info.t()} | {:error, any()}
) :: {:ok, Spear.PersistentSubscription.Info.t()} | {:error, any()}
def get_persistent_subscription_info(conn, stream_name, group_name, opts \\ [])
when (is_binary(stream_name) or stream_name == :all) and is_binary(group_name) do
get_info_message =
Expand Down
14 changes: 7 additions & 7 deletions lib/spear/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ defmodule Spear.Connection do

defstruct [:config, :conn, requests: %{}, keep_alive_timer: %KeepAliveTimer{}]

@type state :: %__MODULE__{}

@typedoc """
A connection process
Expand Down Expand Up @@ -152,9 +154,7 @@ defmodule Spear.Connection do

%Config{errors: errors} ->
error_lines =
errors
|> Enum.map(fn {key, error} -> "\t#{inspect(key)}: #{error}" end)
|> Enum.join("\n")
Enum.map_join(errors, "\n", fn {key, error} -> "\t#{inspect(key)}: #{error}" end)

Logger.error("""
Invalid configuration passed to #{inspect(__MODULE__)}. Found the following errors:
Expand Down Expand Up @@ -327,10 +327,10 @@ defmodule Spear.Connection do
def handle_info(:keep_alive_expired, s), do: {:disconnect, :keep_alive_timeout, s}

def handle_info(message, s) do
with %Mint.HTTP2{} = conn <- s.conn,
{:ok, conn, responses} <- Mint.HTTP2.stream(conn, message) do
{:noreply, put_in(s.conn, conn) |> handle_responses(responses)}
else
case Mint.HTTP2.stream(s.conn, message) do
{:ok, conn, responses} ->
{:noreply, put_in(s.conn, conn) |> handle_responses(responses)}

# coveralls-ignore-start
{:error, conn, reason, responses} ->
s = put_in(s.conn, conn) |> handle_responses(responses)
Expand Down
4 changes: 2 additions & 2 deletions lib/spear/connection/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ defmodule Spear.Connection.Request do
{[{message, message_size} | message_buffer], message_size + message_buffer_size, max_size}}
end

@spec emit_messages(%Spear.Connection{}, %__MODULE__{}) ::
{:ok, %Spear.Connection{}} | {:error, %Spear.Connection{}, reason :: any()}
@spec emit_messages(Spear.Connection.state(), %__MODULE__{}) ::
{:ok, Spear.Connection.state()} | {:error, Spear.Connection.state(), reason :: any()}
def emit_messages(state, %__MODULE__{status: :done, buffer: <<>>}), do: {:ok, state}

def emit_messages(state, %__MODULE__{status: :done, buffer: buffer} = request) do
Expand Down
7 changes: 7 additions & 0 deletions lib/spear/connection/response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ defmodule Spear.Connection.Response do

# a slim data structure for storing information about an HTTP/2 response

@type t :: %__MODULE__{
status: Mint.Types.status(),
type: {module(), atom()},
headers: Mint.Types.headers(),
data: binary()
}

defstruct [:status, :type, headers: [], data: <<>>]
end
2 changes: 1 addition & 1 deletion lib/spear/reading/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ defmodule Spear.Reading.Stream do
response
end

@spec unfold_chunk(binary()) :: {struct(), binary()} | nil
@spec unfold_chunk(binary()) :: {tuple(), binary()} | nil
def unfold_chunk(buffer) when is_binary(buffer) do
Spear.Grpc.decode_next_message(
buffer,
Expand Down
18 changes: 12 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ defmodule Spear.MixProject do
inch: :dev,
bless: :test,
test: :test,
dialyzer: :test
dialyzer: :dev
],
name: "Spear",
source_url: @source_url,
deps: deps(),
docs: docs(),
package: package(),
description: description()
description: description(),
dialyzer: [
plt_add_apps: [:jason],
plt_file: {:no_warn, "priv/plts/dialyzer.plt"}
]
]
end

Expand All @@ -50,14 +54,16 @@ defmodule Spear.MixProject do
{:event_store_db_gpb_protobufs, "~> 2.2"},
{:connection, "~> 1.0"},
# optional dependencies
{:jason, ">= 0.0.0", optional: true},
{:jason, "~> 1.0", optional: true},

# dev/test utilities
{:castore, ">= 0.0.0", only: [:dev, :test]},
{:ex_doc, "~> 0.24", only: :dev, runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:dialyxir, ">= 0.0.0", only: [:dev, :test], runtime: false},
# testing suite
{:credo, "~> 1.5", only: :test},
{:credo, ">= 0.0.0", only: :test},
{:bless, "~> 1.0", only: :test},
{:excoveralls, "~> 0.7", only: :test}
{:excoveralls, ">= 0.0.0", only: :test}
]
end

Expand Down
Loading

0 comments on commit 94b739a

Please sign in to comment.