2015-04-07 20:56:29 +02:00
|
|
|
<?php
|
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
2015-08-10 22:58:55 +02:00
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
2015-04-07 20:56:29 +02:00
|
|
|
|
|
|
|
class FacebookArcanistConfiguration extends ArcanistConfiguration {
|
|
|
|
|
|
|
|
public function didRunWorkflow($command,
|
|
|
|
ArcanistBaseWorkflow $workflow,
|
|
|
|
$error_code) {
|
|
|
|
if ($command == 'diff' && !$workflow->isRawDiffSource()) {
|
2016-01-20 00:33:20 +01:00
|
|
|
$this->startTestsInJenkins($workflow);
|
|
|
|
$this->startTestsInSandcastle($workflow);
|
2015-04-07 20:56:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 00:33:20 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
/* Run tests in sandcastle */
|
2016-01-21 22:06:14 +01:00
|
|
|
function postURL($diffID, $url) {
|
|
|
|
$cmd = 'echo \'{"diff_id": "' . $diffID . '", '
|
|
|
|
. '"name":"click here for sandcastle tests for D' . $diffID . '", '
|
|
|
|
. '"link":"' . $url . '"}\' | '
|
|
|
|
. 'http_proxy=fwdproxy.any.facebook.com:8080 '
|
|
|
|
. 'https_proxy=fwdproxy.any.facebook.com:8080 arc call-conduit '
|
|
|
|
. 'differential.updateunitresults';
|
|
|
|
shell_exec($cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateTestCommand($diffID, $test, $status) {
|
|
|
|
$cmd = 'echo \'{"diff_id": "' . $diffID . '", '
|
|
|
|
. '"name":"' . $test . '", '
|
|
|
|
. '"result":"' . $status . '"}\' | '
|
|
|
|
. 'http_proxy=fwdproxy.any.facebook.com:8080 '
|
|
|
|
. 'https_proxy=fwdproxy.any.facebook.com:8080 arc call-conduit '
|
|
|
|
. 'differential.updateunitresults';
|
|
|
|
return $cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateTest($diffID, $test) {
|
|
|
|
shell_exec($this->updateTestCommand($diffID, $test, "waiting"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSteps($diffID, $username, $test) {
|
2016-01-20 00:33:20 +01:00
|
|
|
$arcrc_content = exec("cat ~/.arcrc | base64 -w0");
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// Sandcastle machines don't have arc setup. We copy the user certificate
|
|
|
|
// and authenticate using that in sandcastle
|
2016-01-20 00:33:20 +01:00
|
|
|
$setup = array(
|
|
|
|
"name" => "Setup arcrc",
|
|
|
|
"shell" => "echo " . $arcrc_content . " | base64 --decode > ~/.arcrc",
|
|
|
|
"user" => "root"
|
|
|
|
);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// arc demands certain permission on its config
|
2016-01-20 00:33:20 +01:00
|
|
|
$fix_permission = array(
|
|
|
|
"name" => "Fix environment",
|
|
|
|
"shell" => "chmod 600 ~/.arcrc",
|
|
|
|
"user" => "root"
|
|
|
|
);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// fbcode is a sub-repo. We cannot patch until we add it to ignore otherwise
|
|
|
|
// git thinks it is uncommited change
|
2016-01-20 00:33:20 +01:00
|
|
|
$fix_git_ignore = array(
|
|
|
|
"name" => "Fix git ignore",
|
|
|
|
"shell" => "echo fbcode >> .git/info/exclude",
|
|
|
|
"user" => "root"
|
|
|
|
);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// Patch the code (keep your fingures crossed)
|
2016-01-20 00:33:20 +01:00
|
|
|
$patch = array(
|
|
|
|
"name" => "Patch " . $diffID,
|
|
|
|
"shell" => "HTTPS_PROXY=fwdproxy:8080 arc --arcrc-file ~/.arcrc "
|
2016-01-21 22:06:14 +01:00
|
|
|
. "patch --diff " . $diffID,
|
2016-01-20 00:33:20 +01:00
|
|
|
"user" => "root"
|
|
|
|
);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// Clean up the user arc config we are using
|
2016-01-20 00:33:20 +01:00
|
|
|
$cleanup = array(
|
|
|
|
"name" => "Arc cleanup",
|
|
|
|
"shell" => "rm -f ~/.arcrc",
|
|
|
|
"user" => "root"
|
|
|
|
);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// Construct the steps in the order of execution
|
2016-01-20 00:33:20 +01:00
|
|
|
$steps[] = $setup;
|
|
|
|
$steps[] = $fix_permission;
|
|
|
|
$steps[] = $fix_git_ignore;
|
|
|
|
$steps[] = $patch;
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// Run the actual command
|
2016-01-21 22:06:14 +01:00
|
|
|
$this->updateTest($diffID, $test);
|
|
|
|
$cmd = $this->updateTestCommand($diffID, $test, "running") . ";"
|
|
|
|
. "(./build_tools/precommit_checker.py " . $test
|
|
|
|
. "&& "
|
|
|
|
. $this->updateTestCommand($diffID, $test, "pass") . ")"
|
|
|
|
. "|| " . $this->updateTestCommand($diffID, $test, "fail")
|
|
|
|
. "; cat /tmp/precommit-check.log"
|
|
|
|
. "; for f in `ls t/log-*`; do echo \$f; cat \$f; done";
|
|
|
|
|
|
|
|
$run_test = array(
|
|
|
|
"name" => "Run " . $test,
|
|
|
|
"shell" => $cmd,
|
|
|
|
"user" => "root",
|
2016-01-20 00:33:20 +01:00
|
|
|
);
|
|
|
|
|
2016-01-21 22:06:14 +01:00
|
|
|
$steps[] = $run_test;
|
|
|
|
$steps[] = $cleanup;
|
2016-01-20 00:33:20 +01:00
|
|
|
|
|
|
|
return $steps;
|
|
|
|
}
|
|
|
|
|
|
|
|
function startTestsInSandcastle($workflow) {
|
2016-01-23 01:27:48 +01:00
|
|
|
// extract information we need from workflow or CLI
|
2016-01-20 00:33:20 +01:00
|
|
|
$diffID = $workflow->getDiffId();
|
|
|
|
$username = exec("whoami");
|
|
|
|
|
|
|
|
if ($diffID == null || $username == null) {
|
2016-01-23 01:27:48 +01:00
|
|
|
// there is no diff and we can't extract username
|
|
|
|
// we cannot schedule sandcasstle job
|
2016-01-20 00:33:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// list of tests we want to run in sandcastle
|
2016-01-21 22:06:14 +01:00
|
|
|
$tests = array(
|
2016-01-25 22:06:11 +01:00
|
|
|
"unit", "unit_481", "clang_unit", "tsan", "asan", "lite", "valgrind"
|
2016-01-21 22:06:14 +01:00
|
|
|
);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// construct a job definition for each test and add it to the master plan
|
2016-01-21 22:06:14 +01:00
|
|
|
foreach ($tests as $test) {
|
|
|
|
$arg[] = array(
|
|
|
|
"name" => "RocksDB diff " . $diffID . " test " . $test,
|
|
|
|
"steps" => $this->getSteps($diffID, $username, $test)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// we cannot submit the parallel execution master plan to sandcastle
|
|
|
|
// we need supply the job plan as a determinator
|
|
|
|
// so we construct a small job that will spit out the master job plan
|
|
|
|
// which sandcastle will parse and execute
|
2016-01-21 22:06:14 +01:00
|
|
|
$arg_encoded = base64_encode(json_encode($arg));
|
|
|
|
|
|
|
|
$command = array(
|
|
|
|
"name" => "Run diff " . $diffID . "for user " . $username,
|
|
|
|
"steps" => array()
|
|
|
|
);
|
|
|
|
|
|
|
|
$command["steps"][] = array(
|
|
|
|
"name" => "Generate determinator",
|
|
|
|
"shell" => "echo " . $arg_encoded . " | base64 --decode",
|
|
|
|
"determinator" => true,
|
|
|
|
"user" => "root"
|
2016-01-20 00:33:20 +01:00
|
|
|
);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// submit to sandcastle
|
2016-01-20 00:33:20 +01:00
|
|
|
$url = 'https://interngraph.intern.facebook.com/sandcastle/generate?'
|
|
|
|
.'command=SandcastleUniversalCommand'
|
|
|
|
.'&vcs=rocksdb-git&revision=origin%2Fmaster&type=lego'
|
2016-01-21 22:06:14 +01:00
|
|
|
.'&user=krad&alias=rocksdb-precommit'
|
|
|
|
.'&command-args=' . urlencode(json_encode($command));
|
2016-01-20 00:33:20 +01:00
|
|
|
|
|
|
|
$cmd = 'https_proxy= HTTPS_PROXY= curl -s -k -F app=659387027470559 '
|
|
|
|
. '-F token=AeO_3f2Ya3TujjnxGD4 "' . $url . '"';
|
|
|
|
|
|
|
|
$output = shell_exec($cmd);
|
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// extract sandcastle URL from the response
|
2016-01-21 22:06:14 +01:00
|
|
|
preg_match('/url": "(.+)"/', $output, $sandcastle_url);
|
2016-01-20 00:33:20 +01:00
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
echo "\nSandcastle URL: " . $sandcastle_url[1] . "\n";
|
2016-01-21 22:06:14 +01:00
|
|
|
|
2016-01-23 01:27:48 +01:00
|
|
|
// Ask phabricator to display it on the diff UI
|
2016-01-21 22:06:14 +01:00
|
|
|
$this->postURL($diffID, $sandcastle_url[1]);
|
2016-01-20 00:33:20 +01:00
|
|
|
}
|
|
|
|
|
2015-04-07 20:56:29 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
/* Send off builds to jenkins */
|
2016-01-20 00:33:20 +01:00
|
|
|
function startTestsInJenkins($workflow) {
|
2015-04-07 20:56:29 +02:00
|
|
|
$diffID = $workflow->getDiffID();
|
|
|
|
if ($diffID === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = $workflow->getTestResults();
|
|
|
|
if (!$results) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$url = "https://ci-builds.fb.com/view/rocksdb/job/rocksdb_diff_check/"
|
|
|
|
."buildWithParameters?token=AUTH&DIFF_ID=$diffID";
|
|
|
|
system("curl --noproxy '*' \"$url\" > /dev/null 2>&1");
|
|
|
|
}
|
|
|
|
}
|