2017-10-29 21:10:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__ . '/config.php';
|
|
|
|
|
|
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
|
|
|
|
|
# define('AMQP_DEBUG', true);
|
|
|
|
$connection = rabbitmq_conn();
|
|
|
|
$channel = $connection->channel();
|
|
|
|
$channel->basic_qos(null, 1, true);
|
|
|
|
|
|
|
|
|
2017-10-31 08:09:41 +00:00
|
|
|
list($queueName, , ) = $channel->queue_declare('mass-rebuild-check-jobs',
|
2017-10-29 21:10:26 +00:00
|
|
|
false, true, false, false);
|
|
|
|
|
|
|
|
echo "hi\n";
|
|
|
|
|
|
|
|
function outrunner($msg) {
|
|
|
|
try {
|
2017-10-31 08:09:41 +00:00
|
|
|
runner($msg);
|
2017-10-29 21:10:26 +00:00
|
|
|
} catch (\GHE\ExecException $e) {
|
2017-11-03 12:34:18 +00:00
|
|
|
// var_dump($msg);
|
2017-10-29 21:10:26 +00:00
|
|
|
var_dump($e->getMessage());
|
|
|
|
var_dump($e->getCode());
|
|
|
|
var_dump($e->getOutput());
|
2017-10-31 08:09:41 +00:00
|
|
|
} catch (\PhpAmqpLib\Exception\AMQPProtocolChannelException $e) {
|
|
|
|
echo "Channel exception:\n";
|
|
|
|
var_dump($e);
|
2017-10-29 21:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function runner($msg) {
|
|
|
|
$in = json_decode($msg->body);
|
|
|
|
|
2017-10-31 08:09:41 +00:00
|
|
|
$client = gh_client();
|
|
|
|
$status = $client->api('pull_request')->show(
|
|
|
|
$in->repo->owner,
|
|
|
|
$in->repo->name,
|
|
|
|
$in->pr->number);
|
|
|
|
if ($status['mergeable'] === false) {
|
|
|
|
echo "github says the PR isn't able to be merged\n";
|
|
|
|
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
2017-10-29 21:10:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-10-31 08:09:41 +00:00
|
|
|
if ($status['state'] !== 'open') {
|
|
|
|
echo "github says the PR isn't open\n";
|
|
|
|
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
2017-10-29 21:10:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-03 12:34:18 +00:00
|
|
|
|
|
|
|
$head_sha = $in->pr->head_sha;
|
|
|
|
|
|
|
|
$ghclient = gh_client();
|
|
|
|
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus = new GHE\CommitStatus($ghclient, $in->repo->owner,
|
|
|
|
$in->repo->name, $head_sha,
|
|
|
|
'grahamcofborg-eval');
|
2017-11-03 12:34:18 +00:00
|
|
|
echo "marking PR as pending\n";
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->pending('GrahamCOfBorg is starting');
|
2017-11-03 12:34:18 +00:00
|
|
|
|
2017-10-31 08:09:41 +00:00
|
|
|
$against_name = "origin/" . $in->pr->target_branch;
|
|
|
|
echo "Building against $against_name\n";
|
|
|
|
$co = new GHE\Checkout(WORKING_DIR, "mr-est");
|
|
|
|
$pname = $co->checkOutRef($in->repo->full_name,
|
|
|
|
$in->repo->clone_url,
|
|
|
|
$in->pr->number,
|
|
|
|
$against_name
|
|
|
|
);
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->pending('Checked out ' . $against_name);
|
2017-10-29 21:10:26 +00:00
|
|
|
|
|
|
|
$against = GHE\Exec::exec('git rev-parse %s', [$against_name]);
|
|
|
|
echo " $against_name is $against[0]\n";
|
|
|
|
|
2017-11-03 12:34:18 +00:00
|
|
|
$prev_darwin_stdenv = identify_stdenv("x86_64-darwin");
|
|
|
|
$prev_linux_stdenv = identify_stdenv("x86_64-linux");
|
|
|
|
echo "starting stdenvs:\n";
|
|
|
|
echo " - darwin: $prev_darwin_stdenv\n";
|
|
|
|
echo " - linux: $prev_linux_stdenv\n";
|
|
|
|
|
2017-10-29 21:10:26 +00:00
|
|
|
try {
|
2017-10-31 08:09:41 +00:00
|
|
|
$co->applyPatches($pname, $in->pr->patch_url);
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->pending('Applied patches from ' . $in->pr->number);
|
2017-10-29 21:10:26 +00:00
|
|
|
} catch (GHE\ExecException $e) {
|
2017-11-03 12:34:18 +00:00
|
|
|
echo "marking PR as failed to apply patches\n";
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->error('Failed to apply patches to ' . $against_name);
|
2017-11-03 12:34:18 +00:00
|
|
|
|
2017-10-29 21:10:26 +00:00
|
|
|
echo "Received ExecException applying patches, likely due to conflicts:\n";
|
|
|
|
var_dump($e->getCode());
|
|
|
|
var_dump($e->getMessage());
|
|
|
|
var_dump($e->getArgs());
|
|
|
|
var_dump($e->getOutput());
|
2017-10-31 08:09:41 +00:00
|
|
|
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
2017-10-29 21:10:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-04 15:58:37 +00:00
|
|
|
$querypkgsstatus = new GHE\CommitStatus($ghclient, $in->repo->owner,
|
|
|
|
$in->repo->name, $head_sha,
|
|
|
|
'grahamcofborg-eval-packagelist');
|
2017-11-03 12:34:18 +00:00
|
|
|
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->pending('Checking if stdenv changed');
|
2017-11-03 12:34:18 +00:00
|
|
|
$new_darwin_stdenv = identify_stdenv("x86_64-darwin");
|
|
|
|
$new_linux_stdenv = identify_stdenv("x86_64-linux");
|
|
|
|
echo "new stdenvs:\n";
|
|
|
|
echo " - darwin: $new_darwin_stdenv\n";
|
|
|
|
echo " - linux: $new_linux_stdenv\n";
|
|
|
|
|
|
|
|
|
2017-10-29 21:10:26 +00:00
|
|
|
$current = GHE\Exec::exec('git rev-parse HEAD');
|
|
|
|
echo " currently at ${current[0]}\n";
|
|
|
|
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->pending('Checking for sub-evals');
|
|
|
|
|
|
|
|
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
|
|
|
'package-list',
|
|
|
|
'nix-env --file . --query --available > /dev/null 2>&1', []);
|
|
|
|
|
2017-11-03 12:34:18 +00:00
|
|
|
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
|
|
|
'nixos-options',
|
|
|
|
'nix-instantiate ./nixos/release.nix -A options', []);
|
|
|
|
|
|
|
|
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
|
|
|
'nixos-manual',
|
|
|
|
'nix-instantiate ./nixos/release.nix -A manual', []);
|
|
|
|
|
|
|
|
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
|
|
|
'nixpkgs-manual',
|
|
|
|
'nix-instantiate ./pkgs/top-level/release.nix -A manual', []);
|
|
|
|
|
|
|
|
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
|
|
|
'nixpkgs-tarball',
|
|
|
|
'nix-instantiate ./pkgs/top-level/release.nix -A tarball', []);
|
|
|
|
|
|
|
|
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
|
|
|
'nixpkgs-unstable-jobset',
|
|
|
|
'nix-instantiate ./pkgs/top-level/release.nix -A unstable', []);
|
|
|
|
|
2017-11-04 15:58:37 +00:00
|
|
|
reply_to_issue($overallstatus, $in->repo, $in->pr,
|
2017-11-03 12:34:18 +00:00
|
|
|
$new_darwin_stdenv !== $prev_darwin_stdenv,
|
|
|
|
$new_linux_stdenv !== $prev_linux_stdenv,
|
|
|
|
$against[0], $current[0]);
|
|
|
|
|
|
|
|
echo "marking PR as success\n";
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->success('Evaluation checks OK');
|
2017-10-29 21:10:26 +00:00
|
|
|
|
2017-10-31 08:09:41 +00:00
|
|
|
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
|
|
|
return true;
|
2017-10-29 21:10:26 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 12:34:18 +00:00
|
|
|
function try_eval($ghclient, $owner, $name, $sha, $eval_name, $cmd, $args) {
|
|
|
|
echo "Starting $eval_name on $sha\n";
|
2017-11-04 15:58:37 +00:00
|
|
|
|
|
|
|
$status = new GHE\CommitStatus($ghclient, $owner,
|
|
|
|
$name, $sha,
|
|
|
|
'grahamcofborg-eval-' . $eval_name);
|
|
|
|
|
|
|
|
$status->pending("starting to run $cmd");
|
2017-11-03 12:34:18 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
GHE\Exec::exec($cmd, $args);
|
2017-11-04 15:58:37 +00:00
|
|
|
echo "Success running $eval_name on $sha\n";
|
|
|
|
$status->success("Finished running $cmd");
|
2017-11-03 12:34:18 +00:00
|
|
|
} catch (GHE\ExecException $e) {
|
|
|
|
echo "Failed to run $eval_name on $sha\n";
|
2017-11-04 15:58:37 +00:00
|
|
|
$status->pending("Failed to run $cmd");
|
2017-11-03 12:34:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function identify_stdenv($arch) {
|
|
|
|
$lines = GHE\Exec::exec('nix-instantiate . -A stdenv --argstr system %s 2>&1',
|
|
|
|
[$arch]);
|
|
|
|
echo "fetching stdenv for $arch:\n";
|
|
|
|
var_dump($lines);
|
|
|
|
return array_pop($lines);
|
|
|
|
}
|
|
|
|
|
2017-11-04 15:58:37 +00:00
|
|
|
function reply_to_issue($overallstatus, $repo, $pr, $darwin_changed, $linux_changed, $prev, $current) {
|
2017-10-29 21:10:26 +00:00
|
|
|
$client = gh_client();
|
|
|
|
|
|
|
|
echo "current labels:\n";
|
|
|
|
$already_there = $client->api('issue')->labels()->all(
|
2017-10-31 08:09:41 +00:00
|
|
|
$repo->owner,
|
|
|
|
$repo->name,
|
|
|
|
$pr->number);
|
2017-10-29 21:10:26 +00:00
|
|
|
$already_there = array_map(function($val) { return $val['name']; }, $already_there);
|
|
|
|
var_dump($already_there);
|
|
|
|
|
2017-11-04 15:58:37 +00:00
|
|
|
$overallstatus->pending("Diffing derivations");
|
2017-10-29 21:10:26 +00:00
|
|
|
$output = GHE\Exec::exec('$(nix-instantiate --eval -E %s) %s %s',
|
|
|
|
[
|
|
|
|
'<nixpkgs/maintainers/scripts/rebuild-amount.sh>',
|
|
|
|
$prev,
|
|
|
|
$current
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2017-11-03 12:34:18 +00:00
|
|
|
var_dump($output);
|
|
|
|
|
2017-11-01 15:48:27 +00:00
|
|
|
$labels = GHE\RebuildTagClassifier::parseAndLabel($output);
|
2017-10-29 21:10:26 +00:00
|
|
|
|
2017-11-03 12:34:18 +00:00
|
|
|
if ($darwin_changed) {
|
|
|
|
$labels[] = '10.rebuild-darwin-stdenv';
|
|
|
|
}
|
|
|
|
if ($linux_changed) {
|
|
|
|
$labels[] = '10.rebuild-linux-stdenv';
|
|
|
|
}
|
|
|
|
|
2017-10-29 21:10:26 +00:00
|
|
|
foreach ($labels as $label) {
|
|
|
|
if (in_array($label, $already_there)) {
|
|
|
|
echo "already labeled $label\n";
|
|
|
|
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
echo "will label +$label\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$client->api('issue')->labels()->add(
|
2017-10-31 08:09:41 +00:00
|
|
|
$repo->owner,
|
|
|
|
$repo->name,
|
|
|
|
$pr->number,
|
2017-10-29 21:10:26 +00:00
|
|
|
$label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$consumerTag = 'consumer' . getmypid();
|
2017-10-31 08:09:41 +00:00
|
|
|
$channel->basic_consume($queueName, $consumerTag, false, false, false, false, 'outrunner');
|
2017-10-29 21:10:26 +00:00
|
|
|
while(count($channel->callbacks)) {
|
|
|
|
$channel->wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Bye\n";
|