aboutsummaryrefslogtreecommitdiffstats
path: root/rebuild-packages
blob: f1d2fbaf26cec646b44914e6de5296e66eafbd19 (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
55
56
57
58
59
60
#!/usr/bin/perl -w

use strict;
use File::Temp qw(tempfile);
use Youri::Package::RPM::Updater;
use LWP::UserAgent;
use MDK::Common;
use Cwd;
use List::Util qw(shuffle);

my $status_page = 'http://pkgsubmit.mageia.org/';
my $svn_root = 'svn+ssh://svn.mageia.org/svn/packages/cauldron/';
my $commit_msg = 'Mass Rebuild - https://wiki.mageia.org/en/Feature:Mageia3MassRebuild';
my $bs_max_todo_queue = 5;
my $updater = Youri::Package::RPM::Updater->new;

my ($ci_fh, $ci_fname) = tempfile(UNLINK => 1);
print $ci_fh $commit_msg;
close $ci_fh;

sub list_from_file {
    shuffle(chomp_(cat_($_[0])));
}

sub get_bs_queue_todo() {
    my $ua = LWP::UserAgent->new;
    my $req = HTTP::Request->new(HEAD => $status_page);
    my $res = $ua->request($req);
    return $res->is_success ? $res->header('X-BS-Queue-Todo') : 9999;
}

sub bump_release {
    my ($pkgname) = @_;
    print STDOUT "== Bumping release for $pkgname\n";
    my $oldcwd = getcwd();
    my $tmpdir = File::Temp->newdir;
    chdir $tmpdir->dirname;
    system('svn', 'co', "${svn_root}/${pkgname}/current");
    chdir 'current';
    $updater->update_from_spec(glob('SPECS/*.spec'));
    system('svn', 'ci', '--file', $ci_fname);
    chdir $oldcwd;
}

sub submit_package {
    my ($pkgname) = @_;
    print STDOUT "== Submitting $pkgname\n";
    while (get_bs_queue_todo() > $bs_max_todo_queue) {
	sleep 20;
    }
    system('mgarepo', 'submit', $pkgname);
}

my @packages_list = list_from_file($ARGV[0]);
foreach (@packages_list) {
    eval {
	bump_release($_);
	submit_package($_);
    }
}