Parcourir la source

ci(fix): actually fail check for missing reboot apps

Thales Macedo Garitezi il y a 2 ans
Parent
commit
26d4ee5780
3 fichiers modifiés avec 44 ajouts et 9 suppressions
  1. 1 1
      Makefile
  2. 20 1
      mix.exs
  3. 23 7
      scripts/check_missing_reboot_apps.exs

+ 1 - 1
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)
 

+ 20 - 1
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

+ 23 - 7
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
+
+{: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()
 
-profile = Keyword.fetch!(parsed, :profile)
+# 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