870c1f8ff232aec38de7b384e454e30585c6230b
[Packages/TYPO3.CMS.git] / Build / bamboo / src / main / java / core / PreMergeSpec.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.BambooSpec;
19 import com.atlassian.bamboo.specs.api.builders.AtlassianModule;
20 import com.atlassian.bamboo.specs.api.builders.BambooKey;
21 import com.atlassian.bamboo.specs.api.builders.Variable;
22 import com.atlassian.bamboo.specs.api.builders.notification.AnyNotificationRecipient;
23 import com.atlassian.bamboo.specs.api.builders.notification.Notification;
24 import com.atlassian.bamboo.specs.api.builders.plan.Job;
25 import com.atlassian.bamboo.specs.api.builders.plan.Plan;
26 import com.atlassian.bamboo.specs.api.builders.plan.Stage;
27 import com.atlassian.bamboo.specs.api.builders.plan.branches.BranchCleanup;
28 import com.atlassian.bamboo.specs.api.builders.plan.branches.PlanBranchManagement;
29 import com.atlassian.bamboo.specs.api.builders.project.Project;
30 import com.atlassian.bamboo.specs.api.builders.requirement.Requirement;
31 import com.atlassian.bamboo.specs.builders.notification.PlanCompletedNotification;
32 import com.atlassian.bamboo.specs.builders.task.ScriptTask;
33 import com.atlassian.bamboo.specs.builders.trigger.RemoteTrigger;
34 import com.atlassian.bamboo.specs.builders.trigger.RepositoryPollingTrigger;
35 import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
36 import com.atlassian.bamboo.specs.util.BambooServer;
37
38 /**
39 * Core master pre-merge test plan.
40 */
41 @BambooSpec
42 public class PreMergeSpec extends AbstractCoreSpec {
43
44 protected static String planName = "Core master pre-merge";
45 protected static String planKey = "GTC";
46
47 protected int numberOfAcceptanceTestJobs = 10;
48 protected int numberOfFunctionalMysqlJobs = 10;
49 protected int numberOfFunctionalMssqlJobs = 10;
50 protected int numberOfFunctionalPgsqlJobs = 10;
51 protected int numberOfFunctionalSqliteJobs = 10;
52 protected int numberOfUnitRandomOrderJobs = 2;
53
54 /**
55 * Run main to publish plan on Bamboo
56 */
57 public static void main(final String[] args) throws Exception {
58 // By default credentials are read from the '.credentials' file.
59 BambooServer bambooServer = new BambooServer(bambooServerName);
60 bambooServer.publish(new PreMergeSpec().createPlan());
61 bambooServer.publish(new PreMergeSpec().getDefaultPlanPermissions(projectKey, planKey));
62 }
63
64 /**
65 * Core master pre-merge plan is in "TYPO3 core" project of bamboo
66 */
67 Project project() {
68 return new Project().name(projectName).key(projectKey);
69 }
70
71 /**
72 * Returns full Plan definition
73 */
74 Plan createPlan() {
75 // PREPARATION stage
76 ArrayList<Job> jobsPreparationStage = new ArrayList<Job>();
77 jobsPreparationStage.add(this.getJobBuildLabels());
78 Stage stagePreparation = new Stage("Preparation")
79 .jobs(jobsPreparationStage.toArray(new Job[jobsPreparationStage.size()]));
80
81 // EARLY stage
82 ArrayList<Job> jobsEarlyStage = new ArrayList<Job>();
83 jobsEarlyStage.add(this.getJobCglCheckGitCommit("PHP72"));
84 jobsEarlyStage.add(this.getJobComposerValidate("PHP72"));
85 Stage stageEarly = new Stage("Early")
86 .jobs(jobsEarlyStage.toArray(new Job[jobsEarlyStage.size()]));
87
88 // MAIN stage
89 ArrayList<Job> jobsMainStage = new ArrayList<Job>();
90
91 jobsMainStage.add(this.getJobAcceptanceTestInstallMysql("PHP72"));
92 jobsMainStage.add(this.getJobAcceptanceTestInstallPgsql("PHP72"));
93 jobsMainStage.add(this.getJobAcceptanceTestInstallSqlite("PHP72"));
94
95 jobsMainStage.addAll(this.getJobsAcceptanceTestsBackendMysql(this.numberOfAcceptanceTestJobs, "PHP72"));
96
97 jobsMainStage.add(this.getJobIntegrationAnnotations("PHP72"));
98
99 jobsMainStage.add(this.getJobIntegrationVarious("PHP72"));
100
101 jobsMainStage.addAll(this.getJobsFunctionalTestsMysql(this.numberOfFunctionalMysqlJobs, "PHP72"));
102 // mssql functionals are not executed as pre-merge
103 // jobsMainStage.addAll(this.getJobsFunctionalTestsMssql(this.numberOfFunctionalMssqlJobs, "PHP72"));
104 jobsMainStage.addAll(this.getJobsFunctionalTestsPgsql(this.numberOfFunctionalPgsqlJobs, "PHP72"));
105 jobsMainStage.addAll(this.getJobsFunctionalTestsSqlite(this.numberOfFunctionalSqliteJobs, "PHP72"));
106
107 jobsMainStage.add(this.getJobUnitJavaScript("PHP72"));
108
109 jobsMainStage.add(this.getJobLintPhp("PHP72"));
110
111 jobsMainStage.add(this.getJobLintScssTs("PHP72"));
112
113 jobsMainStage.add(this.getJobUnitPhp("PHP72"));
114 jobsMainStage.add(this.getJobUnitDeprecatedPhp("PHP72"));
115 jobsMainStage.addAll(this.getJobUnitPhpRandom(this.numberOfUnitRandomOrderJobs, "PHP72"));
116
117 Stage stageMainStage = new Stage("Main stage")
118 .jobs(jobsMainStage.toArray(new Job[jobsMainStage.size()]));
119
120 // Compile plan
121 return new Plan(project(), planName, planKey)
122 .description("Execute TYPO3 core master pre-merge tests. Auto generated! See Build/bamboo of core git repository.")
123 .pluginConfigurations(this.getDefaultPlanPluginConfiguration())
124 .stages(
125 stagePreparation,
126 stageEarly,
127 stageMainStage
128 )
129 .linkedRepositories("github TYPO3 TYPO3.CMS")
130 .triggers(
131 new RepositoryPollingTrigger()
132 .name("Repository polling for post-merge builds"),
133 new RemoteTrigger()
134 .name("Remote trigger for pre-merge builds")
135 .description("Gerrit")
136 .triggerIPAddresses("5.10.165.218,91.184.35.13"))
137 .variables(
138 new Variable("changeUrl", ""),
139 new Variable("patchset", "")
140 )
141 .planBranchManagement(
142 new PlanBranchManagement()
143 .delete(new BranchCleanup())
144 .notificationForCommitters()
145 )
146 .notifications(new Notification()
147 .type(new PlanCompletedNotification())
148 .recipients(new AnyNotificationRecipient(new AtlassianModule("com.atlassian.bamboo.plugins.bamboo-slack:recipient.slack"))
149 .recipientString("https://intercept.typo3.com/index.php")
150 )
151 );
152 }
153
154 /**
155 * Job checking CGL of last git commit
156 *
157 * @param String requirementIdentifier
158 */
159 protected Job getJobCglCheckGitCommit(String requirementIdentifier) {
160 return new Job("Integration CGL", new BambooKey("CGLCHECK"))
161 .description("Check coding guidelines by executing Build/Scripts/cglFixMyCommit.sh script")
162 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
163 .tasks(
164 this.getTaskGitCloneRepository(),
165 this.getTaskGitCherryPick(),
166 this.getTaskComposerInstall(requirementIdentifier),
167 new ScriptTask()
168 .description("Execute cgl check script")
169 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
170 .inlineBody(
171 this.getScriptTaskBashInlineBody() +
172 "function cglFixMyCommit() {\n" +
173 " docker run \\\n" +
174 " -u ${HOST_UID} \\\n" +
175 " -v /bamboo-data/${BAMBOO_COMPOSE_PROJECT_NAME}/passwd:/etc/passwd \\\n" +
176 " -v ${BAMBOO_COMPOSE_PROJECT_NAME}_bamboo-data:/srv/bamboo/xml-data/build-dir/ \\\n" +
177 " --name ${BAMBOO_COMPOSE_PROJECT_NAME}sib_adhoc \\\n" +
178 " --rm \\\n" +
179 " typo3gmbh/" + requirementIdentifier.toLowerCase() + ":latest \\\n" +
180 " bin/bash -c \"cd ${PWD}; ./Build/Scripts/cglFixMyCommit.sh $*\"\n" +
181 "}\n" +
182 "\n" +
183 "cglFixMyCommit dryrun\n"
184 )
185 )
186 .requirements(
187 this.getRequirementDocker10()
188 )
189 .cleanWorkingDirectory(true);
190 }
191 }