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-26 20:22:25 +01:00
|
|
|
$arcrc_content = exec("cat ~/.arcrc | gzip -f | base64 -w0");
|
2016-01-20 00:33:20 +01:00
|
|
|
|
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",
|
2016-01-26 20:22:25 +01:00
|
|
|
"shell" => "echo " . $arcrc_content . " | base64 --decode"
|
|
|
|
. " | gzip -d > ~/.arcrc",
|
2016-01-20 00:33:20 +01:00
|
|
|
"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") . ";"
|
2016-04-12 19:37:58 +02:00
|
|
|
. "./build_tools/precommit_checker.py " . $test
|
|
|
|
. "; exit_code=$?; ([[ \$exit_code -eq 0 ]] &&"
|
2016-01-21 22:06:14 +01:00
|
|
|
. $this->updateTestCommand($diffID, $test, "pass") . ")"
|
2016-04-12 19:37:58 +02:00
|
|
|
. "||" . $this->updateTestCommand($diffID, $test, "fail")
|
2016-01-21 22:06:14 +01:00
|
|
|
. "; cat /tmp/precommit-check.log"
|
2016-04-12 19:37:58 +02:00
|
|
|
. "; for f in `ls t/log-*`; do echo \$f; cat \$f; done;"
|
|
|
|
. "[[ \$exit_code -eq 0 ]]";
|
2016-01-21 22:06:14 +01:00
|
|
|
|
|
|
|
$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-26 20:22:25 +01:00
|
|
|
if (strcmp(getenv("ROCKSDB_CHECK_ALL"), 1) == 0) {
|
|
|
|
// extract all tests from the CI definition
|
|
|
|
$output = file_get_contents("build_tools/rocksdb-lego-determinator");
|
|
|
|
preg_match_all('/[ ]{2}([a-zA-Z0-9_]+)[\)]{1}/', $output, $matches);
|
|
|
|
$tests = $matches[1];
|
|
|
|
} else {
|
|
|
|
// manually list of tests we want to run in sandcastle
|
|
|
|
$tests = array(
|
2016-05-06 23:51:20 +02:00
|
|
|
"unit", "unit_481", "clang_unit", "tsan", "asan", "lite_test", "valgrind"
|
2016-01-26 20:22:25 +01:00
|
|
|
);
|
|
|
|
}
|
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-26 20:22:25 +01:00
|
|
|
// Why compress ? Otherwise we run over the max string size.
|
|
|
|
$cmd = "echo " . base64_encode(json_encode($arg))
|
|
|
|
. " | gzip -f | base64 -w0";
|
|
|
|
$arg_encoded = shell_exec($cmd);
|
2016-01-21 22:06:14 +01:00
|
|
|
|
|
|
|
$command = array(
|
|
|
|
"name" => "Run diff " . $diffID . "for user " . $username,
|
|
|
|
"steps" => array()
|
|
|
|
);
|
|
|
|
|
|
|
|
$command["steps"][] = array(
|
|
|
|
"name" => "Generate determinator",
|
2016-01-26 20:22:25 +01:00
|
|
|
"shell" => "echo " . $arg_encoded . " | base64 --decode | gzip -d"
|
|
|
|
. " | base64 --decode",
|
2016-01-21 22:06:14 +01:00
|
|
|
"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");
|
|
|
|
}
|
|
|
|
}
|