forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-test-playwright.xml
299 lines (214 loc) · 9.15 KB
/
build-test-playwright.xml
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?xml version="1.0"?>
<project basedir="." name="portal-test-playwright" xmlns:antelope="antlib:ise.antelope.tasks" xmlns:if="ant:if" xmlns:unless="ant:unless">
<import file="build-test.xml" />
<condition else="portal" property="playwright.project.name" value="${env.PLAYWRIGHT_PROJECT_NAME}">
<isset property="env.PLAYWRIGHT_PROJECT_NAME" />
</condition>
<macrodef name="get-playwright-bash-script">
<attribute name="bash.script.name" />
<sequential>
<var name="playwright.bash.script" unset="true" />
<get-playwright-project-dir />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
File playwrightProjectDir = new File(project.getProperty("playwright.project.dir"));
File playwrightBaseDir = new File(project.getProperty("project.dir"), "modules/test/playwright");
public String getPlaywrightBashScript() {
File bashScriptFile = new File(playwrightProjectDir, "env/@{bash.script.name}");
if (bashScriptFile.exists()) {
return JenkinsResultsParserUtil.getCanonicalPath(bashScriptFile);
}
return JenkinsResultsParserUtil.getCanonicalPath(new File(playwrightBaseDir, "env/@{bash.script.name}"));
}
project.setProperty("playwright.bash.script", getPlaywrightBashScript());
]]>
</beanshell>
</sequential>
</macrodef>
<macrodef name="get-playwright-project-dir">
<sequential>
<var name="playwright.project.dir" unset="true" />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Pattern pattern = Pattern.compile("name\\: '([^']+)'");
String playwrightProjectName = project.getProperty("playwright.project.name");
File playwrightBaseDir = new File(project.getProperty("project.dir"), "modules/test/playwright");
public String getPlaywrightProjectDirPath() {
for (File configTSFile : JenkinsResultsParserUtil.findFiles(playwrightBaseDir, ".*config.ts")) {
Matcher matcher = pattern.matcher(JenkinsResultsParserUtil.read(configTSFile));
if (!matcher.find()) {
continue;
}
if (!Objects.equals(matcher.group(1), playwrightProjectName)) {
continue;
}
return JenkinsResultsParserUtil.getCanonicalPath(configTSFile.getParentFile());
}
return JenkinsResultsParserUtil.getCanonicalPath(playwrightBaseDir);
}
project.setProperty("playwright.project.dir", getPlaywrightProjectDirPath());
]]>
</beanshell>
</sequential>
</macrodef>
<macrodef name="run-playwright-bash-script">
<attribute name="bash.script.name" />
<sequential>
<get-playwright-bash-script bash.script.name="@{bash.script.name}" />
<get-playwright-project-dir />
<local name="tstamp.value" />
<tstamp>
<format pattern="yyyyMMddkkmmssSSS" property="tstamp.value" />
</tstamp>
<trycatch>
<try>
<echo file="${tstamp.value}.sh">
<![CDATA[
#!/bin/bash
export LIFERAY_HOME=${liferay.home}
export PLAYWRIGHT_BASE_DIR=${project.dir}/modules/test/playwright
export PLAYWRIGHT_PROJECT_DIR=${playwright.project.dir}
export PROJECT_DIR=${project.dir}
/bin/bash ${playwright.bash.script}
]]>
</echo>
<exec executable="/bin/bash">
<arg value="${tstamp.value}.sh" />
</exec>
</try>
<finally>
<delete failonerror="false" file="${tstamp.value}.sh" />
</finally>
</trycatch>
</sequential>
</macrodef>
<target name="deploy-client-extension">
<fail message="Please set the property ${client.extension.dir}." unless="client.extension.dir" />
<local name="client.extension.dir.path" />
<property name="client.extension.dir.path" value="${project.dir}/${client.extension.dir}" />
<if>
<not>
<available file="${client.extension.dir.path}" />
</not>
<then>
<fail message="${client.extension.dir.path} does not exist" />
</then>
</if>
<gradle-execute dir="${client.extension.dir.path}" task="clean">
<arg value="-Pliferay.workspace.home.dir=${liferay.home}" />
</gradle-execute>
<gradle-execute dir="${client.extension.dir.path}" task="deploy">
<arg value="-Pliferay.workspace.home.dir=${liferay.home}" />
</gradle-execute>
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
public String getClientExtensionName() {
File clientExtensionDir = new File(project.getProperty("client.extension.dir.path"));
String clientExtensionName = clientExtensionDir.getName();
return clientExtensionName.replaceAll("-", "") + "_7.4.13";
}
public void waitForClientExtension() {
String clientExtensionName = getClientExtensionName();
File liferayHomeDir = new File(project.getProperty("liferay.home"));
for (int i = 0; i < 60; i++) {
System.out.println("Waiting for " + clientExtensionName + " to be deployed");
for (File logFile : JenkinsResultsParserUtil.findFiles(liferayHomeDir, "liferay\\.[^\\.]+\\.log")) {
String logFileContent = JenkinsResultsParserUtil.read(logFile);
if (logFileContent.contains("STARTED " + clientExtensionName)) {
System.out.println(clientExtensionName + " was started");
return;
}
}
JenkinsResultsParserUtil.sleep(3000);
}
throw new Exception(clientExtensionName + " was not started");
}
waitForClientExtension();
]]>
</beanshell>
</target>
<target name="deploy-osgi-module">
<fail message="Please set the property ${osgi.module.dir}." unless="osgi.module.dir" />
<local name="osgi.module.dir.path" />
<property name="osgi.module.dir.path" value="${project.dir}/${osgi.module.dir}" />
<if>
<not>
<available file="${osgi.module.dir.path}" />
</not>
<then>
<fail message="${osgi.module.dir.path} does not exist" />
</then>
</if>
<gradle-execute dir="${osgi.module.dir.path}" task="clean">
<arg value="-Pliferay.workspace.home.dir=${liferay.home}" />
</gradle-execute>
<gradle-execute dir="${osgi.module.dir.path}" task="deploy">
<arg value="-Pliferay.workspace.home.dir=${liferay.home}" />
</gradle-execute>
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
public String getOSGiModuleName() {
File osgiModuleDir = new File(project.getProperty("osgi.module.dir.path"));
Properties bndProperties = JenkinsResultsParserUtil.getProperties(new File[] {new File(osgiModuleDir, "bnd.bnd")});
String bundleSymbolicName = JenkinsResultsParserUtil.getProperty(bndProperties, "Bundle-SymbolicName");
String bundleVersion = JenkinsResultsParserUtil.getProperty(bndProperties, "Bundle-Version");
return bundleSymbolicName + "_" + bundleVersion;
}
public void waitForOSGiModule() {
String osgiModuleName = getOSGiModuleName();
File liferayHomeDir = new File(project.getProperty("liferay.home"));
for (int i = 0; i < 60; i++) {
System.out.println("Waiting for " + osgiModuleName + " to be deployed");
for (File logFile : JenkinsResultsParserUtil.findFiles(liferayHomeDir, "liferay\\.[^\\.]+\\.log")) {
String logFileContent = JenkinsResultsParserUtil.read(logFile);
if (logFileContent.contains("STARTED " + osgiModuleName)) {
System.out.println(osgiModuleName + " was started");
return;
}
}
JenkinsResultsParserUtil.sleep(3000);
}
throw new Exception(osgiModuleName + " was not started");
}
waitForOSGiModule();
]]>
</beanshell>
</target>
<target name="set-up-playwright-environment">
<run-playwright-bash-script bash.script.name="set_up.sh" />
</target>
<target name="tear-down-playwright-environment">
<run-playwright-bash-script bash.script.name="tear_down.sh" />
</target>
<target name="update-portal-ext-properties">
<fail message="Please set the property ${updated.portal.ext.properties}." unless="updated.portal.ext.properties" />
<beanshell>
<![CDATA[
import com.liferay.jenkins.results.parser.JenkinsResultsParserUtil;
public File getPortalExtPropertiesFile() {
List portalExtPropertiesFiles = JenkinsResultsParserUtil.findFiles(new File(project.getProperty("liferay.home")), "portal-ext.properties");
if (portalExtPropertiesFiles.isEmpty()) {
throw new RuntimeException("Could not find the original portal-ext.properties file");
}
return portalExtPropertiesFiles.get(0);
}
public File getUpdatedPortalExtPropertiesFile() {
File updatedPortalExtPropertiesFile = new File(project.getProperty("updated.portal.ext.properties"));
if (!updatedPortalExtPropertiesFile.exists()) {
throw new RuntimeException("Could not find the updated portal-ext.properties file at " + updatedPortalExtPropertiesFile);
}
return updatedPortalExtPropertiesFile;
}
File portalExtPropertiesFile = getPortalExtPropertiesFile();
Properties portalExtProperties = JenkinsResultsParserUtil.getProperties(new File[] {portalExtPropertiesFile, getUpdatedPortalExtPropertiesFile()});
JenkinsResultsParserUtil.writePropertiesFile(portalExtPropertiesFile, portalExtProperties, true);
]]>
</beanshell>
</target>
</project>