Page MenuHomePhabricator

D7499.id16906.diff

D7499.id16906.diff

diff --git a/resources/sql/patches/20131105.buildstep.sql b/resources/sql/patches/20131105.buildstep.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/patches/20131105.buildstep.sql
@@ -0,0 +1,10 @@
+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,
+ 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
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -91,6 +91,7 @@
'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',
@@ -2192,6 +2193,7 @@
'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',
),
@@ -2866,7 +2868,11 @@
'HarbormasterBuildPlanTransactionComment' => 'PhabricatorApplicationTransactionComment',
'HarbormasterBuildPlanTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'HarbormasterBuildQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
- 'HarbormasterBuildStep' => 'HarbormasterDAO',
+ 'HarbormasterBuildStep' =>
+ array(
+ 0 => 'HarbormasterDAO',
+ 1 => 'PhabricatorPolicyInterface',
+ ),
'HarbormasterBuildStepQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'HarbormasterBuildTarget' => 'HarbormasterDAO',
'HarbormasterBuildTargetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
@@ -4647,6 +4653,7 @@
'ReleephStatusFieldSpecification' => 'ReleephFieldSpecification',
'ReleephSummaryFieldSpecification' => 'ReleephFieldSpecification',
'ReleephUserView' => 'AphrontView',
+ 'SleepBuildStepImplementation' => 'BuildStepImplementation',
'SlowvoteEmbedView' => 'AphrontView',
'SlowvoteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
),
diff --git a/src/applications/harbormaster/daemon/PhabricatorHarbormasterBuildDaemon.php b/src/applications/harbormaster/daemon/PhabricatorHarbormasterBuildDaemon.php
--- a/src/applications/harbormaster/daemon/PhabricatorHarbormasterBuildDaemon.php
+++ b/src/applications/harbormaster/daemon/PhabricatorHarbormasterBuildDaemon.php
@@ -29,11 +29,25 @@
$buildable = $build->getBuildable();
$plan = $build->getBuildPlan();
- // TODO: Do the actual build here.
- $this->sleep(15);
+ $steps = id(new HarbormasterBuildStepQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withBuildPlanPHIDs(array($plan->getPHID()))
+ ->execute();
+
+ // 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 passed.
- $build->setBuildStatus(HarbormasterBuild::STATUS_PASSED);
+ // 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/applications/harbormaster/query/HarbormasterBuildStepQuery.php b/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php
--- a/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php
+++ b/src/applications/harbormaster/query/HarbormasterBuildStepQuery.php
@@ -5,6 +5,7 @@
private $ids;
private $phids;
+ private $buildPlanPHIDs;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -16,6 +17,11 @@
return $this;
}
+ public function withBuildPlanPHIDs(array $phids) {
+ $this->buildPlanPHIDs = $phids;
+ return $this;
+ }
+
protected function loadPage() {
$table = new HarbormasterBuildStep();
$conn_r = $table->establishConnection('r');
@@ -48,6 +54,13 @@
$this->phids);
}
+ if ($this->buildPlanPHIDs) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'buildPlanPHID in (%Ls)',
+ $this->buildPlanPHIDs);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
diff --git a/src/applications/harbormaster/step/BuildStepImplementation.php b/src/applications/harbormaster/step/BuildStepImplementation.php
new file mode 100644
--- /dev/null
+++ b/src/applications/harbormaster/step/BuildStepImplementation.php
@@ -0,0 +1,48 @@
+<?php
+
+abstract class BuildStepImplementation {
+
+ private $settings;
+
+ /**
+ * The name of the implementation.
+ */
+ abstract public function getName();
+
+ /**
+ * The description of the implementation.
+ */
+ public function getDescription() {
+ return '';
+ }
+
+ /**
+ * Run the build step against the specified build.
+ */
+ abstract public function execute(HarbormasterBuild $build);
+
+ /**
+ * Gets the settings for this build step.
+ */
+ protected function getSettings() {
+ return $this->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
--- /dev/null
+++ b/src/applications/harbormaster/step/SleepBuildStepImplementation.php
@@ -0,0 +1,24 @@
+<?php
+
+final class SleepBuildStepImplementation extends BuildStepImplementation {
+
+ public function getName() {
+ return pht('Sleep');
+ }
+
+ public function getDescription() {
+ return pht('Sleep for a specified number of seconds.');
+ }
+
+ public function execute(HarbormasterBuild $build) {
+ $settings = $this->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
--- a/src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php
+++ b/src/applications/harbormaster/storage/configuration/HarbormasterBuildStep.php
@@ -1,14 +1,20 @@
<?php
-final class HarbormasterBuildStep extends HarbormasterDAO {
+final class HarbormasterBuildStep extends HarbormasterDAO
+ implements PhabricatorPolicyInterface {
protected $buildPlanPHID;
+ protected $className;
+ protected $details = array();
private $buildPlan = self::ATTACHABLE;
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
+ self::CONFIG_SERIALIZATION => array(
+ 'details' => self::SERIALIZATION_JSON,
+ )
) + parent::getConfiguration();
}
@@ -26,4 +32,50 @@
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 = new $class();
+ if ($implementation === null) {
+ throw new Exception("Unable to create implementation.");
+ }
+ $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 false;
+ }
+
+ public function describeAutomaticCapability($capability) {
+ return null;
+ }
}
diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
--- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
+++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
@@ -1720,6 +1720,10 @@
'type' => 'sql',
'name' => $this->getPatchPath('20131031.vcspassword.sql'),
),
+ '20131105.buildstep.sql' => array(
+ 'type' => 'sql',
+ 'name' => $this->getPatchPath('20131105.buildstep.sql'),
+ ),
);
}
}

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/3j/dk/yhvdsmakzyx7rhtu
Default Alt Text
D7499.id16906.diff (10 KB)

Event Timeline