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