Use CommitStatus to make updating statuses cleaner
This commit is contained in:
parent
a19582caef
commit
d7cef0179d
|
@ -53,16 +53,11 @@ function runner($msg) {
|
||||||
|
|
||||||
$ghclient = gh_client();
|
$ghclient = gh_client();
|
||||||
|
|
||||||
|
$overallstatus = new GHE\CommitStatus($ghclient, $in->repo->owner,
|
||||||
|
$in->repo->name, $head_sha,
|
||||||
|
'grahamcofborg-eval');
|
||||||
echo "marking PR as pending\n";
|
echo "marking PR as pending\n";
|
||||||
$ghclient->api('repository')->statuses()->create(
|
$overallstatus->pending('GrahamCOfBorg is starting');
|
||||||
$in->repo->owner,
|
|
||||||
$in->repo->name,
|
|
||||||
$head_sha,
|
|
||||||
[
|
|
||||||
'state' => 'pending',
|
|
||||||
'context' => 'grahamcofborg-eval',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$against_name = "origin/" . $in->pr->target_branch;
|
$against_name = "origin/" . $in->pr->target_branch;
|
||||||
echo "Building against $against_name\n";
|
echo "Building against $against_name\n";
|
||||||
|
@ -72,6 +67,7 @@ function runner($msg) {
|
||||||
$in->pr->number,
|
$in->pr->number,
|
||||||
$against_name
|
$against_name
|
||||||
);
|
);
|
||||||
|
$overallstatus->pending('Checked out ' . $against_name);
|
||||||
|
|
||||||
$against = GHE\Exec::exec('git rev-parse %s', [$against_name]);
|
$against = GHE\Exec::exec('git rev-parse %s', [$against_name]);
|
||||||
echo " $against_name is $against[0]\n";
|
echo " $against_name is $against[0]\n";
|
||||||
|
@ -84,18 +80,10 @@ function runner($msg) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$co->applyPatches($pname, $in->pr->patch_url);
|
$co->applyPatches($pname, $in->pr->patch_url);
|
||||||
|
$overallstatus->pending('Applied patches from ' . $in->pr->number);
|
||||||
} catch (GHE\ExecException $e) {
|
} catch (GHE\ExecException $e) {
|
||||||
echo "marking PR as failed to apply patches\n";
|
echo "marking PR as failed to apply patches\n";
|
||||||
$ghclient->api('repository')->statuses()->create(
|
$overallstatus->error('Failed to apply patches to ' . $against_name);
|
||||||
$in->repo->owner,
|
|
||||||
$in->repo->name,
|
|
||||||
$head_sha,
|
|
||||||
[
|
|
||||||
'state' => 'error',
|
|
||||||
'description' => "failed to apply patches to $against_name",
|
|
||||||
'context' => 'grahamcofborg-eval',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
echo "Received ExecException applying patches, likely due to conflicts:\n";
|
echo "Received ExecException applying patches, likely due to conflicts:\n";
|
||||||
var_dump($e->getCode());
|
var_dump($e->getCode());
|
||||||
|
@ -106,25 +94,11 @@ function runner($msg) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
$querypkgsstatus = new GHE\CommitStatus($ghclient, $in->repo->owner,
|
||||||
GHE\Exec::exec('nix-env --file . --query --available --json > /dev/null 2>&1');
|
$in->repo->name, $head_sha,
|
||||||
} catch (GHE\ExecException $e) {
|
'grahamcofborg-eval-packagelist');
|
||||||
echo "marking PR as failed to evaluate\n";
|
|
||||||
$ghclient->api('repository')->statuses()->create(
|
|
||||||
$in->repo->owner,
|
|
||||||
$in->repo->name,
|
|
||||||
$head_sha,
|
|
||||||
[
|
|
||||||
'state' => 'failure',
|
|
||||||
'description' => 'Failed to evaluate packages',
|
|
||||||
'context' => 'grahamcofborg-eval',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$overallstatus->pending('Checking if stdenv changed');
|
||||||
$new_darwin_stdenv = identify_stdenv("x86_64-darwin");
|
$new_darwin_stdenv = identify_stdenv("x86_64-darwin");
|
||||||
$new_linux_stdenv = identify_stdenv("x86_64-linux");
|
$new_linux_stdenv = identify_stdenv("x86_64-linux");
|
||||||
echo "new stdenvs:\n";
|
echo "new stdenvs:\n";
|
||||||
|
@ -135,6 +109,12 @@ function runner($msg) {
|
||||||
$current = GHE\Exec::exec('git rev-parse HEAD');
|
$current = GHE\Exec::exec('git rev-parse HEAD');
|
||||||
echo " currently at ${current[0]}\n";
|
echo " currently at ${current[0]}\n";
|
||||||
|
|
||||||
|
$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', []);
|
||||||
|
|
||||||
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
try_eval($ghclient, $in->repo->owner, $in->repo->name, $head_sha,
|
||||||
'nixos-options',
|
'nixos-options',
|
||||||
'nix-instantiate ./nixos/release.nix -A options', []);
|
'nix-instantiate ./nixos/release.nix -A options', []);
|
||||||
|
@ -155,22 +135,13 @@ function runner($msg) {
|
||||||
'nixpkgs-unstable-jobset',
|
'nixpkgs-unstable-jobset',
|
||||||
'nix-instantiate ./pkgs/top-level/release.nix -A unstable', []);
|
'nix-instantiate ./pkgs/top-level/release.nix -A unstable', []);
|
||||||
|
|
||||||
reply_to_issue($in->repo, $in->pr,
|
reply_to_issue($overallstatus, $in->repo, $in->pr,
|
||||||
$new_darwin_stdenv !== $prev_darwin_stdenv,
|
$new_darwin_stdenv !== $prev_darwin_stdenv,
|
||||||
$new_linux_stdenv !== $prev_linux_stdenv,
|
$new_linux_stdenv !== $prev_linux_stdenv,
|
||||||
$against[0], $current[0]);
|
$against[0], $current[0]);
|
||||||
|
|
||||||
echo "marking PR as success\n";
|
echo "marking PR as success\n";
|
||||||
$ghclient->api('repository')->statuses()->create(
|
$overallstatus->success('Evaluation checks OK');
|
||||||
$in->repo->owner,
|
|
||||||
$in->repo->name,
|
|
||||||
$head_sha,
|
|
||||||
[
|
|
||||||
'state' => 'success',
|
|
||||||
'description' => 'Evaluation checks OK',
|
|
||||||
'context' => 'grahamcofborg-eval',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
||||||
return true;
|
return true;
|
||||||
|
@ -178,45 +149,22 @@ function runner($msg) {
|
||||||
|
|
||||||
function try_eval($ghclient, $owner, $name, $sha, $eval_name, $cmd, $args) {
|
function try_eval($ghclient, $owner, $name, $sha, $eval_name, $cmd, $args) {
|
||||||
echo "Starting $eval_name on $sha\n";
|
echo "Starting $eval_name on $sha\n";
|
||||||
$ghclient->api('repository')->statuses()->create(
|
|
||||||
$owner,
|
$status = new GHE\CommitStatus($ghclient, $owner,
|
||||||
$name,
|
$name, $sha,
|
||||||
$sha,
|
'grahamcofborg-eval-' . $eval_name);
|
||||||
[
|
|
||||||
'state' => 'pending',
|
$status->pending("starting to run $cmd");
|
||||||
'context' => 'grahamcofborg-eval-' . $eval_name,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GHE\Exec::exec($cmd, $args);
|
GHE\Exec::exec($cmd, $args);
|
||||||
|
echo "Success running $eval_name on $sha\n";
|
||||||
|
$status->success("Finished running $cmd");
|
||||||
} catch (GHE\ExecException $e) {
|
} catch (GHE\ExecException $e) {
|
||||||
echo "Failed to run $eval_name on $sha\n";
|
echo "Failed to run $eval_name on $sha\n";
|
||||||
$ghclient->api('repository')->statuses()->create(
|
$status->pending("Failed to run $cmd");
|
||||||
$owner,
|
|
||||||
$name,
|
|
||||||
$sha,
|
|
||||||
[
|
|
||||||
'state' => 'failure',
|
|
||||||
'description' => 'Failed to evaluate ' . $eval_name,
|
|
||||||
'context' => 'grahamcofborg-eval-' . $eval_name,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Success running $eval_name on $sha\n";
|
|
||||||
$ghclient->api('repository')->statuses()->create(
|
|
||||||
$owner,
|
|
||||||
$name,
|
|
||||||
$sha,
|
|
||||||
[
|
|
||||||
'state' => 'success',
|
|
||||||
'description' => 'Evaluation of ' . $eval_name . ' is OK',
|
|
||||||
'context' => 'grahamcofborg-eval-' . $eval_name,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function identify_stdenv($arch) {
|
function identify_stdenv($arch) {
|
||||||
|
@ -227,7 +175,7 @@ function identify_stdenv($arch) {
|
||||||
return array_pop($lines);
|
return array_pop($lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reply_to_issue($repo, $pr, $darwin_changed, $linux_changed, $prev, $current) {
|
function reply_to_issue($overallstatus, $repo, $pr, $darwin_changed, $linux_changed, $prev, $current) {
|
||||||
$client = gh_client();
|
$client = gh_client();
|
||||||
|
|
||||||
echo "current labels:\n";
|
echo "current labels:\n";
|
||||||
|
@ -238,6 +186,7 @@ function reply_to_issue($repo, $pr, $darwin_changed, $linux_changed, $prev, $cur
|
||||||
$already_there = array_map(function($val) { return $val['name']; }, $already_there);
|
$already_there = array_map(function($val) { return $val['name']; }, $already_there);
|
||||||
var_dump($already_there);
|
var_dump($already_there);
|
||||||
|
|
||||||
|
$overallstatus->pending("Diffing derivations");
|
||||||
$output = GHE\Exec::exec('$(nix-instantiate --eval -E %s) %s %s',
|
$output = GHE\Exec::exec('$(nix-instantiate --eval -E %s) %s %s',
|
||||||
[
|
[
|
||||||
'<nixpkgs/maintainers/scripts/rebuild-amount.sh>',
|
'<nixpkgs/maintainers/scripts/rebuild-amount.sh>',
|
||||||
|
|
49
src/CommitStatus.php
Normal file
49
src/CommitStatus.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace GHE;
|
||||||
|
|
||||||
|
class CommitStatus {
|
||||||
|
|
||||||
|
protected $ghclient;
|
||||||
|
protected $owner;
|
||||||
|
protected $repo;
|
||||||
|
protected $sha;
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
function __construct($ghclient, $owner, $repo, $sha, $name) {
|
||||||
|
$this->ghclient = $ghclient;
|
||||||
|
$this->owner = $owner;
|
||||||
|
$this->repo = $repo;
|
||||||
|
$this->sha = $sha;
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pending($description) {
|
||||||
|
$this->mark('pending', $description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function error($description) {
|
||||||
|
$this->mark('error', $description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function failure($description) {
|
||||||
|
$this->mark('failure', $description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function success($description) {
|
||||||
|
$this->mark('success', $description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mark($state, $description) {
|
||||||
|
$this->ghclient->api('repository')->statuses()->create(
|
||||||
|
$this->owner,
|
||||||
|
$this->repo,
|
||||||
|
$this->sha,
|
||||||
|
[
|
||||||
|
'state' => $state,
|
||||||
|
'context' => $this->name,
|
||||||
|
'description' => $description,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue