[TASK] bamboo-specs: Upgrade to 6.1 99/54299/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 4 Oct 2017 21:02:31 +0000 (23:02 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 5 Oct 2017 09:45:19 +0000 (11:45 +0200)
The 6.0 to 6.1 upgrade allows us to specifiy last missing
pieces via bamboo specs: mostly job cleanups, plugin
configuration and plan permissions.

Change-Id: If26aeb45b1109ba9797f3807087201033ea1f368
Resolves: #82679
Releases: master, 8.7, 7.6
Reviewed-on: https://review.typo3.org/54299
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Build/bamboo/pom.xml
Build/bamboo/src/main/java/core/AbstractCoreSpec.java
Build/bamboo/src/main/java/core/PreMergeSpec.java

index a47fddd..30c3f14 100644 (file)
@@ -5,7 +5,7 @@
   <parent>
     <groupId>com.atlassian.bamboo</groupId>
     <artifactId>bamboo-specs-parent</artifactId>
-    <version>6.0.2</version>
+    <version>6.1.0</version>
     <relativePath/>
   </parent>
 
index 25d718f..69d293f 100644 (file)
@@ -16,7 +16,13 @@ package core;
 import java.util.ArrayList;
 
 import com.atlassian.bamboo.specs.api.builders.BambooKey;
+import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;
+import com.atlassian.bamboo.specs.api.builders.permission.Permissions;
+import com.atlassian.bamboo.specs.api.builders.permission.PlanPermissions;
 import com.atlassian.bamboo.specs.api.builders.plan.Job;
+import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;
+import com.atlassian.bamboo.specs.api.builders.plan.configuration.AllOtherPluginsConfiguration;
+import com.atlassian.bamboo.specs.api.builders.plan.configuration.PluginConfiguration;
 import com.atlassian.bamboo.specs.api.builders.requirement.Requirement;
 import com.atlassian.bamboo.specs.api.builders.task.Task;
 import com.atlassian.bamboo.specs.builders.task.CheckoutItem;
@@ -26,12 +32,17 @@ import com.atlassian.bamboo.specs.builders.task.TestParserTask;
 import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;
 import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
 import com.atlassian.bamboo.specs.model.task.TestParserTaskProperties;
+import com.atlassian.bamboo.specs.util.MapBuilder;
 
 /**
  * Abstract class with common methods of pre-merge and nightly plan
  */
 abstract public class AbstractCoreSpec {
 
+    protected static String bambooServerName = "https://bamboo.typo3.com:443";
+    protected static String projectName = "TYPO3 Core";
+    protected static String projectKey = "CORE";
+
     protected String testingFrameworkBuildPath = "typo3/sysext/core/Build/";
 
     protected String credentialsMysql =
@@ -42,18 +53,91 @@ abstract public class AbstractCoreSpec {
         " typo3InstallToolPassword=\"klaus\"";
 
     /**
+     * Default permissions on core plans
+     *
+     * @param projectName
+     * @param planName
+     * @return
+     */
+    protected PlanPermissions getDefaultPlanPermissions(String projectKey, String planKey) {
+        return new PlanPermissions(new PlanIdentifier(projectKey, planKey))
+            .permissions(new Permissions()
+            .groupPermissions("TYPO3 GmbH", PermissionType.ADMIN, PermissionType.VIEW, PermissionType.EDIT, PermissionType.BUILD, PermissionType.CLONE)
+            .groupPermissions("TYPO3 Core Team", PermissionType.VIEW, PermissionType.BUILD)
+            .loggedInUserPermissions(PermissionType.VIEW)
+            .anonymousUserPermissionView()
+        );
+    }
+
+    /**
+     * Default plan plugin configuration
+     *
+     * @return
+     */
+    protected PluginConfiguration getDefaultPlanPluginConfiguration() {
+        return new AllOtherPluginsConfiguration()
+            .configuration(new MapBuilder()
+            .put("custom", new MapBuilder()
+                .put("artifactHandlers.useCustomArtifactHandlers", "false")
+                .put("buildExpiryConfig", new MapBuilder()
+                    .put("duration", "30")
+                    .put("period", "days")
+                    .put("labelsToKeep", "")
+                    .put("expiryTypeResult", "true")
+                    .put("buildsToKeep", "")
+                    .put("enabled", "true")
+                    .build()
+                )
+                .build()
+            )
+            .build()
+        );
+    }
+
+    /**
+     * Default job plugin configuration
+     *
+     * @return
+     */
+    protected PluginConfiguration getDefaultJobPluginConfiguration() {
+        return new AllOtherPluginsConfiguration()
+            .configuration(new MapBuilder()
+                .put("repositoryDefiningWorkingDirectory", -1)
+                .put("custom", new MapBuilder()
+                    .put("auto", new MapBuilder()
+                        .put("regex", "")
+                        .put("label", "")
+                        .build()
+                    )
+                    .put("buildHangingConfig.enabled", "false")
+                    .put("ncover.path", "")
+                    .put("clover", new MapBuilder()
+                        .put("path", "")
+                        .put("license", "")
+                        .put("useLocalLicenseKey", "true")
+                        .build()
+                    )
+                    .build()
+                )
+                .build()
+            );
+    }
+
+    /**
      * Job composer validate
      */
     protected Job getJobComposerValidate() {
         return new Job("Validate composer.json", new BambooKey("VC"))
         .description("Validate composer.json before actual tests are executed")
+        .pluginConfigurations(this.getDefaultJobPluginConfiguration())
         .tasks(
             this.getTaskGitCloneRepository(),
             this.getTaskGitCherryPick(),
             new CommandTask()
                 .description("composer validate")
                 .executable("composer").argument("validate")
-        );
+        )
+        .cleanWorkingDirectory(true);
     }
 
     /**
@@ -69,6 +153,7 @@ abstract public class AbstractCoreSpec {
         for (int i=0; i<numberOfChunks; i++) {
             jobs.add(new Job("Func mysql " + requirementIdentifier + " 0" + i, new BambooKey("FMY" + requirementIdentifier + "0" + i))
                 .description("Run functional tests on mysql DB " + requirementIdentifier)
+                .pluginConfigurations(this.getDefaultJobPluginConfiguration())
                 .tasks(
                     this.getTaskGitCloneRepository(),
                     this.getTaskGitCherryPick(),
@@ -91,6 +176,7 @@ abstract public class AbstractCoreSpec {
                 .requirements(
                     requirement
                 )
+                .cleanWorkingDirectory(true)
             );
         }
 
@@ -104,6 +190,7 @@ abstract public class AbstractCoreSpec {
         // Exception code checker, xlf, permissions, rst file check
         return new Job("Integration various", new BambooKey("CDECC"))
             .description("Checks duplicate exceptions, git submodules, xlf files, permissions, rst")
+            .pluginConfigurations(this.getDefaultJobPluginConfiguration())
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
@@ -124,7 +211,8 @@ abstract public class AbstractCoreSpec {
                         this.getScriptTaskBashInlineBody() +
                         "./typo3/sysext/core/Build/Scripts/xlfcheck.sh"
                     )
-            );
+            )
+            .cleanWorkingDirectory(true);
     }
 
     /**
@@ -136,6 +224,7 @@ abstract public class AbstractCoreSpec {
     protected Job getJobLintPhp(Requirement requirement, String requirementIdentifier) {
         return new Job("Lint " + requirementIdentifier, new BambooKey("L" + requirementIdentifier))
             .description("Run php -l on source files for linting " + requirementIdentifier)
+            .pluginConfigurations(this.getDefaultJobPluginConfiguration())
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
@@ -149,7 +238,8 @@ abstract public class AbstractCoreSpec {
             )
             .requirements(
                 requirement
-            );
+            )
+            .cleanWorkingDirectory(true);
     }
 
     /**
@@ -161,6 +251,7 @@ abstract public class AbstractCoreSpec {
     protected Job getJobUnitPhp(Requirement requirement, String requirementIdentifier) {
         return new Job("Unit " + requirementIdentifier, new BambooKey("UT" + requirementIdentifier))
             .description("Run unit tests " + requirementIdentifier)
+            .pluginConfigurations(this.getDefaultJobPluginConfiguration())
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
@@ -180,7 +271,8 @@ abstract public class AbstractCoreSpec {
             )
             .requirements(
                 requirement
-            );
+            )
+            .cleanWorkingDirectory(true);
     }
 
     /**
index 31ac58a..0b0ad8b 100644 (file)
@@ -16,19 +16,25 @@ package core;
 import java.util.ArrayList;
 
 import com.atlassian.bamboo.specs.api.BambooSpec;
+import com.atlassian.bamboo.specs.api.builders.AtlassianModule;
 import com.atlassian.bamboo.specs.api.builders.BambooKey;
 import com.atlassian.bamboo.specs.api.builders.Variable;
+import com.atlassian.bamboo.specs.api.builders.notification.AnyNotificationRecipient;
+import com.atlassian.bamboo.specs.api.builders.notification.Notification;
 import com.atlassian.bamboo.specs.api.builders.plan.Job;
 import com.atlassian.bamboo.specs.api.builders.plan.Plan;
 import com.atlassian.bamboo.specs.api.builders.plan.Stage;
 import com.atlassian.bamboo.specs.api.builders.plan.branches.BranchCleanup;
 import com.atlassian.bamboo.specs.api.builders.plan.branches.PlanBranchManagement;
+import com.atlassian.bamboo.specs.api.builders.plan.configuration.AllOtherPluginsConfiguration;
 import com.atlassian.bamboo.specs.api.builders.project.Project;
+import com.atlassian.bamboo.specs.builders.notification.PlanCompletedNotification;
 import com.atlassian.bamboo.specs.builders.task.ScriptTask;
 import com.atlassian.bamboo.specs.builders.trigger.RemoteTrigger;
 import com.atlassian.bamboo.specs.builders.trigger.RepositoryPollingTrigger;
 import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
 import com.atlassian.bamboo.specs.util.BambooServer;
+import com.atlassian.bamboo.specs.util.MapBuilder;
 
 /**
  * Core 7.6 pre-merge test plan.
@@ -36,6 +42,9 @@ import com.atlassian.bamboo.specs.util.BambooServer;
 @BambooSpec
 public class PreMergeSpec extends AbstractCoreSpec {
 
+    protected static String planName = "Core 7.6 pre-merge";
+    protected static String planKey = "GTC76";
+
     protected int numberOfFunctionalMysqlJobs = 5;
 
     /**
@@ -43,16 +52,16 @@ public class PreMergeSpec extends AbstractCoreSpec {
      */
     public static void main(final String[] args) throws Exception {
         // By default credentials are read from the '.credentials' file.
-        BambooServer bambooServer = new BambooServer("https://bamboo.typo3.com:443");
-        Plan plan = new PreMergeSpec().createPlan();
-        bambooServer.publish(plan);
+        BambooServer bambooServer = new BambooServer(bambooServerName);
+        bambooServer.publish(new PreMergeSpec().createPlan());
+        bambooServer.publish(new PreMergeSpec().getDefaultPlanPermissions(projectKey, planKey));
     }
 
     /**
      * Core 7.6 pre-merge plan is in "TYPO3 core" project of bamboo
      */
     Project project() {
-        return new Project().name("TYPO3 Core").key("CORE");
+        return new Project().name(projectName).key(projectKey);
     }
 
     /**
@@ -69,7 +78,6 @@ public class PreMergeSpec extends AbstractCoreSpec {
         Stage stagePreparation = new Stage("Preparation")
             .jobs(jobsPreparationStage.toArray(new Job[jobsPreparationStage.size()]));
 
-
         // MAIN stage
         ArrayList<Job> jobsMainStage = new ArrayList<Job>();
 
@@ -93,10 +101,10 @@ public class PreMergeSpec extends AbstractCoreSpec {
         Stage stageMainStage = new Stage("Main stage")
             .jobs(jobsMainStage.toArray(new Job[jobsMainStage.size()]));
 
-
         // Compile plan
-        return new Plan(project(), "Core 7.6 pre-merge", "GTC76")
+        return new Plan(project(), planName, planKey)
             .description("Execute TYPO3 core 7.6 pre-merge tests. Auto generated! See Build/bamboo of core git repository.")
+            .pluginConfigurations(this.getDefaultPlanPluginConfiguration())
             .stages(
                 stagePreparation,
                 stageMainStage
@@ -117,7 +125,13 @@ public class PreMergeSpec extends AbstractCoreSpec {
                 new PlanBranchManagement()
                     .delete(new BranchCleanup())
                     .notificationForCommitters()
-            );
+            )
+            .notifications(new Notification()
+                .type(new PlanCompletedNotification())
+                .recipients(new AnyNotificationRecipient(new AtlassianModule("com.atlassian.bamboo.plugins.bamboo-slack:recipient.slack"))
+                    .recipientString("https://intercept.typo3.com/index.php")
+                )
+        );
     }
 
     /**
@@ -126,10 +140,33 @@ public class PreMergeSpec extends AbstractCoreSpec {
     protected Job getJobBuildLabels() {
         return new Job("Create build labels", new BambooKey("CLFB"))
             .description("Create changeId and patch set labels from variable access and parsing result of a dummy task")
+            .pluginConfigurations(new AllOtherPluginsConfiguration()
+                .configuration(new MapBuilder()
+                    .put("repositoryDefiningWorkingDirectory", -1)
+                    .put("custom", new MapBuilder()
+                        .put("auto", new MapBuilder()
+                            .put("regex", "https:\\/\\/review\\.typo3\\.org\\/(#\\/c\\/)?(\\d+)")
+                            .put("label", "change-\\2, patchset-${bamboo.patchset}")
+                            .build()
+                        )
+                        .put("buildHangingConfig.enabled", "false")
+                        .put("ncover.path", "")
+                        .put("clover", new MapBuilder()
+                            .put("path", "")
+                            .put("license", "")
+                            .put("useLocalLicenseKey", "true")
+                            .build()
+                        )
+                        .build()
+                    )
+                    .build()
+                )
+            )
             .tasks(
                 new ScriptTask()
                     .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
                     .inlineBody("echo \"I'm just here for the labels!\"")
-            );
+            )
+            .cleanWorkingDirectory(true);
     }
 }