@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HarbormasterWaitForPreviousBuildStepImplementation
4 extends HarbormasterBuildStepImplementation {
5
6 public function getName() {
7 return pht('Wait for Previous Commits to Build');
8 }
9
10 public function getGenericDescription() {
11 return pht(
12 'Wait for previous commits to finish building the current plan '.
13 'before continuing.');
14 }
15
16 public function getBuildStepGroupKey() {
17 return HarbormasterControlBuildStepGroup::GROUPKEY;
18 }
19
20 public function execute(
21 HarbormasterBuild $build,
22 HarbormasterBuildTarget $build_target) {
23
24 // We can only wait when building against commits.
25 $buildable = $build->getBuildable();
26 $object = $buildable->getBuildableObject();
27 if (!($object instanceof PhabricatorRepositoryCommit)) {
28 return;
29 }
30
31 // Block until all previous builds of the same build plan have
32 // finished.
33 $plan = $build->getBuildPlan();
34 $blockers = $this->getBlockers($object, $plan, $build);
35
36 if ($blockers) {
37 throw new PhabricatorWorkerYieldException(15);
38 }
39 }
40
41 private function getBlockers(
42 PhabricatorRepositoryCommit $commit,
43 HarbormasterBuildPlan $plan,
44 HarbormasterBuild $source) {
45
46 $call = new ConduitCall(
47 'diffusion.commitparentsquery',
48 array(
49 'commit' => $commit->getCommitIdentifier(),
50 'repository' => $commit->getRepository()->getPHID(),
51 ));
52 $call->setUser(PhabricatorUser::getOmnipotentUser());
53 $parents = $call->execute();
54
55 $parents = id(new DiffusionCommitQuery())
56 ->setViewer(PhabricatorUser::getOmnipotentUser())
57 ->withRepository($commit->getRepository())
58 ->withIdentifiers($parents)
59 ->execute();
60
61 $blockers = array();
62
63 $build_objects = array();
64 foreach ($parents as $parent) {
65 if (!$parent->isImported()) {
66 $blockers[] = pht('Commit %s', $parent->getCommitIdentifier());
67 } else {
68 $build_objects[] = $parent->getPHID();
69 }
70 }
71
72 if ($build_objects) {
73 $buildables = id(new HarbormasterBuildableQuery())
74 ->setViewer(PhabricatorUser::getOmnipotentUser())
75 ->withBuildablePHIDs($build_objects)
76 ->withManualBuildables(false)
77 ->execute();
78 $buildable_phids = mpull($buildables, 'getPHID');
79
80 if ($buildable_phids) {
81 $builds = id(new HarbormasterBuildQuery())
82 ->setViewer(PhabricatorUser::getOmnipotentUser())
83 ->withBuildablePHIDs($buildable_phids)
84 ->withBuildPlanPHIDs(array($plan->getPHID()))
85 ->execute();
86
87 foreach ($builds as $build) {
88 if (!$build->isComplete()) {
89 $blockers[] = pht('Build %d', $build->getID());
90 }
91 }
92 }
93 }
94
95 return $blockers;
96 }
97
98}