Minor improvements to the maint helper scripts
[dbsrgits/DBIx-Class.git] / maint / travis_buildlog_downloader
1 #!/usr/bin/env perl
2
3 use warnings;
4 use strict;
5
6 # H::T does not support gzip/deflate out of the box, but you know what?
7 # THAT'S OK BECAUSE TRAVIS' LOGSERVER DOESN'T EITHER </headdesk>
8 use HTTP::Tiny;
9
10 use JSON::PP;
11
12 ( my $build_id = $ARGV[0]||'' ) =~ /^[0-9]+$/
13   or die "Expecting a numeric build id as argument\n";
14
15 my $base_url = "http://api.travis-ci.org/builds/$build_id";
16 print "Retrieving $base_url\n";
17
18 my $resp = ( my $ua = HTTP::Tiny->new )->get( $base_url );
19 die "Unable to retrieve $resp->{url}: $resp->{status}\n$resp->{content}\n\n"
20   unless $resp->{success};
21
22 my @jobs = ( map
23   { ( ($_->{id}||'') =~ /^([0-9]+)$/ ) ? [ $1 =>  $_->{number} ] : () }
24   @{( eval { decode_json( $resp->{content} )->{matrix} } || [] )}
25 ) or die "Unable to find any jobs:\n$resp->{content}\n\n";
26
27 my $dir = "TravisCI_build_$build_id";
28
29 mkdir $dir
30   unless -d $dir;
31
32 for my $job (@jobs) {
33   my $log_url = "http://api.travis-ci.org/jobs/$job->[0]/log.txt";
34   my $dest_fn = "$dir/job_$job->[1].$job->[0].log";
35
36   print "Retrieving $log_url into $dest_fn\n";
37
38   $resp = $ua->mirror( $log_url, $dest_fn );
39   warn "Error retrieving $resp->{url}: $resp->{status}\n$resp->{content}\n\n"
40     unless $resp->{success};
41 }