Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistTryWorkflow.php
- This file was added.
| <?php | |||||
| /** | |||||
| * Pushes the current HEAD to a staging repository for a test build. | |||||
| * | |||||
| * @concrete-extensible | |||||
| */ | |||||
| class ArcanistTryWorkflow extends ArcanistWorkflow { | |||||
| private $branches; | |||||
| public function getWorkflowName() { | |||||
| return 'try'; | |||||
| } | |||||
| public function getCommandSynopses() { | |||||
| return phutil_console_format(<<<EOTEXT | |||||
| **try** [__options__] | |||||
| EOTEXT | |||||
| ); | |||||
| } | |||||
| public function getCommandHelp() { | |||||
| return phutil_console_format(<<<EOTEXT | |||||
| Supports: git | |||||
| Runs a build on the Phabricator server using the current HEAD of | |||||
| this repository, without creating a revision. | |||||
| EOTEXT | |||||
| ); | |||||
| } | |||||
| public function requiresConduit() { | |||||
| return true; | |||||
| } | |||||
| public function requiresAuthentication() { | |||||
| return true; | |||||
| } | |||||
| public function requiresRepositoryAPI() { | |||||
| return true; | |||||
| } | |||||
| public function getArguments() { | |||||
| return array(); | |||||
| } | |||||
| public function getSupportedRevisionControlSystems() { | |||||
| return array('git'); | |||||
| } | |||||
| public function run() { | |||||
| $conduit = $this->getConduit(); | |||||
| $api = $this->getRepositoryAPI(); | |||||
| $staging = $this->getRepositoryStaging(); | |||||
| if ($staging == null || !idx($staging, 'supported', false)) { | |||||
| throw new ArcanistUsageException(pht( | |||||
| 'This project does not have a staging repository.')); | |||||
| } | |||||
| $build_plan_id = $this->getConfigFromAnySource('try.buildplanid'); | |||||
| if ($build_plan_id === null) { | |||||
| throw new ArcanistUsageException(pht( | |||||
| 'No build plan ID configured for project; set '. | |||||
| '\'try.buildplanid\' in .arcconfig first.')); | |||||
| } | |||||
| $uri = idx($staging, 'uri'); | |||||
| echo pht("Pushing HEAD to staging repository...\n"); | |||||
| $api->execxLocal( | |||||
| 'push -f %s HEAD:temporary-%s', | |||||
| $uri, | |||||
| Filesystem::readRandomCharacters(20)); | |||||
| list($commit_ref, $stderr) = $api->execxLocal('rev-parse HEAD'); | |||||
| echo pht( | |||||
| "Scheduling build plan %d on %s...\n", | |||||
| $build_plan_id, | |||||
| trim($commit_ref)); | |||||
| $url = null; | |||||
| while (true) { | |||||
| try { | |||||
| $url = $conduit->callMethodSynchronous( | |||||
| 'harbormaster.startmanualbuild', | |||||
| array( | |||||
| 'commitIdentifier' => trim($commit_ref), | |||||
| 'buildPlanID' => $build_plan_id, | |||||
| )); | |||||
| break; | |||||
| } catch (ConduitClientException $ex) { | |||||
| if (substr_count($ex->getMessage(), 'No such commit!') > 0) { | |||||
| echo pht("Commit not yet parsed (waiting 5 seconds)...\n"); | |||||
| sleep(5); | |||||
| } | |||||
| } | |||||
| } | |||||
| echo pht("Build started at %s\n", $url); | |||||
| return 0; | |||||
| } | |||||
| } | |||||