summaryrefslogtreecommitdiff
path: root/bin/rebuild-for-athena
blob: b32db303455e62fb0470768fdcd8f0fd289baaaa (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl

use 5.028;
use strict;
use warnings;

use autodie;

use File::Basename qw(basename);
use Git::Wrapper;
use Getopt::Long;
use Term::UI;

my ($want_minus, $want_plus) = (0, 0);
GetOptions
  "minus" => \$want_minus,
  "plus"  => \$want_plus;
die "invalid options" if $want_minus and $want_plus;
$want_minus = 1 unless $want_minus or $want_plus;
die "usage: " . basename $0 . " [--minus|--plus] CODENAME\n" unless @ARGV == 1;
my $codename = pop @ARGV;
my $git      = Git::Wrapper->new(".");
my $term     = Term::ReadLine->new("brand");
die "git commit first\n" unless $git->RUN("status", { porcelain => 1 }) == 0;

rebuild_for_suite($codename);
system "release-to-athena";

# if we just rebuilt for unstable, also offer to rebuild for stable-backports
if ($codename eq "unstable") {
    exit unless $term->ask_yn(prompt => "also rebuild for bullseye-backports?");

    rebuild_for_suite("bullseye-backports", "~bpo11+1");
    system "release-to-athena";
}

sub rebuild_for_suite {
    my $codename = shift;
    my $local    = shift;
    my $branch   = "athena/$codename";

    my $local_branch_exists = $git->for_each_ref("[r]efs/heads/$branch") != 0;
    my @remote_branches     = map {
        my (undef, undef, $ref) = split;
        $ref =~ s{^refs/remotes/}{};
        $ref
      }
      grep {
        m{/$branch$}
      } $git->for_each_ref("refs/remotes");

    $local .= "~athena" if $want_minus;
    $local .= "+athena" if $want_plus;

    if ($local_branch_exists) {
        my ($branch_to_build) = $git->symbolic_ref("HEAD");
        $branch_to_build =~ s{^refs/heads/}{};

        # are we already on the requisite branch and this script is being used
        # to release?
        if ($branch eq $branch_to_build) {
            chomp(my $dist = `dpkg-parsechangelog -SDistribution`);
            if ($dist eq "UNRELEASED") {
                system "dch", "-r", "-D$codename";
            } else {
                say "Hmm, already on $branch and changelog is not UNRELEASED";
                exit 1;
            }
        } else {
            $git->checkout($branch);
	    system "dgit", "setup-mergechangelogs";
            $git->merge($branch_to_build);
            system "dch", "-D$codename", "-l$local",
              "Rebuild for athena's apt repository.";
            system qw(dch -r);
        }
    } else {
        if (@remote_branches) {
            say "I want to create branch $branch, "
              . "but these remote branches already exist:";
            say for @remote_branches;
            say
"maybe you want to check out or `git branchmove get` one of those";
            exit 1;
        } else {
            $git->checkout("-b", $branch);
            system "dch", "-D$codename", "-l$local",
              "Rebuild for athena's apt repository.";
            system qw(dch -r);
        }
    }

    $git->add("debian/changelog");
    $git->commit({ message => "Rebuild for athena's apt repository" });
}