Skip to content
Merged
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
46 changes: 36 additions & 10 deletions .github/workflows/test_format_dialyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,26 @@ on:
jobs:
build:

name: Build and test
runs-on: ubuntu-latest
name: Build and test (${{ matrix.name }})
runs-on: ${{ matrix.runs-on }}

strategy:
fail-fast: false
matrix:
include:
# The versions we develop on.
- name: .tool-versions
runs-on: ubuntu-latest
version-file: .tool-versions
version-type: strict
lint: true
# The minimum versions mix.exs supports (`elixir: "~> 1.12"`), also used to publish to Hex.
- name: Elixir 1.12
runs-on: ubuntu-24.04 # The newest runner with builds of OTP 24
elixir: "1.12"
otp: "24"
version-type: loose
lint: false

steps:
- name: Checkout
Expand All @@ -21,8 +39,10 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
version-file: ${{ matrix.version-file }}
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
version-type: ${{ matrix.version-type }}

- name: Set mix.lock file hash environment variable
run: echo "MIX_LOCK_HASH=${{ hashFiles('**/mix.lock') }}" >> $GITHUB_ENV
Expand All @@ -32,8 +52,8 @@ jobs:
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-deps-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-mix-
key: ${{ runner.os }}-${{ matrix.name }}-deps-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ matrix.name }}-deps-

- name: Install dependencies
run: mix deps.get
Expand All @@ -42,21 +62,27 @@ jobs:
uses: actions/cache@v4
with:
path: _build
key: ${{ runner.os }}-build-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-build-
key: ${{ runner.os }}-${{ matrix.name }}-build-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ matrix.name }}-build-

- name: Compile
run: mix compile --warnings-as-errors

- name: Check formatting
if: matrix.lint
run: mix format --check-formatted

- name: Run tests
run: mix test

- name: Restore dialyzer PLTS
if: matrix.lint
uses: actions/cache@v4
with:
path: priv/plts
key: ${{ runner.os }}-plts-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-plts-
key: ${{ runner.os }}-${{ matrix.name }}-plts-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ matrix.name }}-plts-

- name: Run dialyzer
if: matrix.lint
run: mix dialyzer
4 changes: 3 additions & 1 deletion lib/configuration/flagsmith_configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ defmodule Flagsmith.Configuration do
:ok

false ->
Logger.warn("unknown option #{inspect(k)} passed as configuration to Flagsmith.Client")
Logger.warning(
"unknown option #{inspect(k)} passed as configuration to Flagsmith.Client"
)
end
end)

Expand Down
2 changes: 1 addition & 1 deletion lib/engine/evaluator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,6 @@ defmodule Flagsmith.Engine.Evaluator do
defp to_str(value) when is_integer(value), do: Integer.to_string(value)
defp to_str(value) when is_float(value), do: Float.to_string(value)
defp to_str(value) when is_atom(value), do: Atom.to_string(value)
defp to_str(%Version{} = value), do: Version.to_string(value)
defp to_str(%Version{} = value), do: to_string(value)
defp to_str(value), do: inspect(value)
end
2 changes: 1 addition & 1 deletion lib/engine/mappers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule Flagsmith.Engine.Mappers do
defp map_trait(%Traits.Trait{trait_key: key, trait_value: value}),
do: {key, map_trait_value(value)}

defp map_trait_value(%Version{} = value), do: Version.to_string(value)
defp map_trait_value(%Version{} = value), do: to_string(value)
defp map_trait_value(value), do: value

defp map_segment(%Segments.Segment{id: id, name: name} = segment) do
Expand Down
2 changes: 1 addition & 1 deletion lib/flagsmith_client_poller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ defmodule Flagsmith.Client.Poller do
# We should never receive this message but I like having a catch all for info msgs
# and just log.
def handle_event(:info, unknown, _state, _data) do
Logger.warn("#{inspect(__MODULE__)} received unexpected message: #{inspect(unknown)}")
Logger.warning("#{inspect(__MODULE__)} received unexpected message: #{inspect(unknown)}")
{:keep_state_and_data, []}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/flagsmith_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ defmodule Flagsmith.Engine do
end
rescue
Decimal.Error ->
Logger.warn(
Logger.warning(
"invalid MODULO segment rule or trait value :: rule: #{inspect(condition_value)} :: value: #{inspect(value)}"
)

Expand Down
2 changes: 1 addition & 1 deletion lib/schemas/traits/trait_value.ex
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ defimpl Jason.Encoder, for: Flagsmith.Schemas.Traits.Trait.Value do
# Jason encodes decimals as strings; send them as integers or floats instead.
defp to_json_value(%Decimal{exp: exp} = value) when exp >= 0, do: Decimal.to_integer(value)
defp to_json_value(%Decimal{} = value), do: Decimal.to_float(value)
defp to_json_value(%Version{} = value), do: Version.to_string(value)
defp to_json_value(%Version{} = value), do: to_string(value)
defp to_json_value(value), do: value
end
2 changes: 1 addition & 1 deletion test/flagsmith_configuration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ defmodule Flagsmith.Configuration.Test do
end

test "logs warning if unknown opt is passed" do
assert capture_log([level: :warn], fn ->
assert capture_log([level: :warning], fn ->
Configuration.build(environment_key: "A", api_url_typo: "something")
end) =~ "unknown option :api_url_typo passed as configuration to Flagsmith.Client"
end
Expand Down
8 changes: 5 additions & 3 deletions test/flagsmith_events_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,14 @@ defmodule Flagsmith.Client.Events.Test do
# When
pid = Processor.whereis(config.environment_key)

{state, log} =
with_log(fn ->
log =
capture_log(fn ->
:ok = Client.track_exposure_event(config, "banner", exposure)
:sys.get_state(pid)
send(self(), {:state, :sys.get_state(pid)})
end)

assert_received {:state, state}

# Then it's buffered again, the buffer dropping its oldest event for it
assert log =~ "dropping the oldest event_2 event"
events = :queue.to_list(state.buffer)
Expand Down
4 changes: 4 additions & 0 deletions test/support/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ defmodule Flagsmith.Test.Helpers do
defp assert_request_key(key, vals, env) when key in [:headers, :query],
do: assert_multiple_kv(vals, Map.get(env, key, []))

# Compare JSON bodies as data, as their key order isn't stable across OTP versions.
defp assert_request_key(:body, val, %{body: body}) when is_binary(val) and is_binary(body),
do: assert(Jason.decode!(val) == Jason.decode!(body))

defp assert_request_key(key, val, env),
do: assert(val == Map.get(env, key))

Expand Down
Loading