f2cf0538f0430e208d755eb475a9d1b45a044748
[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=9.0.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 this.getTaskComposerInstall(),
436 new ScriptTask()
437 .description("Run duplicate exception code check script")
438 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
439 .inlineBody(
440 this.getScriptTaskBashInlineBody() +
441 "./Build/Scripts/duplicateExceptionCodeCheck.sh\n"
442 ),
443 new ScriptTask()
444 .description("Run git submodule status and verify there are none")
445 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
446 .inlineBody(
447 this.getScriptTaskBashInlineBody() +
448 "if [[ `git submodule status 2>&1 | wc -l` -ne 0 ]]; then\n" +
449 " echo \\\"Found a submodule definition in repository\\\";\n" +
450 " exit 99;\n" +
451 "fi\n"
452 ),
453 new ScriptTask()
454 .description("Run permission check script")
455 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
456 .inlineBody(
457 this.getScriptTaskBashInlineBody() +
458 "./Build/Scripts/checkFilePermissions.sh\n"
459 ),
460 new ScriptTask()
461 .description("Run xlf check")
462 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
463 .inlineBody(
464 this.getScriptTaskBashInlineBody() +
465 "./Build/Scripts/xlfcheck.sh"
466 ),
467 new ScriptTask()
468 .description("Run rst check")
469 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
470 .inlineBody(
471 this.getScriptTaskBashInlineBody() +
472 "./Build/Scripts/validateRstFiles.sh"
473 ),
474 new ScriptTask()
475 .description("Run path length check")
476 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
477 .inlineBody(
478 this.getScriptTaskBashInlineBody() +
479 "./Build/Scripts/maxFilePathLength.sh"
480 ),
481 new ScriptTask()
482 .description("Run extension scanner ReST file reference tester")
483 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
484 .inlineBody(
485 this.getScriptTaskBashInlineBody() +
486 "./Build/Scripts/extensionScannerRstFileReferences.php"
487 )
488 )
489 .requirements(
490 new Requirement("system.phpVersion")
491 .matchValue("7\\.0|7\\.1")
492 .matchType(Requirement.MatchType.MATCHES)
493 )
494 .cleanWorkingDirectory(true);
495 }
496
497 /**
498 * Job for javascript unit tests
499 */
500 protected Job getJobUnitJavaScript() {
501 return new Job("Unit JavaScript", new BambooKey("JSUT"))
502 .description("Run JavaScript unit tests")
503 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
504 .tasks(
505 this.getTaskGitCloneRepository(),
506 this.getTaskGitCherryPick(),
507 this.getTaskComposerInstall(),
508 new NpmTask()
509 .description("npm install in Build/ dir")
510 .nodeExecutable("Node.js")
511 .workingSubdirectory("Build/")
512 .command("install"),
513 new ScriptTask()
514 .description("Run tests")
515 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
516 .inlineBody(
517 this.getScriptTaskBashInlineBody() +
518 "./Build/node_modules/karma/bin/karma start " + this.testingFrameworkBuildPath + "Configuration/JSUnit/karma.conf.js --single-run"
519 )
520 )
521 .finalTasks(
522 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
523 .resultDirectories("typo3temp/var/tests/*")
524 )
525 .requirements(
526 new Requirement("system.phpVersion")
527 .matchValue("7\\.0|7\\.1")
528 .matchType(Requirement.MatchType.MATCHES)
529 )
530 .artifacts(
531 new Artifact()
532 .name("Clover Report (System)")
533 .copyPattern("**/*.*")
534 .location("Build/target/site/clover")
535 .shared(false)
536 )
537 .cleanWorkingDirectory(true);
538 }
539
540 /**
541 * Job for PHP lint
542 *
543 * @param Requirement requirement
544 * @param String requirementIdentfier
545 */
546 protected Job getJobLintPhp(Requirement requirement, String requirementIdentifier) {
547 return new Job("Lint " + requirementIdentifier, new BambooKey("L" + requirementIdentifier))
548 .description("Run php -l on source files for linting " + requirementIdentifier)
549 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
550 .tasks(
551 this.getTaskGitCloneRepository(),
552 this.getTaskGitCherryPick(),
553 new ScriptTask()
554 .description("Run php lint")
555 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
556 .inlineBody(
557 this.getScriptTaskBashInlineBody() +
558 "find . -name \\*.php -print0 | xargs -0 -n1 -P2 php -l >/dev/null\n"
559 )
560 )
561 .requirements(
562 requirement
563 )
564 .cleanWorkingDirectory(true);
565 }
566
567 /**
568 * Job for lint npm scss and typescript
569 */
570 protected Job getJobLintScssTs() {
571 return new Job("Lint scss ts", new BambooKey("LSTS"))
572 .description("Run npm lint in Build/ dir")
573 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
574 .tasks(
575 this.getTaskGitCloneRepository(),
576 this.getTaskGitCherryPick(),
577 new NpmTask()
578 .description("npm install in Build/ dir")
579 .nodeExecutable("Node.js")
580 .workingSubdirectory("Build/")
581 .command("install"),
582 new NpmTask()
583 .description("Run npm lint")
584 .nodeExecutable("Node.js")
585 .workingSubdirectory("Build/")
586 .command("run lint")
587 )
588 .requirements(
589 new Requirement("system.imageVersion")
590 )
591 .cleanWorkingDirectory(true);
592 }
593
594 /**
595 * Job for unit testing PHP
596 *
597 * @param Requirement requirement
598 * @param String requirementIdentfier
599 */
600 protected Job getJobUnitPhp(Requirement requirement, String requirementIdentifier) {
601 return new Job("Unit " + requirementIdentifier, new BambooKey("UT" + requirementIdentifier))
602 .description("Run unit tests " + requirementIdentifier)
603 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
604 .tasks(
605 this.getTaskGitCloneRepository(),
606 this.getTaskGitCherryPick(),
607 this.getTaskComposerInstall(),
608 new ScriptTask()
609 .description("Run phpunit")
610 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
611 .inlineBody(
612 this.getScriptTaskBashInlineBody() +
613 this.getScriptTaskBashPhpNoXdebug() +
614 "php_no_xdebug bin/phpunit --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "UnitTests.xml"
615 )
616 )
617 .finalTasks(
618 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
619 .resultDirectories("test-reports/phpunit.xml")
620 )
621 .requirements(
622 requirement
623 )
624 .cleanWorkingDirectory(true);
625 }
626
627 /**
628 * Jobs for unit testing PHP in random test order
629 *
630 * @param int numberOfRuns
631 * @param Requirement requirement
632 * @param String requirementIdentfier
633 */
634 protected ArrayList<Job> getJobUnitPhpRandom(int numberOfRuns, Requirement requirement, String requirementIdentifier) {
635 ArrayList<Job> jobs = new ArrayList<Job>();
636
637 for (int i=0; i<numberOfRuns; i++) {
638 jobs.add(new Job("Unit " + requirementIdentifier + " random 0" + i, new BambooKey("UTR" + requirementIdentifier + "0" + i))
639 .description("Run unit tests on " + requirementIdentifier + " in random order 0" + i)
640 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
641 .tasks(
642 this.getTaskGitCloneRepository(),
643 this.getTaskGitCherryPick(),
644 this.getTaskComposerInstall(),
645 new ScriptTask()
646 .description("Run phpunit-randomizer")
647 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
648 .inlineBody(
649 this.getScriptTaskBashInlineBody() +
650 this.getScriptTaskBashPhpNoXdebug() +
651 "php_no_xdebug bin/phpunit-randomizer --log-junit test-reports/phpunit.xml -c " + this.testingFrameworkBuildPath + "UnitTests.xml --order rand"
652 )
653 )
654 .finalTasks(
655 new TestParserTask(TestParserTaskProperties.TestType.JUNIT)
656 .resultDirectories("test-reports/phpunit.xml")
657 )
658 .requirements(
659 requirement
660 )
661 .cleanWorkingDirectory(true)
662 );
663 }
664
665 return jobs;
666 }
667
668 /**
669 * Task definition for basic core clone of linked default repository
670 */
671 protected Task getTaskGitCloneRepository() {
672 return new VcsCheckoutTask()
673 .description("Checkout git core")
674 .checkoutItems(new CheckoutItem().defaultRepository())
675 .cleanCheckout(true);
676 }
677
678 /**
679 * Task definition to cherry pick a patch set from gerrit on top of cloned core
680 */
681 protected Task getTaskGitCherryPick() {
682 return new ScriptTask()
683 .description("Gerrit cherry pick")
684 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
685 .inlineBody(
686 this.getScriptTaskBashInlineBody() +
687 "CHANGEURL=${bamboo.changeUrl}\n" +
688 "CHANGEURLID=${CHANGEURL#https://review.typo3.org/}\n" +
689 "PATCHSET=${bamboo.patchset}\n" +
690 "\n" +
691 "if [[ $CHANGEURL ]]; then\n" +
692 " gerrit-cherry-pick https://review.typo3.org/Packages/TYPO3.CMS $CHANGEURLID/$PATCHSET || exit 1\n" +
693 "fi\n"
694 );
695 }
696
697 /**
698 * Task definition to execute composer install
699 */
700 protected Task getTaskComposerInstall() {
701 return new CommandTask()
702 .description("composer install")
703 .executable("composer")
704 .argument("install -n")
705 .environmentVariables(this.composerRootVersionEnvironment);
706 }
707
708 /**
709 * Task to prepare an acceptance test starting selenium and others
710 */
711 protected Task getTaskPrepareAcceptanceTest() {
712 return new ScriptTask()
713 .description("Start php web server, chromedriver, prepare environment")
714 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
715 .inlineBody(
716 this.getScriptTaskBashInlineBody() +
717 "php -S localhost:8000 >/dev/null 2>&1 &\n" +
718 "echo $! > phpserver.pid\n" +
719 "\n" +
720 "./bin/chromedriver --url-base=/wd/hub >/dev/null 2>&1 &\n" +
721 "echo $! > chromedriver.pid\n" +
722 "\n" +
723 "mkdir -p typo3temp/var/tests/\n"
724 );
725 }
726
727 /**
728 * Task to delete any created mysql test databases, used as final task
729 */
730 protected Task getTaskDeleteMysqlDatabases() {
731 return new ScriptTask()
732 .description("Delete mysql test dbs")
733 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
734 .inlineBody(
735 this.getScriptTaskBashInlineBody() +
736 "DB_STARTS_WITH=\"func_\"\n" +
737 "MUSER=\"funcu\"\n" +
738 "MPWD=\"funcp\"\n" +
739 "MYSQL=\"mysql\"\n" +
740 "DBS=\"$($MYSQL -u $MUSER -p\"$MPWD\" -Bse 'show databases')\"\n" +
741 "\n" +
742 "for db in $DBS; do\n" +
743 " if [[ \"$db\" == $DB_STARTS_WITH* ]]; then\n" +
744 " echo \"Deleting $db\"\n" +
745 " $MYSQL -u $MUSER -p\"$MPWD\" -Bse \"drop database $db\"\n" +
746 " fi\n" +
747 "done\n"
748 );
749 }
750
751 /**
752 * Task to delete any created mssql test databases, used as final task
753 */
754 protected Task getTaskDeleteMssqlDatabases() {
755 return new ScriptTask()
756 .description("Delete mssql test dbs")
757 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
758 .inlineBody(
759 this.getScriptTaskBashInlineBody() +
760 "DBS=`/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Test1234!' -Q 'select name from sys.databases' | grep '^func_'`\n" +
761 "\n" +
762 "for db in $DBS; do\n" +
763 " echo \"Deleteing $db\"\n" +
764 " /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Test1234!' -Q \"drop database $db\"\n" +
765 "done\n"
766 );
767 }
768
769 /**
770 * Task to delete any created pgsql test databases, used as final task
771 */
772 protected Task getTaskDeletePgsqlDatabases() {
773 return new ScriptTask()
774 .description("Delete pgsql test dbs")
775 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
776 .inlineBody(
777 this.getScriptTaskBashInlineBody() +
778 "DB_STARTS_WITH=\"func_\"\n" +
779 "PGUSER=\"bamboo\"\n" +
780 "DBS=\"$(/usr/bin/psql -qtA -c 'SELECT datname FROM pg_database WHERE datistemplate = false;' postgres)\"\n" +
781 "\n" +
782 "for db in $DBS; do\n" +
783 " if [[ \"$db\" == $DB_STARTS_WITH* ]]; then\n" +
784 " echo \"Deleting $db\"\n" +
785 " /usr/bin/psql -qtA -c \"DROP DATABASE $db\" postgres\n" +
786 " fi\n" +
787 "done\n"
788 );
789 }
790
791 /**
792 * Task to stop selenium and friends, opposite of getTaskPrepareAcceptanceTest, used as final task
793 */
794 protected Task getTaskTearDownAcceptanceTestSetup() {
795 return new ScriptTask()
796 .description("Stop acceptance test services like chromedriver and friends")
797 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
798 .inlineBody(
799 this.getScriptTaskBashInlineBody() +
800 "kill `cat phpserver.pid`\n" +
801 "kill `cat chromedriver.pid`\n"
802 );
803 }
804
805 /**
806 * Task to split functional jobs into chunks
807 */
808 protected Task getTaskSplitFunctionalJobs(int numberOfJobs) {
809 return new ScriptTask()
810 .description("Create list of test files to execute per job")
811 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
812 .inlineBody(
813 this.getScriptTaskBashInlineBody() +
814 "./" + this.testingFrameworkBuildPath + "Scripts/splitFunctionalTests.sh " + numberOfJobs
815 );
816 }
817
818 /**
819 * Requirement for php 7.0
820 */
821 protected Requirement getRequirementPhpVersion70() {
822 return new Requirement("system.phpVersion")
823 .matchValue("7.0")
824 .matchType(Requirement.MatchType.EQUALS);
825 }
826
827 /**
828 * Requirement for php 7.1
829 */
830 protected Requirement getRequirementPhpVersion71() {
831 return new Requirement("system.phpVersion")
832 .matchValue("7.1")
833 .matchType(Requirement.MatchType.EQUALS);
834 }
835
836 /**
837 * Requirement for php 7.0 or 7.1
838 */
839 protected Requirement getRequirementPhpVersion70Or71() {
840 return new Requirement("system.phpVersion")
841 .matchValue("7\\.0|7\\.1")
842 .matchType(Requirement.MatchType.MATCHES);
843 }
844
845 /**
846 * A bash header for script tasks forking a bash if needed
847 */
848 protected String getScriptTaskBashInlineBody() {
849 return
850 "#!/bin/bash\n" +
851 "\n" +
852 "if [ \"$(ps -p \"$$\" -o comm=)\" != \"bash\" ]; then\n" +
853 " bash \"$0\" \"$@\"\n" +
854 " exit \"$?\"\n" +
855 "fi\n" +
856 "\n";
857 }
858
859 /**
860 * A bash function providing a php bin without xdebug
861 */
862 protected String getScriptTaskBashPhpNoXdebug() {
863 return
864 "php_no_xdebug () {\n" +
865 " temporaryPath=\"$(mktemp -t php.XXXX).ini\"\n" +
866 " php -i | grep \"\\.ini\" | grep -o -e '\\(/[A-Za-z0-9._-]\\+\\)\\+\\.ini' | grep -v xdebug | xargs awk 'FNR==1{print \"\"}1' > \"${temporaryPath}\"\n" +
867 " php -n -c \"${temporaryPath}\" \"$@\"\n" +
868 " RETURN=$?\n" +
869 " rm -f \"${temporaryPath}\"\n" +
870 " exit $RETURN\n" +
871 "}\n" +
872 "\n";
873 }
874 }