8c7a67fd675ad288c8f731781a38ca01dcafb68c
[Packages/TYPO3.CMS.git] / Build / bamboo / src / main / java / core / AbstractCoreSpec.java
1 package core;
2
3 /*
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16 import java.util.ArrayList;
17
18 import com.atlassian.bamboo.specs.api.builders.BambooKey;
19 import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;
20 import com.atlassian.bamboo.specs.api.builders.permission.Permissions;
21 import com.atlassian.bamboo.specs.api.builders.permission.PlanPermissions;
22 import com.atlassian.bamboo.specs.api.builders.plan.Job;
23 import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;
24 import com.atlassian.bamboo.specs.api.builders.plan.artifact.Artifact;
25 import com.atlassian.bamboo.specs.api.builders.plan.configuration.AllOtherPluginsConfiguration;
26 import com.atlassian.bamboo.specs.api.builders.plan.configuration.PluginConfiguration;
27 import com.atlassian.bamboo.specs.api.builders.requirement.Requirement;
28 import com.atlassian.bamboo.specs.api.builders.task.Task;
29 import com.atlassian.bamboo.specs.builders.task.CheckoutItem;
30 import com.atlassian.bamboo.specs.builders.task.CommandTask;
31 import com.atlassian.bamboo.specs.builders.task.NpmTask;
32 import com.atlassian.bamboo.specs.builders.task.ScriptTask;
33 import com.atlassian.bamboo.specs.builders.task.TestParserTask;
34 import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;
35 import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
36 import com.atlassian.bamboo.specs.model.task.TestParserTaskProperties;
37 import com.atlassian.bamboo.specs.util.MapBuilder;
38
39 /**
40 * Abstract class with common methods of pre-merge and nightly plan
41 */
42 abstract public class AbstractCoreSpec {
43
44 protected static String bambooServerName = "https://bamboo.typo3.com:443";
45 protected static String projectName = "TYPO3 Core";
46 protected static String projectKey = "CORE";
47
48 protected String composerRootVersionEnvironment = "COMPOSER_ROOT_VERSION=8.7.0";
49
50 protected String testingFrameworkBuildPath = "vendor/typo3/testing-framework/Resources/Core/Build/";
51
52 protected String credentialsMysql =
53 "typo3DatabaseName=\"func\"" +
54 " typo3DatabaseUsername=\"funcu\"" +
55 " typo3DatabasePassword=\"funcp\"" +
56 " typo3DatabaseHost=\"localhost\"" +
57 " typo3InstallToolPassword=\"klaus\"";
58
59 protected String credentialsMssql =
60 "typo3DatabaseDriver=\"sqlsrv\"" +
61 " typo3DatabaseName=\"func\"" +
62 " typo3DatabasePassword='Test1234!'" +
63 " typo3DatabaseUsername=\"SA\"" +
64 " typo3DatabaseHost=\"localhost\"" +
65 " typo3DatabasePort=\"1433\"" +
66 " typo3DatabaseCharset=\"utf-8\"" +
67 " typo3InstallToolPassword=\"klaus\"";
68
69 protected String credentialsPgsql =
70 "typo3DatabaseDriver=\"pdo_pgsql\"" +
71 " typo3DatabaseName=\"func\"" +
72 " typo3DatabaseUsername=\"bamboo\"" +
73 " typo3DatabaseHost=\"localhost\"" +
74 " typo3InstallToolPassword=\"klaus\"";
75
76 /**
77 * Default permissions on core plans
78 *
79 * @param projectName
80 * @param planName
81 * @return
82 */
83 protected PlanPermissions getDefaultPlanPermissions(String projectKey, String planKey) {
84 return new PlanPermissions(new PlanIdentifier(projectKey, planKey))
85 .permissions(new Permissions()
86 .groupPermissions("TYPO3 GmbH", PermissionType.ADMIN, PermissionType.VIEW, PermissionType.EDIT, PermissionType.BUILD, PermissionType.CLONE)
87 .groupPermissions("TYPO3 Core Team", PermissionType.VIEW, PermissionType.BUILD)
88 .loggedInUserPermissions(PermissionType.VIEW)
89 .anonymousUserPermissionView()
90 );
91 }
92
93 /**
94 * Default plan plugin configuration
95 *
96 * @return
97 */
98 protected PluginConfiguration getDefaultPlanPluginConfiguration() {
99 return new AllOtherPluginsConfiguration()
100 .configuration(new MapBuilder()
101 .put("custom", new MapBuilder()
102 .put("artifactHandlers.useCustomArtifactHandlers", "false")
103 .put("buildExpiryConfig", new MapBuilder()
104 .put("duration", "30")
105 .put("period", "days")
106 .put("labelsToKeep", "")
107 .put("expiryTypeResult", "true")
108 .put("buildsToKeep", "")
109 .put("enabled", "true")
110 .build()
111 )
112 .build()
113 )
114 .build()
115 );
116 }
117
118 /**
119 * Default job plugin configuration
120 *
121 * @return
122 */
123 protected PluginConfiguration getDefaultJobPluginConfiguration() {
124 return new AllOtherPluginsConfiguration()
125 .configuration(new MapBuilder()
126 .put("repositoryDefiningWorkingDirectory", -1)
127 .put("custom", new MapBuilder()
128 .put("auto", new MapBuilder()
129 .put("regex", "")
130 .put("label", "")
131 .build()
132 )
133 .put("buildHangingConfig.enabled", "false")
134 .put("ncover.path", "")
135 .put("clover", new MapBuilder()
136 .put("path", "")
137 .put("license", "")
138 .put("useLocalLicenseKey", "true")
139 .build()
140 )
141 .build()
142 )
143 .build()
144 );
145 }
146
147 /**
148 * Job composer validate
149 */
150 protected Job getJobComposerValidate() {
151 return new Job("Validate composer.json", new BambooKey("VC"))
152 .description("Validate composer.json before actual tests are executed")
153 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
154 .tasks(
155 this.getTaskGitCloneRepository(),
156 this.getTaskGitCherryPick(),
157 new CommandTask()
158 .description("composer validate")
159 .executable("composer").argument("validate")
160 .environmentVariables(this.composerRootVersionEnvironment)
161 )
162 .cleanWorkingDirectory(true);
163 }
164
165 /**
166 * Job acceptance test installs system on mysql
167 *
168 * @param Requirement requirement
169 * @param String requirementIdentfier
170 */
171 protected Job getJobAcceptanceTestInstallMysql(Requirement requirement, String requirementIdentifier) {
172 return new Job("Accept inst my " + requirementIdentifier, new BambooKey("ACINSTMY" + requirementIdentifier))
173 .description("Install TYPO3 on mysql and create empty frontend page " + requirementIdentifier)
174 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
175 .tasks(
176 this.getTaskGitCloneRepository(),
177 this.getTaskGitCherryPick(),
178 this.getTaskComposerInstall(),
179 this.getTaskPrepareAcceptanceTest(),
180 new CommandTask()
181 .description("Execute codeception AcceptanceInstallMysql suite")
182 .executable("codecept")
183 .argument("run AcceptanceInstallMysql -d -c " + this.testingFrameworkBuildPath + "AcceptanceTestsInstallMysql.yml --xml reports.xml --html reports.html")
184 .environmentVariables(this.credentialsMysql)
185 )
186 .finalTasks(
187 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
188 .resultDirectories("typo3temp/var/tests/AcceptanceReportsInstallMysql/reports.xml"),
189 this.getTaskDeleteMysqlDatabases(),
190 this.getTaskTearDownAcceptanceTestSetup()
191 )
192 .requirements(
193 requirement
194 )
195 .artifacts(new Artifact()
196 .name("Test Report")
197 .copyPattern("typo3temp/var/tests/AcceptanceReportsInstallMysql/")
198 .shared(false)
199 )
200 .cleanWorkingDirectory(true);
201 }
202
203 /**
204 * Job acceptance test installs system and introduction package on pgsql
205 *
206 * @param Requirement requirement
207 * @param String requirementIdentfier
208 */
209 protected Job getJobAcceptanceTestInstallPgsql(Requirement requirement, String requirementIdentifier) {
210 return new Job("Accept inst pg " + requirementIdentifier, new BambooKey("ACINSTPG" + requirementIdentifier))
211 .description("Install TYPO3 on pgsql and load introduction package " + requirementIdentifier)
212 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
213 .tasks(
214 this.getTaskGitCloneRepository(),
215 this.getTaskGitCherryPick(),
216 this.getTaskComposerInstall(),
217 this.getTaskPrepareAcceptanceTest(),
218 new CommandTask()
219 .description("Execute codeception AcceptanceInstallPgsql suite")
220 .executable("codecept")
221 .argument("run AcceptanceInstallPgsql -d -c " + this.testingFrameworkBuildPath + "AcceptanceTestsInstallPgsql.yml --xml reports.xml --html reports.html")
222 .environmentVariables(this.credentialsPgsql)
223 )
224 .finalTasks(
225 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
226 .resultDirectories("typo3temp/var/tests/AcceptanceReportsInstallPgsql/reports.xml"),
227 this.getTaskDeletePgsqlDatabases(),
228 this.getTaskTearDownAcceptanceTestSetup()
229 )
230 .requirements(
231 requirement
232 )
233 .artifacts(new Artifact()
234 .name("Test Report")
235 .copyPattern("typo3temp/var/tests/AcceptanceReportsInstallPgsql/")
236 .shared(false)
237 )
238 .cleanWorkingDirectory(true);
239 }
240
241 /**
242 * Jobs for mysql based acceptance tests
243 *
244 * @param int numberOfChunks
245 * @param Requirement requirement
246 * @param String requirementIdentifier
247 */
248 protected ArrayList<Job> getJobsAcceptanceTestsMysql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
249 ArrayList<Job> jobs = new ArrayList<Job>();
250
251 for (int i=1; i<=numberOfChunks; i++) {
252 jobs.add(new Job("Accept my " + requirementIdentifier + " 0" + i, new BambooKey("ACMY" + requirementIdentifier + "0" + i))
253 .description("Run acceptance tests" + requirementIdentifier)
254 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
255 .tasks(
256 this.getTaskGitCloneRepository(),
257 this.getTaskGitCherryPick(),
258 this.getTaskComposerInstall(),
259 this.getTaskPrepareAcceptanceTest(),
260 new ScriptTask()
261 .description("Split acceptance tests")
262 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
263 .inlineBody(
264 this.getScriptTaskBashInlineBody() +
265 "./" + this.testingFrameworkBuildPath + "Scripts/splitAcceptanceTests.sh " + numberOfChunks + "\n"
266 ),
267 new CommandTask()
268 .description("Execute codeception acceptance suite group " + i)
269 .executable("codecept")
270 .argument("run Acceptance -d -g AcceptanceTests-Job-" + i + " -c " + this.testingFrameworkBuildPath + "AcceptanceTests.yml --xml reports.xml --html reports.html")
271 .environmentVariables(this.credentialsMysql)
272 )
273 .finalTasks(
274 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
275 .resultDirectories("typo3temp/var/tests/AcceptanceReports/reports.xml"),
276 this.getTaskDeleteMysqlDatabases(),
277 this.getTaskTearDownAcceptanceTestSetup()
278 )
279 .requirements(
280 requirement
281 )
282 .artifacts(new Artifact()
283 .name("Test Report")
284 .copyPattern("typo3temp/var/tests/AcceptanceReports/")
285 .shared(false)
286 )
287 .cleanWorkingDirectory(true)
288 );
289 }
290
291 return jobs;
292 }
293
294 /**
295 * Jobs for mysql based functional tests
296 *
297 * @param int numberOfChunks
298 * @param Requirement requirement
299 * @param String requirementIdentifier
300 */
301 protected ArrayList<Job> getJobsFunctionalTestsMysql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
302 ArrayList<Job> jobs = new ArrayList<Job>();
303
304 for (int i=0; i<numberOfChunks; i++) {
305 jobs.add(new Job("Func mysql " + requirementIdentifier + " 0" + i, new BambooKey("FMY" + requirementIdentifier + "0" + i))
306 .description("Run functional tests on mysql DB " + requirementIdentifier)
307 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
308 .tasks(
309 this.getTaskGitCloneRepository(),
310 this.getTaskGitCherryPick(),
311 this.getTaskComposerInstall(),
312 this.getTaskSplitFunctionalJobs(numberOfChunks),
313 new ScriptTask()
314 .description("Run phpunit with functional chunk 0" + i)
315 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
316 .inlineBody(
317 this.getScriptTaskBashInlineBody() +
318 "./bin/phpunit --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "FunctionalTests-Job-" + i + ".xml"
319 )
320 .environmentVariables(this.credentialsMysql)
321 )
322 .finalTasks(
323 this.getTaskDeleteMysqlDatabases(),
324 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
325 .resultDirectories("test-reports/phpunit.xml")
326 )
327 .requirements(
328 requirement
329 )
330 .cleanWorkingDirectory(true)
331 );
332 }
333
334 return jobs;
335 }
336
337 /**
338 * Jobs for mssql based functional tests
339 *
340 * @param int numberOfChunks
341 * @param Requirement requirement
342 * @param String requirementIdentifier
343 */
344 protected ArrayList<Job> getJobsFunctionalTestsMssql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
345 ArrayList<Job> jobs = new ArrayList<Job>();
346
347 for (int i=0; i<numberOfChunks; i++) {
348 jobs.add(new Job("Func mssql " + requirementIdentifier + " 0" + i, new BambooKey("FMS" + requirementIdentifier + "0" + i))
349 .description("Run functional tests on mysql DB " + requirementIdentifier)
350 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
351 .tasks(
352 this.getTaskGitCloneRepository(),
353 this.getTaskGitCherryPick(),
354 this.getTaskComposerInstall(),
355 this.getTaskSplitFunctionalJobs(numberOfChunks),
356 new ScriptTask()
357 .description("Run phpunit with functional chunk 0" + i)
358 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
359 .inlineBody(
360 this.getScriptTaskBashInlineBody() +
361 "./bin/phpunit --exclude-group not-mssql --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "FunctionalTests-Job-" + i + ".xml"
362 )
363 .environmentVariables(this.credentialsMssql)
364 )
365 .finalTasks(
366 this.getTaskDeleteMssqlDatabases(),
367 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
368 .resultDirectories("test-reports/phpunit.xml")
369 )
370 .requirements(
371 requirement
372 )
373 .cleanWorkingDirectory(true)
374 .enabled(false)
375 );
376 }
377
378 return jobs;
379 }
380
381 /**
382 * Jobs for pgsql based functional tests
383 *
384 * @param int numberOfChunks
385 * @param Requirement requirement
386 * @param String requirementIdentifier
387 */
388 protected ArrayList<Job> getJobsFunctionalTestsPgsql(int numberOfChunks, Requirement requirement, String requirementIdentifier) {
389 ArrayList<Job> jobs = new ArrayList<Job>();
390
391 for (int i=0; i<numberOfChunks; i++) {
392 jobs.add(new Job("Func pgsql " + requirementIdentifier + " 0" + i, new BambooKey("FPG" + requirementIdentifier + "0" + i))
393 .description("Run functional tests on pgsql DB " + requirementIdentifier)
394 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
395 .tasks(
396 this.getTaskGitCloneRepository(),
397 this.getTaskGitCherryPick(),
398 this.getTaskComposerInstall(),
399 this.getTaskSplitFunctionalJobs(numberOfChunks),
400 new ScriptTask()
401 .description("Run phpunit with functional chunk 0" + i)
402 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
403 .inlineBody(
404 this.getScriptTaskBashInlineBody() +
405 "./bin/phpunit --exclude-group not-postgres --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "FunctionalTests-Job-" + i + ".xml"
406 )
407 .environmentVariables(this.credentialsPgsql)
408 )
409 .finalTasks(
410 this.getTaskDeletePgsqlDatabases(),
411 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
412 .resultDirectories("test-reports/phpunit.xml")
413 )
414 .requirements(
415 requirement
416 )
417 .cleanWorkingDirectory(true)
418 );
419 }
420
421 return jobs;
422 }
423
424 /**
425 * Job with various smaller script tests
426 */
427 protected Job getJobIntegrationVarious() {
428 // Exception code checker, xlf, permissions, rst file check
429 return new Job("Integration various", new BambooKey("CDECC"))
430 .description("Checks duplicate exceptions, git submodules, xlf files, permissions, rst")
431 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
432 .tasks(
433 this.getTaskGitCloneRepository(),
434 this.getTaskGitCherryPick(),
435 new ScriptTask()
436 .description("Run duplicate exception code check script")
437 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
438 .inlineBody(
439 this.getScriptTaskBashInlineBody() +
440 "./Build/Scripts/duplicateExceptionCodeCheck.sh\n"
441 ),
442 new ScriptTask()
443 .description("Run git submodule status and verify there are none")
444 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
445 .inlineBody(
446 this.getScriptTaskBashInlineBody() +
447 "if [[ `git submodule status 2>&1 | wc -l` -ne 0 ]]; then\n" +
448 " echo \\\"Found a submodule definition in repository\\\";\n" +
449 " exit 99;\n" +
450 "fi\n"
451 ),
452 new ScriptTask()
453 .description("Run permission check script")
454 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
455 .inlineBody(
456 this.getScriptTaskBashInlineBody() +
457 "./Build/Scripts/checkFilePermissions.sh\n"
458 ),
459 new ScriptTask()
460 .description("Run xlf check")
461 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
462 .inlineBody(
463 this.getScriptTaskBashInlineBody() +
464 "./Build/Scripts/xlfcheck.sh"
465 ),
466 new ScriptTask()
467 .description("Run rst check")
468 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
469 .inlineBody(
470 this.getScriptTaskBashInlineBody() +
471 "./Build/Scripts/validateRstFiles.sh"
472 ),
473 new ScriptTask()
474 .description("Run path length check")
475 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
476 .inlineBody(
477 this.getScriptTaskBashInlineBody() +
478 "./Build/Scripts/maxFilePathLength.sh"
479 )
480 )
481 .requirements(
482 new Requirement("system.phpVersion")
483 .matchValue("7\\.0|7\\.1")
484 .matchType(Requirement.MatchType.MATCHES)
485 )
486 .cleanWorkingDirectory(true);
487 }
488
489 /**
490 * Job for javascript unit tests
491 */
492 protected Job getJobUnitJavaScript() {
493 return new Job("Unit JavaScript", new BambooKey("JSUT"))
494 .description("Run JavaScript unit tests")
495 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
496 .tasks(
497 this.getTaskGitCloneRepository(),
498 this.getTaskGitCherryPick(),
499 this.getTaskComposerInstall(),
500 new NpmTask()
501 .description("npm install in Build/ dir")
502 .nodeExecutable("Node.js")
503 .workingSubdirectory("Build/")
504 .command("install"),
505 new ScriptTask()
506 .description("Run tests")
507 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
508 .inlineBody(
509 this.getScriptTaskBashInlineBody() +
510 "./Build/node_modules/karma/bin/karma start " + this.testingFrameworkBuildPath + "Configuration/JSUnit/karma.conf.js --single-run"
511 )
512 )
513 .finalTasks(
514 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
515 .resultDirectories("typo3temp/var/tests/*")
516 )
517 .requirements(
518 new Requirement("system.phpVersion")
519 .matchValue("7\\.0|7\\.1")
520 .matchType(Requirement.MatchType.MATCHES)
521 )
522 .artifacts(
523 new Artifact()
524 .name("Clover Report (System)")
525 .copyPattern("**/*.*")
526 .location("Build/target/site/clover")
527 .shared(false)
528 )
529 .cleanWorkingDirectory(true);
530 }
531
532 /**
533 * Job for PHP lint
534 *
535 * @param Requirement requirement
536 * @param String requirementIdentfier
537 */
538 protected Job getJobLintPhp(Requirement requirement, String requirementIdentifier) {
539 return new Job("Lint " + requirementIdentifier, new BambooKey("L" + requirementIdentifier))
540 .description("Run php -l on source files for linting " + requirementIdentifier)
541 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
542 .tasks(
543 this.getTaskGitCloneRepository(),
544 this.getTaskGitCherryPick(),
545 new ScriptTask()
546 .description("Run php lint")
547 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
548 .inlineBody(
549 this.getScriptTaskBashInlineBody() +
550 "find . -name \\*.php -print0 | xargs -0 -n1 -P2 php -l >/dev/null\n"
551 )
552 )
553 .requirements(
554 requirement
555 )
556 .cleanWorkingDirectory(true);
557 }
558
559 /**
560 * Job for lint npm scss and typescript
561 */
562 protected Job getJobLintScssTs() {
563 return new Job("Lint scss ts", new BambooKey("LSTS"))
564 .description("Run npm lint in Build/ dir")
565 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
566 .tasks(
567 this.getTaskGitCloneRepository(),
568 this.getTaskGitCherryPick(),
569 new NpmTask()
570 .description("npm install in Build/ dir")
571 .nodeExecutable("Node.js")
572 .workingSubdirectory("Build/")
573 .command("install"),
574 new NpmTask()
575 .description("Run npm lint")
576 .nodeExecutable("Node.js")
577 .workingSubdirectory("Build/")
578 .command("run lint")
579 )
580 .requirements(
581 new Requirement("system.imageVersion")
582 )
583 .cleanWorkingDirectory(true);
584 }
585
586 /**
587 * Job for unit testing PHP
588 *
589 * @param Requirement requirement
590 * @param String requirementIdentfier
591 */
592 protected Job getJobUnitPhp(Requirement requirement, String requirementIdentifier) {
593 return new Job("Unit " + requirementIdentifier, new BambooKey("UT" + requirementIdentifier))
594 .description("Run unit tests " + requirementIdentifier)
595 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
596 .tasks(
597 this.getTaskGitCloneRepository(),
598 this.getTaskGitCherryPick(),
599 this.getTaskComposerInstall(),
600 new ScriptTask()
601 .description("Run phpunit")
602 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
603 .inlineBody(
604 this.getScriptTaskBashInlineBody() +
605 this.getScriptTaskBashPhpNoXdebug() +
606 "php_no_xdebug bin/phpunit --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "UnitTests.xml"
607 )
608 )
609 .finalTasks(
610 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
611 .resultDirectories("test-reports/phpunit.xml")
612 )
613 .requirements(
614 requirement
615 )
616 .cleanWorkingDirectory(true);
617 }
618
619 /**
620 * Jobs for unit testing PHP in random test order
621 *
622 * @param int numberOfRuns
623 * @param Requirement requirement
624 * @param String requirementIdentfier
625 */
626 protected ArrayList<Job> getJobUnitPhpRandom(int numberOfRuns, Requirement requirement, String requirementIdentifier) {
627 ArrayList<Job> jobs = new ArrayList<Job>();
628
629 for (int i=0; i<numberOfRuns; i++) {
630 jobs.add(new Job("Unit " + requirementIdentifier + " random 0" + i, new BambooKey("UTR" + requirementIdentifier + "0" + i))
631 .description("Run unit tests on " + requirementIdentifier + " in random order 0" + i)
632 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
633 .tasks(
634 this.getTaskGitCloneRepository(),
635 this.getTaskGitCherryPick(),
636 this.getTaskComposerInstall(),
637 new ScriptTask()
638 .description("Run phpunit-randomizer")
639 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
640 .inlineBody(
641 this.getScriptTaskBashInlineBody() +
642 this.getScriptTaskBashPhpNoXdebug() +
643 "php_no_xdebug bin/phpunit-randomizer --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "UnitTests.xml --order rand"
644 )
645 )
646 .finalTasks(
647 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
648 .resultDirectories("test-reports/phpunit.xml")
649 )
650 .requirements(
651 requirement
652 )
653 .cleanWorkingDirectory(true)
654 );
655 }
656
657 return jobs;
658 }
659
660 /**
661 * Task definition for basic core clone of linked default repository
662 */
663 protected Task getTaskGitCloneRepository() {
664 return new VcsCheckoutTask()
665 .description("Checkout git core")
666 .checkoutItems(new CheckoutItem().defaultRepository())
667 .cleanCheckout(true);
668 }
669
670 /**
671 * Task definition to cherry pick a patch set from gerrit on top of cloned core
672 */
673 protected Task getTaskGitCherryPick() {
674 return new ScriptTask()
675 .description("Gerrit cherry pick")
676 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
677 .inlineBody(
678 this.getScriptTaskBashInlineBody() +
679 "CHANGEURL=${bamboo.changeUrl}\n" +
680 "CHANGEURLID=${CHANGEURL#https://review.typo3.org/}\n" +
681 "PATCHSET=${bamboo.patchset}\n" +
682 "\n" +
683 "if [[ $CHANGEURL ]]; then\n" +
684 " gerrit-cherry-pick https://review.typo3.org/Packages/TYPO3.CMS $CHANGEURLID/$PATCHSET || exit 1\n" +
685 "fi\n"
686 );
687 }
688
689 /**
690 * Task definition to execute composer install
691 */
692 protected Task getTaskComposerInstall() {
693 return new CommandTask()
694 .description("composer install")
695 .executable("composer")
696 .argument("install -n")
697 .environmentVariables(this.composerRootVersionEnvironment);
698 }
699
700 /**
701 * Task to prepare an acceptance test starting selenium and others
702 */
703 protected Task getTaskPrepareAcceptanceTest() {
704 return new ScriptTask()
705 .description("Start php web server, chromedriver, prepare environment")
706 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
707 .inlineBody(
708 this.getScriptTaskBashInlineBody() +
709 "php -S localhost:8000 >/dev/null 2>&1 &\n" +
710 "echo $! > phpserver.pid\n" +
711 "\n" +
712 "./bin/chromedriver --url-base=/wd/hub >/dev/null 2>&1 &\n" +
713 "echo $! > chromedriver.pid\n" +
714 "\n" +
715 "mkdir -p typo3temp/var/tests/\n"
716 );
717 }
718
719 /**
720 * Task to delete any created mysql test databases, used as final task
721 */
722 protected Task getTaskDeleteMysqlDatabases() {
723 return new ScriptTask()
724 .description("Delete mysql test dbs")
725 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
726 .inlineBody(
727 this.getScriptTaskBashInlineBody() +
728 "DB_STARTS_WITH=\"func_\"\n" +
729 "MUSER=\"funcu\"\n" +
730 "MPWD=\"funcp\"\n" +
731 "MYSQL=\"mysql\"\n" +
732 "DBS=\"$($MYSQL -u $MUSER -p\"$MPWD\" -Bse 'show databases')\"\n" +
733 "\n" +
734 "for db in $DBS; do\n" +
735 " if [[ \"$db\" == $DB_STARTS_WITH* ]]; then\n" +
736 " echo \"Deleting $db\"\n" +
737 " $MYSQL -u $MUSER -p\"$MPWD\" -Bse \"drop database $db\"\n" +
738 " fi\n" +
739 "done\n"
740 );
741 }
742
743 /**
744 * Task to delete any created mssql test databases, used as final task
745 */
746 protected Task getTaskDeleteMssqlDatabases() {
747 return new ScriptTask()
748 .description("Delete mssql test dbs")
749 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
750 .inlineBody(
751 this.getScriptTaskBashInlineBody() +
752 "DBS=`/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Test1234!' -Q 'select name from sys.databases' | grep '^func_'`\n" +
753 "\n" +
754 "for db in $DBS; do\n" +
755 " echo \"Deleteing $db\"\n" +
756 " /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Test1234!' -Q \"drop database $db\"\n" +
757 "done\n"
758 );
759 }
760
761 /**
762 * Task to delete any created pgsql test databases, used as final task
763 */
764 protected Task getTaskDeletePgsqlDatabases() {
765 return new ScriptTask()
766 .description("Delete pgsql test dbs")
767 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
768 .inlineBody(
769 this.getScriptTaskBashInlineBody() +
770 "DB_STARTS_WITH=\"func_\"\n" +
771 "PGUSER=\"bamboo\"\n" +
772 "DBS=\"$(/usr/bin/psql -qtA -c 'SELECT datname FROM pg_database WHERE datistemplate = false;' postgres)\"\n" +
773 "\n" +
774 "for db in $DBS; do\n" +
775 " if [[ \"$db\" == $DB_STARTS_WITH* ]]; then\n" +
776 " echo \"Deleting $db\"\n" +
777 " /usr/bin/psql -qtA -c \"DROP DATABASE $db\" postgres\n" +
778 " fi\n" +
779 "done\n"
780 );
781 }
782
783 /**
784 * Task to stop selenium and friends, opposite of getTaskPrepareAcceptanceTest, used as final task
785 */
786 protected Task getTaskTearDownAcceptanceTestSetup() {
787 return new ScriptTask()
788 .description("Stop acceptance test services like chromedriver and friends")
789 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
790 .inlineBody(
791 this.getScriptTaskBashInlineBody() +
792 "kill `cat phpserver.pid`\n" +
793 "kill `cat chromedriver.pid`\n"
794 );
795 }
796
797 /**
798 * Task to split functional jobs into chunks
799 */
800 protected Task getTaskSplitFunctionalJobs(int numberOfJobs) {
801 return new ScriptTask()
802 .description("Create list of test files to execute per job")
803 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
804 .inlineBody(
805 this.getScriptTaskBashInlineBody() +
806 "./" + this.testingFrameworkBuildPath + "Scripts/splitFunctionalTests.sh " + numberOfJobs
807 );
808 }
809
810 /**
811 * Requirement for php 7.0
812 */
813 protected Requirement getRequirementPhpVersion70() {
814 return new Requirement("system.phpVersion")
815 .matchValue("7.0")
816 .matchType(Requirement.MatchType.EQUALS);
817 }
818
819 /**
820 * Requirement for php 7.1
821 */
822 protected Requirement getRequirementPhpVersion71() {
823 return new Requirement("system.phpVersion")
824 .matchValue("7.1")
825 .matchType(Requirement.MatchType.EQUALS);
826 }
827
828 /**
829 * Requirement for php 7.0 or 7.1
830 */
831 protected Requirement getRequirementPhpVersion70Or71() {
832 return new Requirement("system.phpVersion")
833 .matchValue("7\\.0|7\\.1")
834 .matchType(Requirement.MatchType.MATCHES);
835 }
836
837 /**
838 * A bash header for script tasks forking a bash if needed
839 */
840 protected String getScriptTaskBashInlineBody() {
841 return
842 "#!/bin/bash\n" +
843 "\n" +
844 "if [ \"$(ps -p \"$$\" -o comm=)\" != \"bash\" ]; then\n" +
845 " bash \"$0\" \"$@\"\n" +
846 " exit \"$?\"\n" +
847 "fi\n" +
848 "\n";
849 }
850
851 /**
852 * A bash function providing a php bin without xdebug
853 */
854 protected String getScriptTaskBashPhpNoXdebug() {
855 return
856 "php_no_xdebug () {\n" +
857 " temporaryPath=\"$(mktemp -t php.XXXX).ini\"\n" +
858 " php -i | grep \"\\.ini\" | grep -o -e '\\(/[A-Za-z0-9._-]\\+\\)\\+\\.ini' | grep -v xdebug | xargs awk 'FNR==1{print \"\"}1' > \"${temporaryPath}\"\n" +
859 " php -n -c \"${temporaryPath}\" \"$@\"\n" +
860 " RETURN=$?\n" +
861 " rm -f \"${temporaryPath}\"\n" +
862 " exit $RETURN\n" +
863 "}\n" +
864 "\n";
865 }
866 }