Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add dialyzer to pipeline #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 10 additions & 20 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@ 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
env:
MIX_ENV: test
EVENTSTORE_HOST: localhost
EVENTSTORE_VERSION: ${{ matrix.eventstore }}

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

- name: Set the EventStoreDB version
run: sed -i 's|ghcr.io/eventstore/eventstore:ci|eventstore/eventstore:${{ matrix.eventstore }}-buster-slim|g' docker-compose.yml
Expand All @@ -34,27 +28,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

Comment on lines -38 to 35
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compatibility workflow should check a range of old/new Elixir and Erlang/OTP versions rather than use the main .tool-versions. Removing credo and updating to the new actions v3 versions looks good though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my understanding is that it is valuable to check against a range of Event Store DB versions, but since Elixir 1.10, there is not much value in adding such a matrix IMO.

Being said, sure I can add it back

- 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 +65,3 @@ jobs:

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

- name: Credo
run: mix credo
15 changes: 5 additions & 10 deletions .github/workflows/refresh-dev-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,14 @@ jobs:

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

- 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
uses: actions/checkout@v3

- name: Setup Elixir and Erlang versions
uses: erlef/[email protected]
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@v1
Expand Down
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
Comment on lines +1 to +2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥺🥺🥺🥺 please 🥺🥺🥺🥺

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this to the CI and using it locally is ok but we should also test against earlier Elixir versions as far back as 1.9

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 docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
# messages via wireshark
# command: "--insecure --run-projections=All"
ports:
- 2113:2113
- '2113:2113'

app:
image: elixir:1.12.2
Expand Down
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],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

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