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