9b5c1a3aa1da1aa3692b89864a69a72d0a158b00
[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.plan.configuration.AllOtherPluginsConfiguration;
30 import com.atlassian.bamboo.specs.api.builders.project.Project;
31 import com.atlassian.bamboo.specs.api.builders.requirement.Requirement;
32 import com.atlassian.bamboo.specs.builders.notification.PlanCompletedNotification;
33 import com.atlassian.bamboo.specs.builders.task.ScriptTask;
34 import com.atlassian.bamboo.specs.builders.trigger.RemoteTrigger;
35 import com.atlassian.bamboo.specs.builders.trigger.RepositoryPollingTrigger;
36 import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
37 import com.atlassian.bamboo.specs.util.BambooServer;
38 import com.atlassian.bamboo.specs.util.MapBuilder;
39
40 /**
41 * Core master pre-merge test plan.
42 */
43 @BambooSpec
44 public class PreMergeSpec extends AbstractCoreSpec {
45
46 protected static String planName = "Core master pre-merge";
47 protected static String planKey = "GTC";
48
49 protected int numberOfAcceptanceTestJobs = 8;
50 protected int numberOfFunctionalMysqlJobs = 10;
51 protected int numberOfFunctionalMssqlJobs = 10;
52 protected int numberOfFunctionalPgsqlJobs = 10;
53 protected int numberOfFunctionalSqliteJobs = 10;
54 protected int numberOfUnitRandomOrderJobs = 2;
55
56 /**
57 * Run main to publish plan on Bamboo
58 */
59 public static void main(final String[] args) throws Exception {
60 // By default credentials are read from the '.credentials' file.
61 BambooServer bambooServer = new BambooServer(bambooServerName);
62 bambooServer.publish(new PreMergeSpec().createPlan());
63 bambooServer.publish(new PreMergeSpec().getDefaultPlanPermissions(projectKey, planKey));
64 }
65
66 /**
67 * Core master pre-merge plan is in "TYPO3 core" project of bamboo
68 */
69 Project project() {
70 return new Project().name(projectName).key(projectKey);
71 }
72
73 /**
74 * Returns full Plan definition
75 */
76 Plan createPlan() {
77 // PREPARATION stage
78 ArrayList<Job> jobsPreparationStage = new ArrayList<Job>();
79 jobsPreparationStage.add(this.getJobBuildLabels());
80 Stage stagePreparation = new Stage("Preparation")
81 .jobs(jobsPreparationStage.toArray(new Job[jobsPreparationStage.size()]));
82
83 // EARLY stage
84 ArrayList<Job> jobsEarlyStage = new ArrayList<Job>();
85 jobsEarlyStage.add(this.getJobCglCheckGitCommit("PHP72"));
86 jobsEarlyStage.add(this.getJobComposerValidate("PHP72"));
87 Stage stageEarly = new Stage("Early")
88 .jobs(jobsEarlyStage.toArray(new Job[jobsEarlyStage.size()]));
89
90 // MAIN stage
91 ArrayList<Job> jobsMainStage = new ArrayList<Job>();
92
93 jobsMainStage.add(this.getJobAcceptanceTestInstallMysql("PHP72"));
94 jobsMainStage.add(this.getJobAcceptanceTestInstallPgsql("PHP72"));
95 jobsMainStage.add(this.getJobAcceptanceTestInstallSqlite("PHP72"));
96
97 jobsMainStage.addAll(this.getJobsAcceptanceTestsMysql(this.numberOfAcceptanceTestJobs, "PHP72"));
98
99 jobsMainStage.add(this.getJobIntegrationAnnotations("PHP72"));
100
101 jobsMainStage.add(this.getJobIntegrationVarious("PHP72"));
102
103 jobsMainStage.addAll(this.getJobsFunctionalTestsMysql(this.numberOfFunctionalMysqlJobs, "PHP72"));
104 jobsMainStage.addAll(this.getJobsFunctionalTestsMssql(this.numberOfFunctionalMssqlJobs, "PHP72"));
105 jobsMainStage.addAll(this.getJobsFunctionalTestsPgsql(this.numberOfFunctionalPgsqlJobs, "PHP72"));
106 jobsMainStage.addAll(this.getJobsFunctionalTestsSqlite(this.numberOfFunctionalSqliteJobs, "PHP72"));
107
108 jobsMainStage.add(this.getJobUnitJavaScript("PHP72"));
109
110 jobsMainStage.add(this.getJobLintPhp("PHP72"));
111
112 jobsMainStage.add(this.getJobLintScssTs("PHP72"));
113
114 jobsMainStage.add(this.getJobUnitPhp("PHP72"));
115 jobsMainStage.add(this.getJobUnitDeprecatedPhp("PHP72"));
116 jobsMainStage.addAll(this.getJobUnitPhpRandom(this.numberOfUnitRandomOrderJobs, "PHP72"));
117
118 Stage stageMainStage = new Stage("Main stage")
119 .jobs(jobsMainStage.toArray(new Job[jobsMainStage.size()]));
120
121 // Compile plan
122 return new Plan(project(), planName, planKey)
123 .description("Execute TYPO3 core master pre-merge tests. Auto generated! See Build/bamboo of core git repository.")
124 .pluginConfigurations(this.getDefaultPlanPluginConfiguration())
125 .stages(
126 stagePreparation,
127 stageEarly,
128 stageMainStage
129 )
130 .linkedRepositories("git.typo3.org Core")
131 .triggers(
132 new RepositoryPollingTrigger()
133 .name("Repository polling for post-merge builds"),
134 new RemoteTrigger()
135 .name("Remote trigger for pre-merge builds")
136 .description("Gerrit")
137 .triggerIPAddresses("5.10.165.218,91.184.35.13"))
138 .variables(
139 new Variable("changeUrl", ""),
140 new Variable("patchset", "")
141 )
142 .planBranchManagement(
143 new PlanBranchManagement()
144 .delete(new BranchCleanup())
145 .notificationForCommitters()
146 )
147 .notifications(new Notification()
148 .type(new PlanCompletedNotification())
149 .recipients(new AnyNotificationRecipient(new AtlassianModule("com.atlassian.bamboo.plugins.bamboo-slack:recipient.slack"))
150 .recipientString("https://intercept.typo3.com/index.php")
151 )
152 );
153 }
154
155 /**
156 * Job creating labels needed for intercept communication
157 */
158 protected Job getJobBuildLabels() {
159 return new Job("Create build labels", new BambooKey("CLFB"))
160 .description("Create changeId and patch set labels from variable access and parsing result of a dummy task")
161 .pluginConfigurations(new AllOtherPluginsConfiguration()
162 .configuration(new MapBuilder()
163 .put("repositoryDefiningWorkingDirectory", -1)
164 .put("custom", new MapBuilder()
165 .put("auto", new MapBuilder()
166 .put("regex", "https:\\/\\/review\\.typo3\\.org\\/(#\\/c\\/)?(\\d+)")
167 .put("label", "change-\\2\\, patchset-${bamboo.patchset}")
168 .build()
169 )
170 .put("buildHangingConfig.enabled", "false")
171 .put("ncover.path", "")
172 .put("clover", new MapBuilder()
173 .put("path", "")
174 .put("license", "")
175 .put("useLocalLicenseKey", "true")
176 .build()
177 )
178 .build()
179 )
180 .build()
181 )
182 )
183 .tasks(
184 new ScriptTask()
185 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
186 .inlineBody("echo \"I'm just here for the labels!\"")
187 )
188 .requirements(
189 this.getRequirementDocker10()
190 )
191 .cleanWorkingDirectory(true);
192 }
193
194 /**
195 * Job checking CGL of last git commit
196 *
197 * @param String requirementIdentifier
198 */
199 protected Job getJobCglCheckGitCommit(String requirementIdentifier) {
200 return new Job("Integration CGL", new BambooKey("CGLCHECK"))
201 .description("Check coding guidelines by executing Build/Scripts/cglFixMyCommit.sh script")
202 .pluginConfigurations(this.getDefaultJobPluginConfiguration())
203 .tasks(
204 this.getTaskGitCloneRepository(),
205 this.getTaskGitCherryPick(),
206 this.getTaskComposerInstall(requirementIdentifier),
207 new ScriptTask()
208 .description("Execute cgl check script")
209 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
210 .inlineBody(
211 this.getScriptTaskBashInlineBody() +
212 "function cglFixMyCommit() {\n" +
213 " docker run \\\n" +
214 " -u ${HOST_UID} \\\n" +
215 " -v /etc/passwd:/etc/passwd \\\n" +
216 " -v ${BAMBOO_COMPOSE_PROJECT_NAME}_bamboo-data:/srv/bamboo/xml-data/build-dir/ \\\n" +
217 " --name ${BAMBOO_COMPOSE_PROJECT_NAME}sib_adhoc \\\n" +
218 " --rm \\\n" +
219 " typo3gmbh/" + requirementIdentifier.toLowerCase() + ":latest \\\n" +
220 " bin/bash -c \"cd ${PWD}; ./Build/Scripts/cglFixMyCommit.sh $*\"\n" +
221 "}\n" +
222 "\n" +
223 "cglFixMyCommit dryrun\n"
224 )
225 )
226 .requirements(
227 this.getRequirementDocker10()
228 )
229 .cleanWorkingDirectory(true);
230 }
231 }