3 final class HarbormasterWaitForPreviousBuildStepImplementation
4 extends HarbormasterBuildStepImplementation
{
6 public function getName() {
7 return pht('Wait for Previous Commits to Build');
10 public function getGenericDescription() {
12 'Wait for previous commits to finish building the current plan '.
13 'before continuing.');
16 public function getBuildStepGroupKey() {
17 return HarbormasterControlBuildStepGroup
::GROUPKEY
;
20 public function execute(
21 HarbormasterBuild
$build,
22 HarbormasterBuildTarget
$build_target) {
24 // We can only wait when building against commits.
25 $buildable = $build->getBuildable();
26 $object = $buildable->getBuildableObject();
27 if (!($object instanceof PhabricatorRepositoryCommit
)) {
31 // Block until all previous builds of the same build plan have
33 $plan = $build->getBuildPlan();
34 $blockers = $this->getBlockers($object, $plan, $build);
37 throw new PhabricatorWorkerYieldException(15);
41 private function getBlockers(
42 PhabricatorRepositoryCommit
$commit,
43 HarbormasterBuildPlan
$plan,
44 HarbormasterBuild
$source) {
46 $call = new ConduitCall(
47 'diffusion.commitparentsquery',
49 'commit' => $commit->getCommitIdentifier(),
50 'repository' => $commit->getRepository()->getPHID(),
52 $call->setUser(PhabricatorUser
::getOmnipotentUser());
53 $parents = $call->execute();
55 $parents = id(new DiffusionCommitQuery())
56 ->setViewer(PhabricatorUser
::getOmnipotentUser())
57 ->withRepository($commit->getRepository())
58 ->withIdentifiers($parents)
63 $build_objects = array();
64 foreach ($parents as $parent) {
65 if (!$parent->isImported()) {
66 $blockers[] = pht('Commit %s', $parent->getCommitIdentifier());
68 $build_objects[] = $parent->getPHID();
73 $buildables = id(new HarbormasterBuildableQuery())
74 ->setViewer(PhabricatorUser
::getOmnipotentUser())
75 ->withBuildablePHIDs($build_objects)
76 ->withManualBuildables(false)
78 $buildable_phids = mpull($buildables, 'getPHID');
80 if ($buildable_phids) {
81 $builds = id(new HarbormasterBuildQuery())
82 ->setViewer(PhabricatorUser
::getOmnipotentUser())
83 ->withBuildablePHIDs($buildable_phids)
84 ->withBuildPlanPHIDs(array($plan->getPHID()))
87 foreach ($builds as $build) {
88 if (!$build->isComplete()) {
89 $blockers[] = pht('Build %d', $build->getID());