@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 HarbormasterDrydockCommandBuildStepImplementation
4 extends HarbormasterBuildStepImplementation {
5
6 public function getName() {
7 return pht('Drydock: Run Command');
8 }
9
10 public function getGenericDescription() {
11 return pht('Run a command on Drydock resource.');
12 }
13
14 public function getBuildStepGroupKey() {
15 return HarbormasterDrydockBuildStepGroup::GROUPKEY;
16 }
17
18 public function getDescription() {
19 return pht(
20 'Run command %s on %s.',
21 $this->formatSettingForDescription('command'),
22 $this->formatSettingForDescription('artifact'));
23 }
24
25 public function execute(
26 HarbormasterBuild $build,
27 HarbormasterBuildTarget $build_target) {
28 $viewer = PhabricatorUser::getOmnipotentUser();
29
30 $settings = $this->getSettings();
31 $variables = $build_target->getVariables();
32
33 $artifact = $build_target->loadArtifact($settings['artifact']);
34 $impl = $artifact->getArtifactImplementation();
35 $lease = $impl->loadArtifactLease($viewer);
36
37 // TODO: Require active lease.
38
39 $command = $this->mergeVariables(
40 'vcsprintf',
41 $settings['command'],
42 $variables);
43
44 $interface = $lease->getInterface(DrydockCommandInterface::INTERFACE_TYPE);
45
46 $exec_future = $interface->getExecFuture('%C', $command);
47
48 $harbor_future = id(new HarbormasterExecFuture())
49 ->setFuture($exec_future)
50 ->setLogs(
51 $build_target->newLog('remote', 'stdout'),
52 $build_target->newLog('remote', 'stderr'));
53
54 $this->resolveFutures(
55 $build,
56 $build_target,
57 array($harbor_future));
58
59 list($err) = $harbor_future->resolve();
60 if ($err) {
61 throw new HarbormasterBuildFailureException();
62 }
63 }
64
65 public function getArtifactInputs() {
66 return array(
67 array(
68 'name' => pht('Drydock Lease'),
69 'key' => $this->getSetting('artifact'),
70 'type' => HarbormasterWorkingCopyArtifact::ARTIFACTCONST,
71 ),
72 );
73 }
74
75 public function getFieldSpecifications() {
76 return array(
77 'command' => array(
78 'name' => pht('Command'),
79 'type' => 'text',
80 'required' => true,
81 ),
82 'artifact' => array(
83 'name' => pht('Drydock Lease'),
84 'type' => 'text',
85 'required' => true,
86 ),
87 );
88 }
89
90}