#!/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" }); }