aboutsummaryrefslogtreecommitdiffstats
path: root/test/plugin_relx.mk
blob: f2d7f076a64163079522e67e56cca5a4afa9c7fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Relx plugin.
#
# Sleeps when interacting with relx script are necessary after start and upgrade
# as both of those interactions are not synchronized.

RELX_CASES = rel relup start-stop tar
RELX_TARGETS = $(addprefix relx-,$(RELX_CASES))

.PHONY: relx $(RELX_TARGETS)

relx: $(RELX_TARGETS)

relx-rel: build clean

	$i "Bootstrap a new release named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v

	$i "Build the release"
	$t $(MAKE) -C $(APP) $v

	$i "Check that relx was downloaded"
	$t test -f $(APP)/.erlang.mk/relx

	$i "Check that the release was built"
	$t test -d $(APP)/_rel
	$t test -d $(APP)/_rel/$(APP)_release
	$t test -d $(APP)/_rel/$(APP)_release/bin
	$t test -d $(APP)/_rel/$(APP)_release/lib
	$t test -d $(APP)/_rel/$(APP)_release/releases
	$t test -d $(APP)/_rel/$(APP)_release/releases/1

	$i "Clean the application"
	$t $(MAKE) -C $(APP) clean $v

	$i "Check that the release still exists"
	$t test -d $(APP)/_rel
	$t test -d $(APP)/_rel/$(APP)_release
	$t test -d $(APP)/_rel/$(APP)_release/bin
	$t test -d $(APP)/_rel/$(APP)_release/lib
	$t test -d $(APP)/_rel/$(APP)_release/releases
	$t test -d $(APP)/_rel/$(APP)_release/releases/1

	$i "Distclean the application"
	$t $(MAKE) -C $(APP) distclean $v

	$i "Check that the output directory was removed entirely"
	$t test ! -d $(APP)/_rel/

relx-relup: build clean

	$i "Bootstrap a new release named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v

	$i "Set the initial application version"
ifeq ($(LEGACY),1)
	$t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
else
	$t echo "PROJECT_VERSION = 1" >> $(APP)/Makefile
endif

	$i "Generate a test module"
	$t printf "%s\n"\
		"-module(test)." \
		"-export([test/0])." \
		"test() -> old." > $(APP)/src/test.erl

	$i "Build the initial release as a tarball"
	$t $(MAKE) -C $(APP) $v

	$i "Update the test module"
	$t sed -i.bak s/"test() -> old."/"test() -> new."/ $(APP)/src/test.erl

	$i "Bump the application version"
ifeq ($(LEGACY),1)
	$t sed -i.bak s/"{vsn, \"1\"}"/"{vsn, \"2\"}"/ $(APP)/src/$(APP).app.src
else
	$t sed -i.bak s/"PROJECT_VERSION = 1"/"PROJECT_VERSION = 2"/ $(APP)/Makefile
endif

	$i "Generate a .appup for the application"
	$t printf "%s\n" \
		"{\"2\","\
		"  [{\"1\", [{load_module, test}]}],"\
		"  [{\"1\", [{load_module, test}]}]"\
		"}." > $(APP)/ebin/$(APP).appup

	$i "Bump the release version"
	$t sed -i.bak s/"1"/"2"/ $(APP)/relx.config

	$i "Build a new release with a relup as a tarball"
	$t $(MAKE) -C $(APP) relup $v

	$i "Test that both releases are available"
	$t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
	$t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz

	$i "Unpack initial release"
	$t mkdir $(APP)/tmp
	$t tar -xzf $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz -C $(APP)/tmp

	$i "Start initial release and confirm it runs the old code"
ifeq ($(PLATFORM),msys2)
	$t $(APP)/tmp/bin/$(APP)_release.cmd install $v
	$t $(APP)/tmp/bin/$(APP)_release.cmd start $v
	$t sleep 1
	$t test `$(APP)/tmp/bin/$(APP)_release.cmd rpcterms test test` = old
else
	$t $(APP)/tmp/bin/$(APP)_release start $v
	$t sleep 1
	$t test `$(APP)/tmp/bin/$(APP)_release rpcterms test test` = old
endif

	$i "Move the relup tarball to the release directory"
	$t mkdir $(APP)/tmp/releases/2
	$t mv $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz $(APP)/tmp/releases/2/$(APP)_release.tar.gz

	$i "Upgrade the release and confirm it runs the new code"
ifeq ($(PLATFORM),msys2)
	$t $(APP)/tmp/bin/$(APP)_release.cmd upgrade "2/$(APP)_release" $v
	$t sleep 1
	$t test `$(APP)/tmp/bin/$(APP)_release.cmd rpcterms test test` = new

	$i "Stop the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd stop $v
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
else
	$i "Upgrade running release"
	$t $(APP)/tmp/bin/$(APP)_release upgrade "2/$(APP)_release" $v
	$t sleep 1
	$t test `$(APP)/tmp/bin/$(APP)_release rpcterms test test` = new

	$i "Stop the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
endif

relx-start-stop: build clean

	$i "Bootstrap a new release named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v

	$i "Build the release"
	$t $(MAKE) -C $(APP) $v

ifeq ($(PLATFORM),msys2)
	$i "Install and start the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd start $v
	$t sleep 1

	$i "Ping the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd ping $v

	$i "Stop and uninstall the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd stop $v
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v

	$i "Check that further pings get no replies"
	$t ! $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd ping $v
else
	$i "Start the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
	$t sleep 1

	$i "Ping the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release ping $v

	$i "Stop the release"
	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v

	$i "Check that further pings get no replies"
	$t ! $(APP)/_rel/$(APP)_release/bin/$(APP)_release ping $v
endif

relx-tar: build clean

	$i "Bootstrap a new release named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v

	$i "Build the release without a tarball"
	$t $(MAKE) -C $(APP) RELX_TAR=0 $v

	$i "Check that tarball doesn't exist"
	$t test ! -e $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz

	$i "Build the release as a tarball"
	$t $(MAKE) -C $(APP) $v

	$i "Check that tarball exists"
	$t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz