Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php
12256 views
1
<?php
2
3
final class HarbormasterManagementBuildWorkflow
4
extends HarbormasterManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('build')
9
->setExamples('**build** [__options__] __buildable__ --plan __id__')
10
->setSynopsis(pht('Run plan __id__ on __buildable__.'))
11
->setArguments(
12
array(
13
array(
14
'name' => 'plan',
15
'param' => 'id',
16
'help' => pht('ID of build plan to run.'),
17
),
18
array(
19
'name' => 'background',
20
'help' => pht(
21
'Submit builds into the build queue normally instead of '.
22
'running them in the foreground.'),
23
),
24
array(
25
'name' => 'buildable',
26
'wildcard' => true,
27
),
28
));
29
}
30
31
public function execute(PhutilArgumentParser $args) {
32
$viewer = $this->getViewer();
33
34
$names = $args->getArg('buildable');
35
if (count($names) != 1) {
36
throw new PhutilArgumentUsageException(
37
pht('Specify exactly one buildable object, by object name.'));
38
}
39
40
$name = head($names);
41
42
$buildable = id(new PhabricatorObjectQuery())
43
->setViewer($viewer)
44
->withNames($names)
45
->executeOne();
46
if (!$buildable) {
47
throw new PhutilArgumentUsageException(
48
pht('No such buildable "%s"!', $name));
49
}
50
51
if (!($buildable instanceof HarbormasterBuildableInterface)) {
52
throw new PhutilArgumentUsageException(
53
pht('Object "%s" is not a buildable!', $name));
54
}
55
56
$plan_id = $args->getArg('plan');
57
if (!$plan_id) {
58
throw new PhutilArgumentUsageException(
59
pht(
60
'Use %s to specify a build plan to run.',
61
'--plan'));
62
}
63
64
$plan = id(new HarbormasterBuildPlanQuery())
65
->setViewer($viewer)
66
->withIDs(array($plan_id))
67
->executeOne();
68
if (!$plan) {
69
throw new PhutilArgumentUsageException(
70
pht('Build plan "%s" does not exist.', $plan_id));
71
}
72
73
if (!$plan->canRunManually()) {
74
throw new PhutilArgumentUsageException(
75
pht('This build plan can not be run manually.'));
76
}
77
78
$console = PhutilConsole::getConsole();
79
80
$buildable = HarbormasterBuildable::initializeNewBuildable($viewer)
81
->setIsManualBuildable(true)
82
->setBuildablePHID($buildable->getHarbormasterBuildablePHID())
83
->setContainerPHID($buildable->getHarbormasterContainerPHID())
84
->save();
85
86
$buildable->sendMessage(
87
$viewer,
88
HarbormasterMessageType::BUILDABLE_BUILD,
89
false);
90
91
$console->writeOut(
92
"%s\n",
93
pht(
94
'Applying plan %s to new buildable %s...',
95
$plan->getID(),
96
'B'.$buildable->getID()));
97
98
$console->writeOut(
99
"\n %s\n\n",
100
PhabricatorEnv::getProductionURI('/B'.$buildable->getID()));
101
102
if (!$args->getArg('background')) {
103
PhabricatorWorker::setRunAllTasksInProcess(true);
104
}
105
106
if ($viewer->isOmnipotent()) {
107
$initiator = id(new PhabricatorHarbormasterApplication())->getPHID();
108
} else {
109
$initiator = $viewer->getPHID();
110
}
111
$buildable->applyPlan($plan, array(), $initiator);
112
113
$console->writeOut("%s\n", pht('Done.'));
114
115
return 0;
116
}
117
118
}
119
120