3 final class HarbormasterManagementBuildWorkflow
4 extends HarbormasterManagementWorkflow
{
6 protected function didConstruct() {
9 ->setExamples('**build** [__options__] __buildable__ --plan __id__')
10 ->setSynopsis(pht('Run plan __id__ on __buildable__.'))
16 'help' => pht('ID of build plan to run.'),
19 'name' => 'background',
21 'Submit builds into the build queue normally instead of '.
22 'running them in the foreground.'),
25 'name' => 'buildable',
31 public function execute(PhutilArgumentParser
$args) {
32 $viewer = $this->getViewer();
34 $names = $args->getArg('buildable');
35 if (count($names) != 1) {
36 throw new PhutilArgumentUsageException(
37 pht('Specify exactly one buildable object, by object name.'));
42 $buildable = id(new PhabricatorObjectQuery())
47 throw new PhutilArgumentUsageException(
48 pht('No such buildable "%s"!', $name));
51 if (!($buildable instanceof HarbormasterBuildableInterface
)) {
52 throw new PhutilArgumentUsageException(
53 pht('Object "%s" is not a buildable!', $name));
56 $plan_id = $args->getArg('plan');
58 throw new PhutilArgumentUsageException(
60 'Use %s to specify a build plan to run.',
64 $plan = id(new HarbormasterBuildPlanQuery())
66 ->withIDs(array($plan_id))
69 throw new PhutilArgumentUsageException(
70 pht('Build plan "%s" does not exist.', $plan_id));
73 if (!$plan->canRunManually()) {
74 throw new PhutilArgumentUsageException(
75 pht('This build plan can not be run manually.'));
78 $console = PhutilConsole
::getConsole();
80 $buildable = HarbormasterBuildable
::initializeNewBuildable($viewer)
81 ->setIsManualBuildable(true)
82 ->setBuildablePHID($buildable->getHarbormasterBuildablePHID())
83 ->setContainerPHID($buildable->getHarbormasterContainerPHID())
86 $buildable->sendMessage(
88 HarbormasterMessageType
::BUILDABLE_BUILD
,
94 'Applying plan %s to new buildable %s...',
96 'B'.$buildable->getID()));
100 PhabricatorEnv
::getProductionURI('/B'.$buildable->getID()));
102 if (!$args->getArg('background')) {
103 PhabricatorWorker
::setRunAllTasksInProcess(true);
106 if ($viewer->isOmnipotent()) {
107 $initiator = id(new PhabricatorHarbormasterApplication())->getPHID();
109 $initiator = $viewer->getPHID();
111 $buildable->applyPlan($plan, array(), $initiator);
113 $console->writeOut("%s\n", pht('Done.'));