emqx_static_checks.erl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_static_checks).
  17. -compile(export_all).
  18. -compile(nowarn_export_all).
  19. -include_lib("common_test/include/ct.hrl").
  20. -include_lib("stdlib/include/assert.hrl").
  21. all() -> emqx_common_test_helpers:all(?MODULE).
  22. init_per_suite(Config) ->
  23. Config.
  24. end_per_suite(_Config) ->
  25. logger:notice(
  26. asciiart:visible(
  27. $=,
  28. "If this test suite failed, and you are unsure why, read this:~n"
  29. "https://github.com/emqx/emqx/blob/master/apps/emqx/src/bpapi/README.md",
  30. []
  31. )
  32. ).
  33. check_if_versions_consistent(OldData, NewData) ->
  34. %% OldData can contain a wider list of BPAPI versions
  35. %% than the release being checked.
  36. [] =:= NewData -- OldData.
  37. t_run_check(_) ->
  38. try
  39. {ok, OldData} = file:consult(emqx_bpapi_static_checks:versions_file()),
  40. ?assert(emqx_bpapi_static_checks:run()),
  41. {ok, NewData} = file:consult(emqx_bpapi_static_checks:versions_file()),
  42. check_if_versions_consistent(OldData, NewData) orelse
  43. begin
  44. logger:critical(
  45. asciiart:visible(
  46. $=,
  47. "BPAPI versions were changed, but not committed to the repo.\n\n"
  48. "Versions file is generated automatically, to update it, run\n"
  49. "'make && make static_checks' locally, and then add the\n"
  50. "changed 'bpapi.versions' files to the commit.\n",
  51. []
  52. )
  53. ),
  54. error(version_mismatch)
  55. end,
  56. BpapiDumps = filelib:wildcard(
  57. filename:join(
  58. emqx_bpapi_static_checks:dumps_dir(),
  59. "*" ++ emqx_bpapi_static_checks:dump_file_extension()
  60. )
  61. ),
  62. logger:info("Backplane API dump files: ~p", [BpapiDumps]),
  63. ?assert(emqx_bpapi_static_checks:check_compat(BpapiDumps))
  64. catch
  65. error:version_mismatch ->
  66. error(tc_failed);
  67. EC:Err:Stack ->
  68. logger:critical("Test suite failed: ~p:~p~nStack:~p", [EC, Err, Stack]),
  69. error(tc_failed)
  70. end.