From f97df9ebea90a240e66efa0ad7ac49c3de57086a Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 28 Feb 2019 13:19:21 -0800 Subject: [PATCH] Implement Build Plan behavior "Affects Buildable" Summary: Ref T13258. Make the "Affects Buildable" option actually work. Test Plan: - As in previous change, created a "wait for HTTP request" build plan and had it always run against every revision. - Created revisions, waited a bit, then sent the build a "Fail" message, with different values of "Affects Buildable": - "Always": Same behavior as today. Buildable waited for the build, then failed when it failed. - "While Building": Buildable waited for the build, but passed even though it failed (buildable has green checkmark even though build is red): {F6250359} - "Never": Buildable passed immediately (buildable has green checkmark even though build is still running): {F6250360} Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13258 Differential Revision: https://secure.phabricator.com/D20233 --- .../engine/HarbormasterBuildEngine.php | 24 +++++++++++++++++++ .../plan/HarbormasterBuildPlanBehavior.php | 13 ++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php index 170e4c8a5c..447bd53704 100644 --- a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php +++ b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php @@ -497,9 +497,33 @@ final class HarbormasterBuildEngine extends Phobject { // passed everything it needs to. if (!$buildable->isPreparing()) { + $behavior_key = HarbormasterBuildPlanBehavior::BEHAVIOR_BUILDABLE; + $behavior = HarbormasterBuildPlanBehavior::getBehavior($behavior_key); + + $key_never = HarbormasterBuildPlanBehavior::BUILDABLE_NEVER; + $key_building = HarbormasterBuildPlanBehavior::BUILDABLE_IF_BUILDING; + $all_pass = true; $any_fail = false; foreach ($buildable->getBuilds() as $build) { + $plan = $build->getBuildPlan(); + $option = $behavior->getPlanOption($plan); + $option_key = $option->getKey(); + + $is_never = ($option_key === $key_never); + $is_building = ($option_key === $key_building); + + // If this build "Never" affects the buildable, ignore it. + if ($is_never) { + continue; + } + + // If this build affects the buildable "If Building", but is already + // complete, ignore it. + if ($is_building && $build->isComplete()) { + continue; + } + if (!$build->isPassed()) { $all_pass = false; } diff --git a/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php b/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php index 63fc263fcb..690619f56e 100644 --- a/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php +++ b/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php @@ -22,6 +22,11 @@ final class HarbormasterBuildPlanBehavior const DRAFTS_IF_BUILDING = 'building'; const DRAFTS_NEVER = 'never'; + const BEHAVIOR_BUILDABLE = 'buildable'; + const BUILDABLE_ALWAYS = 'always'; + const BUILDABLE_IF_BUILDING = 'building'; + const BUILDABLE_NEVER = 'never'; + public function setKey($key) { $this->key = $key; return $this; @@ -207,7 +212,7 @@ final class HarbormasterBuildPlanBehavior $aggregate_options = array( id(new HarbormasterBuildPlanBehaviorOption()) - ->setKey('always') + ->setKey(self::BUILDABLE_ALWAYS) ->setIcon('fa-check-circle-o green') ->setName(pht('Always')) ->setIsDefault(true) @@ -216,7 +221,7 @@ final class HarbormasterBuildPlanBehavior 'The buildable waits for the build, and fails if the '. 'build fails.')), id(new HarbormasterBuildPlanBehaviorOption()) - ->setKey('building') + ->setKey(self::BUILDABLE_IF_BUILDING) ->setIcon('fa-pause-circle-o yellow') ->setName(pht('If Building')) ->setDescription( @@ -224,7 +229,7 @@ final class HarbormasterBuildPlanBehavior 'The buildable waits for the build, but does not fail '. 'if the build fails.')), id(new HarbormasterBuildPlanBehaviorOption()) - ->setKey('never') + ->setKey(self::BUILDABLE_NEVER) ->setIcon('fa-circle-o red') ->setName(pht('Never')) ->setDescription( @@ -310,7 +315,7 @@ final class HarbormasterBuildPlanBehavior 'this warning and continue, even if builds have failed.')) ->setOptions($land_options), id(new self()) - ->setKey('buildable') + ->setKey(self::BEHAVIOR_BUILDABLE) ->setEditInstructions( pht( 'The overall state of a buildable (like a commit or revision) is '.