diff --git a/.github/workflows/test_format_dialyze.yml b/.github/workflows/test_format_dialyze.yml index cd9779c..3dbdaeb 100644 --- a/.github/workflows/test_format_dialyze.yml +++ b/.github/workflows/test_format_dialyze.yml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/configuration/flagsmith_configuration.ex b/lib/configuration/flagsmith_configuration.ex index 415de6a..2b59f40 100644 --- a/lib/configuration/flagsmith_configuration.ex +++ b/lib/configuration/flagsmith_configuration.ex @@ -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) diff --git a/lib/engine/evaluator.ex b/lib/engine/evaluator.ex index bbbdd60..7f3c87d 100644 --- a/lib/engine/evaluator.ex +++ b/lib/engine/evaluator.ex @@ -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 diff --git a/lib/engine/mappers.ex b/lib/engine/mappers.ex index 4160bd2..139f871 100644 --- a/lib/engine/mappers.ex +++ b/lib/engine/mappers.ex @@ -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 diff --git a/lib/flagsmith_client_poller.ex b/lib/flagsmith_client_poller.ex index aa62d8a..adccf44 100644 --- a/lib/flagsmith_client_poller.ex +++ b/lib/flagsmith_client_poller.ex @@ -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 diff --git a/lib/flagsmith_engine.ex b/lib/flagsmith_engine.ex index ebb6076..9835e54 100644 --- a/lib/flagsmith_engine.ex +++ b/lib/flagsmith_engine.ex @@ -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)}" ) diff --git a/lib/schemas/traits/trait_value.ex b/lib/schemas/traits/trait_value.ex index d9afc3c..996f964 100644 --- a/lib/schemas/traits/trait_value.ex +++ b/lib/schemas/traits/trait_value.ex @@ -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 diff --git a/test/flagsmith_configuration_test.exs b/test/flagsmith_configuration_test.exs index 5ccd110..70280af 100644 --- a/test/flagsmith_configuration_test.exs +++ b/test/flagsmith_configuration_test.exs @@ -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 diff --git a/test/flagsmith_events_test.exs b/test/flagsmith_events_test.exs index ded052c..1117e51 100644 --- a/test/flagsmith_events_test.exs +++ b/test/flagsmith_events_test.exs @@ -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) diff --git a/test/support/helpers.ex b/test/support/helpers.ex index e56616c..702ae10 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -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))