From d3abb6557252a5bfb820f8a9465c26c5fb472e95 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 29 Sep 2015 09:51:51 -0700 Subject: [PATCH] Add a --target flag to `arc unit` for uploading results Summary: Ref T5821. Basic idea here is that Harbormaster can run `arc unit --everything --target ...` to get a build target updated. Test Plan: Ran `arc unit --target ...`, saw web UI update with test results. Reviewers: chad Reviewed By: chad Maniphest Tasks: T5821 Differential Revision: https://secure.phabricator.com/D14190 --- src/workflow/ArcanistDiffWorkflow.php | 29 +------------ src/workflow/ArcanistUnitWorkflow.php | 62 +++++++++++++++++++++++++++ src/workflow/ArcanistWorkflow.php | 19 ++++++++ 3 files changed, 82 insertions(+), 28 deletions(-) diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 3074c166..eeabfdfb 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -2753,15 +2753,7 @@ EOTEXT $unit[$key] = $this->getModernUnitDictionary($message); } - switch ($unit_result) { - case ArcanistUnitWorkflow::RESULT_OKAY: - case ArcanistUnitWorkflow::RESULT_SKIP: - $type = 'pass'; - break; - default: - $type = 'fail'; - break; - } + $type = ArcanistUnitWorkflow::getHarbormasterTypeFromResult($unit_result); $futures[] = $this->getConduit()->callMethod( 'harbormaster.sendmessage', @@ -2785,23 +2777,4 @@ EOTEXT } } - private function getModernLintDictionary(array $map) { - $map = $this->getModernCommonDictionary($map); - return $map; - } - - private function getModernUnitDictionary(array $map) { - $map = $this->getModernCommonDictionary($map); - return $map; - } - - private function getModernCommonDictionary(array $map) { - foreach ($map as $key => $value) { - if ($value === null) { - unset($map[$key]); - } - } - return $map; - } - } diff --git a/src/workflow/ArcanistUnitWorkflow.php b/src/workflow/ArcanistUnitWorkflow.php index 1fcee32a..04d8c8e0 100644 --- a/src/workflow/ArcanistUnitWorkflow.php +++ b/src/workflow/ArcanistUnitWorkflow.php @@ -84,6 +84,12 @@ EOTEXT 'ugly' => pht('Only one output format allowed'), ), ), + 'target' => array( + 'param' => 'phid', + 'help' => pht( + '(PROTOTYPE) Record a copy of the test results on the specified '. + 'Harbormaster build target.'), + ), 'everything' => array( 'help' => pht('Run every test.'), 'conflicts' => array( @@ -107,6 +113,14 @@ EOTEXT return true; } + public function requiresConduit() { + return $this->shouldUploadResults(); + } + + public function requiresAuthentication() { + return $this->shouldUploadResults(); + } + public function getEngine() { return $this->engine; } @@ -263,6 +277,12 @@ EOTEXT break; } + + $target_phid = $this->getArgument('target'); + if ($target_phid) { + $this->uploadTestResults($target_phid, $overall_result, $results); + } + return $overall_result; } @@ -370,4 +390,46 @@ EOTEXT } + public static function getHarbormasterTypeFromResult($unit_result) { + switch ($unit_result) { + case self::RESULT_OKAY: + case self::RESULT_SKIP: + $type = 'pass'; + break; + default: + $type = 'fail'; + break; + } + + return $type; + } + + private function shouldUploadResults() { + return ($this->getArgument('target') !== null); + } + + private function uploadTestResults( + $target_phid, + $unit_result, + array $unit) { + + // TODO: It would eventually be nice to stream test results up to the + // server as we go, but just get things working for now. + + $message_type = self::getHarbormasterTypeFromResult($unit_result); + + foreach ($unit as $key => $result) { + $dictionary = $result->toDictionary(); + $unit[$key] = $this->getModernUnitDictionary($dictionary); + } + + $this->getConduit()->callMethodSynchronous( + 'harbormaster.sendmessage', + array( + 'buildTargetPHID' => $target_phid, + 'unit' => array_values($unit), + 'type' => $message_type, + )); + } + } diff --git a/src/workflow/ArcanistWorkflow.php b/src/workflow/ArcanistWorkflow.php index 54649103..c07279cc 100644 --- a/src/workflow/ArcanistWorkflow.php +++ b/src/workflow/ArcanistWorkflow.php @@ -2040,5 +2040,24 @@ abstract class ArcanistWorkflow extends Phobject { } } + protected function getModernLintDictionary(array $map) { + $map = $this->getModernCommonDictionary($map); + return $map; + } + + protected function getModernUnitDictionary(array $map) { + $map = $this->getModernCommonDictionary($map); + return $map; + } + + private function getModernCommonDictionary(array $map) { + foreach ($map as $key => $value) { + if ($value === null) { + unset($map[$key]); + } + } + return $map; + } + } -- 2.43.0