aboutsummaryrefslogtreecommitdiff
path: root/tools/cover.pl
blob: fcd813f94c9fc9a2aaf7935aae03690c80e08db7 (plain)
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
#!/usr/bin/env perl

use strict;
use warnings;
use feature 'say';

use AWS::S3;
use Path::Tiny;

if (!@ARGV) {
	die "Need to specify a build number to check coverage for.\n";
}

my $build = shift;
my $base = qr!^[^/]+/sbotools/\Q$build\E/!;

if (
  ! length($ENV{S3_ID}) or
  ! length($ENV{S3_KEY}) or
  ! length($ENV{S3_BUCKET})) {
	die "S3_ID and S3_KEY need to be defined in the environment.\n";
}

print "Connecting to S3...\n";

my $s3 = AWS::S3->new(
	access_key_id => $ENV{S3_ID},
	secret_access_key => $ENV{S3_KEY},
);

my $bucket = $s3->bucket($ENV{S3_BUCKET});

my $f_iter = $bucket->files(
	page_size => 100,
	page_number => 1,
	pattern => qr!$base\Q$build.11\E/!,
);

my $num = 0;
while (my @files = $f_iter->next_page) {
	for my $file (@files) {
		$num++;
		print $file->key, "\n";

		my $local_fname = $file->key =~ s!$base!cover_db/!r;
		my $path = path($local_fname)->absolute();

		$path->touchpath->spew_raw(${ $file->contents() });
	}
}

if ($num == 0) {
	die "No files found for build number $build.\n";
}