Page MenuHomePhabricator
Paste P1132

arc update-diff with results from delayed build - rough draft
ActivePublic

Authored by avivey on May 2 2014, 6:29 PM.
Tags
None
Referenced Files
F149981: arc_update-diff_with_results_from_delayed_build
May 2 2014, 6:29 PM
Subscribers
None
<?php
final class UpdateDiffWorkflow extends ArcanistBaseWorkflow {
private $console;
private static $TEST_FIELDS = array(
'name',
'link',
'result',
'message',
'coverage',
);
public function run() {
$this->console = PhutilConsole::getConsole();
$root = $this->getWorkingCopy()->getProjectRoot() . '/';
$diff_id = $this->getArgument('diff');
if (!$diff_id) {
throw new ArcanistUsageException("diff param required");
}
$this->console->writeOut(
"Updating diff $diff_id/ \n");
$lint_messages = $this->runLint();
$test_results = $this->runUnit();
try {
$this->getConduit()->callMethodSynchronous( // todo async
'differential.finishpostponedlinters',
array('diffID' => $diff_id,
'linters' => array('jenkins' => $lint_messages)));
} catch (Exception $ex) {
$this->console->writeOut(
"Lint reporting failed: " . $ex->getMessage() ."\n");
}
$coverage = magically_obtain_coverage_data(); // TODO
$sampeler = new TestResultsSampeler(); // this object reduces the number of tests, which == number of api calls.
$sampeler->setExtraTestCoverage($coverage);
if ($this->isBuildFailed()) {
$sampeler->setExtraTestStatus(ArcanistUnitTestResult::RESULT_BROKEN);
$sampeler->setExtraTestText("Build Failed! ");
}
$build_uri = getenv('BUILD_URL');
if ($build_uri)
$sampeler->setExtraTestLink($build_uri);
$sampeler_results = $sampeler->sampelize($test_results);
$test_results = $sampeler_results['sampled'];
$extra_test = $sampeler_results['extra test'];
foreach ($test_results as $test) {
$data = $test->toDictionary();
$data = array_select_keys($data, self::$TEST_FIELDS);
$data['diff_id'] = $diff_id;
$this->getConduit()->callMethodSynchronous( // todo async
'differential.updateunitresults',
$data);
}
$data = $extra_test->toDictionary();
$data = array_select_keys($data, self::$TEST_FIELDS);
$data['diff_id'] = $diff_id;
// This deletes the "postponed" value.
$data['file'] = 'Jenkins postponed tests';
$data['message'] = $extra_test->getName();
$data['name'] = 'Jenkins Build';
$this->getConduit()->callMethodSynchronous(
'differential.updateunitresults',
$data);
}
private function isBuildFailed() {
$status = $this->getArgument('build-status', false);
if ($status === false)
// no data
return false;
if ($status == 0)
// build pass
return false;
return true;
}
public function getArguments() {
return array(
'diff' => array(
'param' => 'diff_id',
'help' => 'diff_id to update (not Differential Diff - small diff!)'
),
'build-status' => array(
'param' => 'build_status',
'help' => 'exit code from the build script (Unix style - 0 means "good")'
),
);
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**update-diff** [__options__]
EOTEXT
);
}
public function getCommandHelp() {
return 'Expected to be run by Jenkins, after "mvn test" was executed.';
}
public function requiresWorkingCopy() {
return true;
}
public function requiresConduit() {
return true;
}
public function requiresAuthentication() {
return true;
}
public function requiresRepositoryAPI() {
return true;
}
public function getWorkflowName() {
return 'update-diff';
}
}

Event Timeline

avivey changed the title of this paste from untitled to arc update-diff with results from delayed build.
avivey updated the paste's language from autodetect to php.
avivey changed the title of this paste from arc update-diff with results from delayed build to arc update-diff with results from delayed build - rough draft.