#!/usr/bin/env perl
# This script greps the JSON files for the buildbots on
# the LLVM official build master by name and prints an
# HTML page with the links to the bots and the status.
#
# Multiple masters can be used, as well as multiple groups of bots
# and multiple bots per group, all in a json file. See linaro.json
# in this repository to have an idea how the config file is.
#
# Module JSON needs to be installed, either from cpan or packages.
push @INC, `dirname $0`;
use strict;
use warnings;
# Core modules
use File::Temp qw/tempfile/;
use File::Copy;
# This is not part of core, but you really *need* it.
use JSON;
# This can be replaced by `wget/curl`
use LWP;
use LWP::UserAgent;
# We don't have DateTime everywhere...
my $date = `date`;
# DEBUG
my $DEBUG = 0;
######################################################### Initialisation
# Option checking
my $syntax = "$0 config-file.json output-file.html\n";
die $syntax unless (scalar @ARGV == 2);
# Read config file
my ($config, $error) = &read_file($ARGV[0]);
die $error if ($error);
($config, $error) = &decode($config);
die $error if ($error);
# Setup HTML output file
my $output = $ARGV[1];
my ($temp, $tempname) = tempfile();
######################################################### Main Logic
# Get status for all bots
my %bot_cache;
my $fail = 0;
foreach my $server (@$config) {
next if (defined $server->{'ignore'} and $server->{'ignore'} eq "true");
my ($BASE_URL, $BUILDER_URL, $BUILD_URL) =
($server->{'base_url'}, $server->{'builder_url'}, $server->{'build_url'});
&debug("Parsing server ".$server->{'name'}."...\n");
foreach my $builder (@{$server->{'builders'}}) {
&debug(" Parsing builder ".$builder->{'name'}."...\n");
foreach my $bot (@{$builder->{'bots'}}) {
&debug(" Parsing bot ".$bot->{'name'}."...\n");
next if defined $bot_cache{$bot->{'name'}};
my $status = &get_status($bot->{'name'}, $BASE_URL, $BUILDER_URL, $BUILD_URL);
if (!defined $bot->{'ignore'} or $bot->{'ignore'} ne "true") {
$fail = 1 if ($status->{'fail'});
} else {
&debug(" Ignoring...\n");
}
&debug($status->{'fail'} ? " FAIL\n" : " PASS\n");
$bot_cache{$BASE_URL.'/'.$bot->{'name'}} = $status;
}
}
}
# Dump all servers / bots
foreach my $server (@$config) {
next if (defined $server->{'ignore'} and $server->{'ignore'} eq "true");
my ($BASE_URL, $BUILDER_URL, $BUILD_URL) =
($server->{'base_url'}, $server->{'builder_url'}, $server->{'build_url'});
# Favicon
my $favicon = $fail ? "fail.ico" : "ok.ico";
print $temp "\n";
# Header
print $temp "
\n";
print $temp "
\n";
print $temp "
$server->{'name'} @ $date
\n";
## Main loop
foreach my $builder (@{$server->{'builders'}}) {
print $temp "
\n";
print $temp "
$builder->{'name'}
\n";
print $temp "
Buildbot
Status
Comments
".
"
Build #
Commits
Time (minutes)
\n";
foreach my $bot (@{$builder->{'bots'}}) {
print $temp "
\n";
my $status = $bot_cache{$BASE_URL.'/'.$bot->{'name'}};
my $url = "$BASE_URL/$BUILDER_URL/$bot->{'name'}";
print $temp "