1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#!/usr/bin/env perl
use strict;
use warnings;
use Redis;
use JSON;
use YAML qw/LoadFile Dump/;
use File::Spec;
use File::Path qw/rmtree/;
use File::Basename;
use Git::Repository;
$|++;
my $conf = LoadFile('config.yml');
my $redis = Redis->new(server => $conf->{redis});
my $key = join(':', 'jitterbug', 'tasks');
while (1) {
my $task_key = $redis->spop($key);
if ($task_key) {
my $task = $redis->get($task_key);
my $desc = JSON::decode_json($task);
my $repo = $desc->{repo} . '.git';
my $commit = delete $desc->{id};
my $project = delete $desc->{project};
my $report_path =
File::Spec->catdir( $conf->{jitterbug}->{reports}->{dir},
$project, $commit );
my $build_dir =
File::Spec->catdir( $conf->{jitterbug}->{build}->{dir}, $project );
my $r = Git::Repository->create( clone => $repo => $build_dir );
$r->run('checkout', $commit);
my $res = `./scripts/capsule.sh $build_dir $report_path`;
rmtree($build_dir);
$redis->del($task_key);
my $build = {
project => $project,
repo => $repo,
commit => $commit,
status => 1,
time => time(),
%$desc,
};
my @versions = glob($report_path.'/*');
foreach my $version (@versions) {
open my $fh, '<', $version;
my @lines = <$fh>;
my $result = pop @lines;
chomp $result;
$result =~ s/Result:\s//;
my ($name, ) = basename($version);
$name =~ s/\.txt//;
$build->{version}->{$name} = $result;
}
my $build_key = join( ':', 'jitterbug', 'build', $commit );
$redis->set( $build_key, JSON::encode_json($build) );
my $project_build = join( ':', 'jitterbug', 'builds', $project );
$redis->sadd( $project_build, $build_key );
warn "done, next\n";
}
sleep 5;
}
|