plugin_relx.mk 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. # Relx plugin.
  2. #
  3. # Sleeps when interacting with relx script are necessary after start and upgrade
  4. # as both of those interactions are not synchronized.
  5. RELX_CASES = rel relup start-stop tar vsn
  6. RELX_TARGETS = $(addprefix relx-,$(RELX_CASES))
  7. .PHONY: relx $(RELX_TARGETS)
  8. ifeq ($(PLATFORM),msys2)
  9. RELX_REL_EXT = .cmd
  10. else
  11. RELX_REL_EXT =
  12. endif
  13. relx: $(RELX_TARGETS)
  14. relx-rel: build clean
  15. $i "Bootstrap a new release named $(APP)"
  16. $t mkdir $(APP)/
  17. $t cp ../erlang.mk $(APP)/
  18. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  19. $i "Build the release"
  20. $t $(MAKE) -C $(APP) $v
  21. $i "Check that relx was downloaded"
  22. $t test -f $(APP)/.erlang.mk/relx
  23. $i "Check that the release was built"
  24. $t test -d $(APP)/_rel
  25. $t test -d $(APP)/_rel/$(APP)_release
  26. $t test -d $(APP)/_rel/$(APP)_release/bin
  27. $t test -d $(APP)/_rel/$(APP)_release/lib
  28. $t test -d $(APP)/_rel/$(APP)_release/releases
  29. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  30. $i "Clean the application"
  31. $t $(MAKE) -C $(APP) clean $v
  32. $i "Check that the release still exists"
  33. $t test -d $(APP)/_rel
  34. $t test -d $(APP)/_rel/$(APP)_release
  35. $t test -d $(APP)/_rel/$(APP)_release/bin
  36. $t test -d $(APP)/_rel/$(APP)_release/lib
  37. $t test -d $(APP)/_rel/$(APP)_release/releases
  38. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  39. $i "Distclean the application"
  40. $t $(MAKE) -C $(APP) distclean $v
  41. $i "Check that the output directory was removed entirely"
  42. $t test ! -d $(APP)/_rel/
  43. relx-relup: build clean
  44. $i "Bootstrap a new release named $(APP)"
  45. $t mkdir $(APP)/
  46. $t cp ../erlang.mk $(APP)/
  47. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  48. $i "Set the initial application version"
  49. ifeq ($(LEGACY),1)
  50. $t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
  51. else
  52. $t echo "PROJECT_VERSION = 1" >> $(APP)/Makefile
  53. endif
  54. $i "Generate a test module"
  55. $t printf "%s\n"\
  56. "-module(test)." \
  57. "-export([test/0])." \
  58. "test() -> old." > $(APP)/src/test.erl
  59. $i "Build the initial release as a tarball"
  60. $t $(MAKE) -C $(APP) $v
  61. $i "Update the test module"
  62. $t sed -i.bak s/"test() -> old."/"test() -> new."/ $(APP)/src/test.erl
  63. $i "Bump the application version"
  64. ifeq ($(LEGACY),1)
  65. $t sed -i.bak s/"{vsn, \"1\"}"/"{vsn, \"2\"}"/ $(APP)/src/$(APP).app.src
  66. else
  67. $t sed -i.bak s/"PROJECT_VERSION = 1"/"PROJECT_VERSION = 2"/ $(APP)/Makefile
  68. endif
  69. $i "Generate a .appup for the application"
  70. $t printf "%s\n" \
  71. "{\"2\","\
  72. " [{\"1\", [{load_module, test}]}],"\
  73. " [{\"1\", [{load_module, test}]}]"\
  74. "}." > $(APP)/ebin/$(APP).appup
  75. $i "Bump the release version"
  76. $t sed -i.bak s/"1"/"2"/ $(APP)/relx.config
  77. $i "Build a new release with a relup as a tarball"
  78. $t $(MAKE) -C $(APP) relup $v
  79. $i "Test that both releases are available"
  80. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  81. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz
  82. $i "Unpack initial release"
  83. $t mkdir $(APP)/tmp
  84. $t tar -xzf $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz -C $(APP)/tmp
  85. $i "Start initial release and confirm it runs the old code"
  86. ifeq ($(PLATFORM),msys2)
  87. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) install $v
  88. endif
  89. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) start $v
  90. $t sleep 1
  91. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  92. $i "Check that it's 1 available version"
  93. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "2"
  94. $i "Copy the relup tarball to the release directory"
  95. $t mkdir $(APP)/tmp/releases/2
  96. $t cp $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  97. $t test -f $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  98. $i "Upgrade the release and confirm it runs the new code"
  99. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) upgrade "2"
  100. $t sleep 1
  101. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = new
  102. $i "Check that it's 2 available versions"
  103. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "3"
  104. $i "Downgrade the release and confirm it runs the old code"
  105. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) downgrade "1"
  106. $t sleep 1
  107. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  108. $i "Stop the release"
  109. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop $v
  110. ifeq ($(PLATFORM),msys2)
  111. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall $v
  112. endif
  113. relx-start-stop: build clean
  114. $i "Bootstrap a new release named $(APP)"
  115. $t mkdir $(APP)/
  116. $t cp ../erlang.mk $(APP)/
  117. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  118. $i "Build the release"
  119. $t $(MAKE) -C $(APP) $v
  120. $i "Start the release"
  121. ifeq ($(PLATFORM),msys2)
  122. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
  123. endif
  124. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) start $v
  125. $t sleep 1
  126. $i "Ping the release"
  127. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping $v
  128. $i "Stop the release"
  129. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop $v
  130. ifeq ($(PLATFORM),msys2)
  131. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
  132. endif
  133. $i "Check that further pings get no replies"
  134. $t ! $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping $v
  135. relx-tar: build clean
  136. $i "Bootstrap a new release named $(APP)"
  137. $t mkdir $(APP)/
  138. $t cp ../erlang.mk $(APP)/
  139. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  140. $i "Build the release without a tarball"
  141. $t $(MAKE) -C $(APP) RELX_TAR=0 $v
  142. $i "Check that tarball doesn't exist"
  143. $t test ! -e $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  144. $i "Build the release as a tarball"
  145. $t $(MAKE) -C $(APP) $v
  146. $i "Check that tarball exists"
  147. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  148. relx-vsn: build clean
  149. $i "Bootstrap a new release named $(APP)"
  150. $t mkdir $(APP)/
  151. $t cp ../erlang.mk $(APP)/
  152. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  153. $i "Replace the vsn"
  154. $t sed -i.bak s/"\"1\""/"{cmd, \"echo -n 2\"}"/ $(APP)/relx.config
  155. $i "Build the release"
  156. $t $(MAKE) -C $(APP) $v
  157. $i "Check that the correct release exists"
  158. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  159. $t test -d $(APP)/_rel/$(APP)_release/releases/2