From 26d4ee5780a33c9138bcb86eddbc11cbef3c139b Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 11 Jul 2023 20:07:16 -0300 Subject: [PATCH] ci(fix): actually fail check for missing reboot apps --- Makefile | 2 +- mix.exs | 21 ++++++++++++++++++- scripts/check_missing_reboot_apps.exs | 30 ++++++++++++++++++++------- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index fe533b92d..bb2694d5d 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ static_checks: @$(REBAR) as check do xref, dialyzer @if [ "$${PROFILE}" = 'emqx-enterprise' ]; then $(REBAR) ct --suite apps/emqx/test/emqx_static_checks --readable $(CT_READABLE); fi ./scripts/check-i18n-style.sh - ./scripts/check_missing_reboot_apps.exs --profile $(PROFILE) + ./scripts/check_missing_reboot_apps.exs APPS=$(shell $(SCRIPTS)/find-apps.sh) diff --git a/mix.exs b/mix.exs index 9305b2d57..548e32d36 100644 --- a/mix.exs +++ b/mix.exs @@ -446,13 +446,32 @@ defmodule EMQXUmbrella.MixProject do def check_profile!() do valid_envs = [ - :dev, :emqx, :"emqx-pkg", :"emqx-enterprise", :"emqx-enterprise-pkg" ] + if Mix.env() == :dev do + env_profile = System.get_env("PROFILE") + + if env_profile do + # copy from PROFILE env var + System.get_env("PROFILE") + |> String.to_atom() + |> Mix.env() + else + IO.puts( + IO.ANSI.format([ + :yellow, + "Warning: env var PROFILE is unset; defaulting to emqx" + ]) + ) + + Mix.env(:emqx) + end + end + if Mix.env() not in valid_envs do formatted_envs = valid_envs diff --git a/scripts/check_missing_reboot_apps.exs b/scripts/check_missing_reboot_apps.exs index 9ea2c7925..d9933e099 100755 --- a/scripts/check_missing_reboot_apps.exs +++ b/scripts/check_missing_reboot_apps.exs @@ -1,19 +1,33 @@ #!/usr/bin/env elixir -{parsed, _argv, _errors = []} = - OptionParser.parse( - System.argv(), - strict: [profile: :string] - ) +alias EMQXUmbrella.MixProject -profile = Keyword.fetch!(parsed, :profile) +{:ok, _} = Application.ensure_all_started(:mix) +# note: run from the project root +File.cwd!() +|> Path.join("mix.exs") +|> Code.compile_file() + +inputs = MixProject.check_profile!() +profile = Mix.env() + +# need to use this information because we might have compiled all +# applications in the test profile, and thus filter what's in the +# release lib directory. +rel_apps = MixProject.applications(inputs.edition_type) + +apps = + rel_apps + |> Keyword.keys() + |> Enum.filter(&(to_string(&1) =~ "emqx")) + |> Enum.reject(&(&1 in [:emqx_mix])) :xref.start(:xref) :xref.set_default(:xref, warnings: false) rel_dir = '_build/#{profile}/lib/' :xref.add_release(:xref, rel_dir) -{:ok, calls} = :xref.q(:xref, '(App) (XC || "mria":"create_table"/".*")') +{:ok, calls} = :xref.q(:xref, '(App) (XC | [#{Enum.join(apps, ",")}] || mria:create_table/_)') emqx_calls = calls @@ -59,4 +73,6 @@ if MapSet.size(missing_reboot_apps) != 0 do " otherwise, when a node joins a cluster, it might lose tables.\n" ]) ) + + System.halt(1) end