diff --git a/resources/sql/patches/20131105.buildstep.sql b/resources/sql/patches/20131105.buildstep.sql new file mode 100644 index 0000000000..714e9a3088 --- /dev/null +++ b/resources/sql/patches/20131105.buildstep.sql @@ -0,0 +1,11 @@ +CREATE TABLE {$NAMESPACE}_harbormaster.harbormaster_buildstep ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + phid VARCHAR(64) NOT NULL COLLATE utf8_bin, + buildPlanPHID VARCHAR(64) NOT NULL COLLATE utf8_bin, + className VARCHAR(255) NOT NULL COLLATE utf8_bin, + details LONGTEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + KEY `key_plan` (buildPlanPHID), + UNIQUE KEY `key_phid` (phid) +) ENGINE=InnoDB, COLLATE utf8_general_ci; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 174be1b6cd..3716d1ba9e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -91,6 +91,7 @@ phutil_register_library_map(array( 'AphrontView' => 'view/AphrontView.php', 'AphrontWebpageResponse' => 'aphront/response/AphrontWebpageResponse.php', 'AuditActionMenuEventListener' => 'applications/audit/events/AuditActionMenuEventListener.php', + 'BuildStepImplementation' => 'applications/harbormaster/step/BuildStepImplementation.php', 'CelerityAPI' => 'infrastructure/celerity/CelerityAPI.php', 'CelerityPhabricatorResourceController' => 'infrastructure/celerity/CelerityPhabricatorResourceController.php', 'CelerityResourceController' => 'infrastructure/celerity/CelerityResourceController.php', @@ -2195,6 +2196,7 @@ phutil_register_library_map(array( 'ReleephStatusFieldSpecification' => 'applications/releeph/field/specification/ReleephStatusFieldSpecification.php', 'ReleephSummaryFieldSpecification' => 'applications/releeph/field/specification/ReleephSummaryFieldSpecification.php', 'ReleephUserView' => 'applications/releeph/view/user/ReleephUserView.php', + 'SleepBuildStepImplementation' => 'applications/harbormaster/step/SleepBuildStepImplementation.php', 'SlowvoteEmbedView' => 'applications/slowvote/view/SlowvoteEmbedView.php', 'SlowvoteRemarkupRule' => 'applications/slowvote/remarkup/SlowvoteRemarkupRule.php', ), @@ -2872,7 +2874,11 @@ phutil_register_library_map(array( 'HarbormasterBuildPlanTransactionComment' => 'PhabricatorApplicationTransactionComment', 'HarbormasterBuildPlanTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'HarbormasterBuildQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', - 'HarbormasterBuildStep' => 'HarbormasterDAO', + 'HarbormasterBuildStep' => + array( + 0 => 'HarbormasterDAO', + 1 => 'PhabricatorPolicyInterface', + ), 'HarbormasterBuildStepQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'HarbormasterBuildTarget' => 'HarbormasterDAO', 'HarbormasterBuildTargetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', @@ -4651,6 +4657,7 @@ phutil_register_library_map(array( 'ReleephStatusFieldSpecification' => 'ReleephFieldSpecification', 'ReleephSummaryFieldSpecification' => 'ReleephFieldSpecification', 'ReleephUserView' => 'AphrontView', + 'SleepBuildStepImplementation' => 'BuildStepImplementation', 'SlowvoteEmbedView' => 'AphrontView', 'SlowvoteRemarkupRule' => 'PhabricatorRemarkupRuleObject', ), diff --git a/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php b/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php index 9a94be6e2b..61190b3285 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php @@ -5,6 +5,7 @@ final class HarbormasterBuildStepQuery private $ids; private $phids; + private $buildPlanPHIDs; public function withIDs(array $ids) { $this->ids = $ids; @@ -16,6 +17,11 @@ final class HarbormasterBuildStepQuery return $this; } + public function withBuildPlanPHIDs(array $phids) { + $this->buildPlanPHIDs = $phids; + return $this; + } + protected function loadPage() { $table = new HarbormasterBuildStep(); $conn_r = $table->establishConnection('r'); @@ -48,11 +54,43 @@ final class HarbormasterBuildStepQuery $this->phids); } + if ($this->buildPlanPHIDs) { + $where[] = qsprintf( + $conn_r, + 'buildPlanPHID in (%Ls)', + $this->buildPlanPHIDs); + } + $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); } + protected function willFilterPage(array $page) { + $plans = array(); + + $buildplan_phids = array_filter(mpull($page, 'getBuildPlanPHID')); + if ($buildplan_phids) { + $plans = id(new PhabricatorObjectQuery()) + ->setViewer($this->getViewer()) + ->withPHIDs($buildplan_phids) + ->setParentQuery($this) + ->execute(); + $plans = mpull($plans, null, 'getPHID'); + } + + foreach ($page as $key => $build) { + $buildable_phid = $build->getBuildPlanPHID(); + if (empty($plans[$buildable_phid])) { + unset($page[$key]); + continue; + } + $build->attachBuildPlan($plans[$buildable_phid]); + } + + return $page; + } + public function getQueryApplicationClass() { return 'PhabricatorApplicationHarbormaster'; } diff --git a/src/applications/harbormaster/step/BuildStepImplementation.php b/src/applications/harbormaster/step/BuildStepImplementation.php new file mode 100644 index 0000000000..b782496a6f --- /dev/null +++ b/src/applications/harbormaster/step/BuildStepImplementation.php @@ -0,0 +1,48 @@ +settings; + } + + /** + * Loads the settings for this build step implementation from the build step. + */ + public final function loadSettings(HarbormasterBuildStep $build_step) { + $this->settings = array(); + foreach ($this->getSettingDefinitions() as $name => $opt) { + $this->settings[$name] = $build_step->getDetail($name); + } + return $this->settings; + } + + /** + * Return an array of settings for this step implementation. + */ + public function getSettingDefinitions() { + return array(); + } +} diff --git a/src/applications/harbormaster/step/SleepBuildStepImplementation.php b/src/applications/harbormaster/step/SleepBuildStepImplementation.php new file mode 100644 index 0000000000..bf16b22d23 --- /dev/null +++ b/src/applications/harbormaster/step/SleepBuildStepImplementation.php @@ -0,0 +1,24 @@ +getSettings(); + + sleep($settings['seconds']); + } + + public function getSettingDefinitions() { + return array( + 'seconds' => array()); + } + +} diff --git a/src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php b/src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php index 96d3e827d0..42a7e89fa9 100644 --- a/src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php +++ b/src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php @@ -1,14 +1,20 @@ true, + self::CONFIG_SERIALIZATION => array( + 'details' => self::SERIALIZATION_JSON, + ) ) + parent::getConfiguration(); } @@ -26,4 +32,47 @@ final class HarbormasterBuildStep extends HarbormasterDAO { return $this->assertAttached($this->buildPlan); } + public function getDetail($key, $default = null) { + return idx($this->details, $key, $default); + } + + public function setDetail($key, $value) { + $this->details[$key] = $value; + return $this; + } + + public function getStepImplementation() { + if ($this->className === null) { + throw new Exception("No implementation set for the given step."); + } + + // TODO: We should look up the class in phutil's system to ensure + // that it actually extends BuildStepImplementation. + $class = $this->className; + $implementation = newv($class, array()); + $implementation->loadSettings($this); + return $implementation; + } + + +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + + public function getCapabilities() { + return array( + PhabricatorPolicyCapability::CAN_VIEW, + ); + } + + public function getPolicy($capability) { + return $this->getBuildPlan()->getPolicy($capability); + } + + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { + return $this->getBuildPlan()->hasAutomaticCapability($capability, $viewer); + } + + public function describeAutomaticCapability($capability) { + return pht('A build step has the same policies as its build plan.'); + } } diff --git a/src/applications/harbormaster/worker/HarbormasterBuildWorker.php b/src/applications/harbormaster/worker/HarbormasterBuildWorker.php index a9d8ed79e2..347119e348 100644 --- a/src/applications/harbormaster/worker/HarbormasterBuildWorker.php +++ b/src/applications/harbormaster/worker/HarbormasterBuildWorker.php @@ -32,11 +32,25 @@ final class HarbormasterBuildWorker extends PhabricatorWorker { $buildable = $build->getBuildable(); $plan = $build->getBuildPlan(); - // TODO: Do the actual build here. - sleep(15); + $steps = id(new HarbormasterBuildStepQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withBuildPlanPHIDs(array($plan->getPHID())) + ->execute(); - // If we get to here, then the build has passed. - $build->setBuildStatus(HarbormasterBuild::STATUS_PASSED); + // Perform the build. + foreach ($steps as $step) { + $implementation = $step->getStepImplementation(); + $implementation->execute($build); + if ($build->getBuildStatus() !== HarbormasterBuild::STATUS_BUILDING) { + break; + } + } + + // If we get to here, then the build has finished. Set it to passed + // if no build step explicitly set the status. + if ($build->getBuildStatus() === HarbormasterBuild::STATUS_BUILDING) { + $build->setBuildStatus(HarbormasterBuild::STATUS_PASSED); + } $build->save(); } catch (Exception $e) { // If any exception is raised, the build is marked as a failure and diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index f6bb232bd8..04b303273c 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -1720,6 +1720,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('20131031.vcspassword.sql'), ), + '20131105.buildstep.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('20131105.buildstep.sql'), + ), ); } }