Skip to content
Permalink
Browse files

release.pl: support point releases

  • Loading branch information
jef-n committed Feb 22, 2015
1 parent 9c17f96 commit 01066b60824768cbde343f1117c6d7bd9029abd2
Showing with 146 additions and 79 deletions.
  1. +146 −79 scripts/release.pl
@@ -13,138 +13,205 @@
use Getopt::Long;
use Pod::Usage;

my $newmajor;
my $newminor;
my $releasename;
my $dryrun;

sub updateCMakeLists($$$$) {
my($major,$minor,$patch,$release) = @_;

if( $dryrun ) {
print "DRYRUN: Update CMakeLists.txt to $major.$minor.$patch ($release)\n";
return;
}

rename "CMakeLists.txt", "CMakeLists.txt.orig" or die "cannot rename CMakeLists.txt: $!";
open I, "CMakeLists.txt.orig";
open O, ">CMakeLists.txt" or die "cannot create CMakeLists.txt: $!";
while(<I>) {
s/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/SET(CPACK_PACKAGE_VERSION_MAJOR "$major")/;
s/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/SET(CPACK_PACKAGE_VERSION_MINOR "$minor")/;
s/SET\(CPACK_PACKAGE_VERSION_PATCH "(\d+)"\)/SET(CPACK_PACKAGE_VERSION_PATCH "$patch")/;
s/SET\(RELEASE_NAME "(.+)"\)/SET(RELEASE_NAME "$release")/;
print O;
}
close O;
close I;
}

sub run($$) {
my($cmd, $errmsg) = @_;
if( $dryrun ) {
print "DRYRUN: $cmd\n";
} elsif( system($cmd) != 0 ) {
print STDERR "error: $errmsg [$?]";
exit 1;
}
}

my $newreleasename;
my $help;
my $domajor;
my $dominor;
my $dopoint;

my $result = GetOptions(
"major" => \$newmajor,
"minor" => \$newminor,
"releasename=s" => \$releasename,
"help" => \$help
"major" => \$domajor,
"minor" => \$dominor,
"point" => \$dopoint,
"releasename=s" => \$newreleasename,
"help" => \$help,
"dryrun" => \$dryrun,
);

$releasename = shift @ARGV;
pod2usage(1) if $help;

pod2usage(1) if $help or !defined $releasename;
my $i = 0;
$i++ if defined $domajor;
$i++ if defined $dominor;
$i++ if defined $dopoint;
pod2usage("Exactly one of -major, -minor or -point expected") if $i!=1;
pod2usage("Release name for major and minor releases expected") if !$dopoint && !defined $newreleasename;
pod2usage("No CMakeLists.txt in current directory") unless -r "CMakeLists.txt";

my $major;
my $minor;
my $patch;
my $releasename;
open F, "CMakeLists.txt";
while(<F>) {
if(/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/) {
$major = $1;
} elsif(/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/) {
$minor = $1;
} elsif(/SET\(CPACK_PACKAGE_VERSION_PATCH "(\d+)"\)/) {
$patch = $1;
} elsif(/SET\(RELEASE_NAME \"(.*)\"\)/) {
$releasename = $1;
}
}
close F;

if( defined $newmajor ) {
die "New major must be equal or greater than old major $major" if $newmajor <= $major;
$newminor = 0 unless defined $newminor;
my $branch = `git rev-parse --abbrev-ref HEAD 2>/dev/null`;
$branch =~ s/\s+$//;
pod2usage("Not on a branch") unless $branch;
pod2usage("Current branch is $branch. master or a release branch expected") if $branch !~ /^(master|release-(\d+)_(\d+))$/;
pod2usage("Version mismatch ($2.$3 in branch $branch vs. $major.$minor in CMakeLists.txt)") if $branch ne "master" && ( $major != $2 || $minor != $3 );
pod2usage("Release name Master expected on master branch" ) if $branch eq "master" && $releasename ne "Master";

if( $branch eq "master" ) {
pod2usage("No point releases on master branch") if $dopoint;
pod2usage("No new release name for major/minor release") unless $newreleasename || $newreleasename eq $releasename;
} else {
$newmajor = $major;
pod2usage("Only point releases on release branches") if !$dopoint;
pod2usage("New release names only for new minor releases") if $newreleasename;
$newreleasename = $releasename;
}

if( defined $newminor ) {
die "New minor must be greater than current minor $minor" if $newmajor==$major && $newminor<=$minor;
} else {
my $newmajor;
my $newminor;
my $newpatch;
if( $domajor ) {
$newmajor = $major + 1;
$newminor = 0;
$newpatch = 0;
} elsif( $dominor ) {
$newmajor = $major;
$newminor = $minor + 1;
$newpatch = 0;
} elsif( $dopoint ) {
$newmajor = $major;
$newminor = $minor;
$newpatch = $patch + 1;
} else {
pod2usage("No version change");
}

sub updateCMakeLists {
my($major,$minor,$release) = @_;

rename "CMakeLists.txt", "CMakeLists.txt.orig" or die "cannot rename CMakeLists.txt: $!";
open I, "CMakeLists.txt.orig";
open O, ">CMakeLists.txt" or die "cannot create CMakeLists.txt: $!";
while(<I>) {
s/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/SET(CPACK_PACKAGE_VERSION_MAJOR "$major")/;
s/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/SET(CPACK_PACKAGE_VERSION_MINOR "$minor")/;
s/SET\(RELEASE_NAME "(.+)"\)/SET(RELEASE_NAME "$release")/;
print O;
}
close O;
close I;
}
pod2usage("Splash images/splash/splash-$newmajor.$newminor.png not found") unless -r "images/splash/splash-$newmajor.$newminor.png";
pod2usage("NSIS image ms-windows/Installer-Files/WelcomeFinishPage-$newmajor.$newminor.bmp not found") unless -r "ms-windows/Installer-Files/WelcomeFinishPage-$newmajor.$newminor.bmp";

print "Last pull rebase...\n";
system( "git pull --rebase" ) == 0 or die "git pull rebase failed";
run( "git pull --rebase", "git pull rebase failed" );

my $release = "$newmajor.$newminor";
my $version = "$release.$newpatch";
my $relbranch = "release-${newmajor}_${newminor}";
my $reltag = "final-${newmajor}_${newminor}_0";
my $reltag = "final-${newmajor}_${newminor}_${newpatch}";

print "Pulling transifex translations...\n";
system( "scripts/pull_ts.sh" ) == 0 or die "pull_ts.sh failed";
system( "git add i18n/*.ts" ) == 0 or die "adding translations failed";
system( "git commit -a -m \"translation update to $release from transifex\"") == 0 or die "could not commit translation updates";
unless( $dopoint ) {
print "Pulling transifex translations...\n";
run( "scripts/pull_ts.sh", "pull_ts.sh failed" );
run( "git add i18n/*.ts", "adding translations failed" );
run( "git commit -a -m \"translation update for $release from transifex\"", "could not commit translation updates" );
}

print "Updating changelog...\n";
system( "scripts/create_changelog.sh" ) == 0 or die "create_changelog.sh failed";
system( "git commit -a -m \"changelog update for $release\"") == 0 or die "could not commit changelog update";

print "Creating branch...\n";
system( "git checkout -b $relbranch" ) == 0 or die "git checkout release branch failed";
updateCMakeLists($newmajor,$newminor,$releasename);
run( "scripts/create_changelog.sh", "create_changelog.sh failed" );

print "Updating branch...\n";
system( "dch -r ''" ) == 0 or die "dch failed";
system( "dch --newversion $newmajor.$newminor.0 'Release of $release'" ) == 0 or die "dch failed";
system( "cp debian/changelog /tmp" ) == 0 or die "backup changelog failed";
unless( $dopoint ) {
run( "git commit -a -m \"changelog update for $release\"", "could not commit changelog update" );

if( -f "images/splash/splash-release.png" ) {
system( "cp -v images/splash/splash-release.png images/splash/splash.png" ) == 0 or die "splash png switch failed";
} else {
print "WARNING: NO images/splash/splash-release.png\n";
print "Creating and checking out branch...\n";
run( "git checkout -b $relbranch", "git checkout release branch failed" );
}

if( -f "images/splash/splash-release.xcf.bz2" ) {
system( "cp -v images/splash/splash-release.xcf.bz2 images/splash/splash.xcf.bz2" ) == 0 or die "splash xcf switch failed";
} else {
print "WARNING: NO images/splash/splash-release.xcf.bz2\n";
}
updateCMakeLists($newmajor,$newminor,$newpatch,$releasename);

if( -f "ms-windows/Installer-Files/WelcomeFinishPage-release.bmp" ) {
system( "cp -v ms-windows/Installer-Files/WelcomeFinishPage-release.bmp ms-windows/Installer-Files/WelcomeFinishPage.bmp" ) == 0 or die "installer bitmap switch failed";
print "Updating version...\n";
run( "dch -r ''", "dch failed" );
run( "dch --newversion $version 'Release of $version'", "dch failed" );
run( "cp debian/changelog /tmp", "backup changelog failed" );

unless( $dopoint ) {
run( "cp -v images/splash/splash-$newmajor.$newminor.png images/splash/splash.png", "splash png switch failed" );
run( "cp -v ms-windows/Installer-Files/WelcomeFinishPage-$newmajor.$newminor.bmp ms-windows/Installer-Files/WelcomeFinishPage.bmp", "installer bitmap switch failed" );

if( -f "images/splash/splash-release.xcf.bz2" ) {
run( "cp -v images/splash/splash-$newmajor.$newminor.xcf.bz2 images/splash/splash.xcf.bz2", "splash xcf switch failed" );
} else {
print "WARNING: NO images/splash/splash-release.xcf.bz2\n";
}

run( "git commit -a -m 'Release of $release ($releasename)'", "release commit failed" );
run( "git tag $reltag -m 'Version $release'", "tag failed" );
} else {
print "WARNING: NO ms-windows/Installer-Files/WelcomeFinishPage-release.bmp\n";
run( "git commit -a -m 'Release of $version'", "release commit failed" );
run( "git tag $reltag -m 'Version $version'", "tag failed" );
}

system( "git commit -a -m 'Release of $release ($releasename)'" ) == 0 or die "release commit failed";
system( "git tag $reltag -m 'Version $release'" ) == 0 or die "tag failed";

print "Producing archive...\n";
system( "git archive --format tar --prefix=qgis-$release.0/ $reltag | bzip2 -c >qgis-$release.0.tar.bz2" ) == 0 or die "git archive failed";
system( "md5sum qgis-$newmajor.$newminor.0.tar.bz2 >qgis-$release.0.tar.bz2.md5" ) == 0 or die "md5sum failed";

$newminor++;
run( "git archive --format tar --prefix=qgis-$version/ $reltag | bzip2 -c >qgis-$version.tar.bz2", "git archive failed" );
run( "md5sum qgis-$version.tar.bz2 >qgis-$version.tar.bz2.md5", "md5sum failed" );

unless( $dopoint ) {
$newminor++;

print "Updating master...\n";
run( "git checkout master", "checkout master failed" );
updateCMakeLists($newmajor,$newminor,0,"Master");
run( "cp /tmp/changelog debian", "restore changelog failed" );
run( "dch -r ''", "dch failed" );
run( "dch --newversion $newmajor.$newminor.0 'New development version $newmajor.$newminor after branch of $release'", "dch failed" );
run( "git commit -a -m 'Bump version to $newmajor.$newminor'", "bump version failed" );
}

print "Updating master...\n";
system( "git checkout master" ) == 0 or die "checkout master failed";
updateCMakeLists($newmajor,$newminor,"Master");
system( "cp /tmp/changelog debian" ) == 0 or die "restore changelog failed";
system("dch -r ''" ) == 0 or die "dch failed";
system( "dch --newversion $newmajor.$newminor.0 'New development version $newmajor.$newminor after branch of $release'" ) == 0 or die "dch failed";
system( "git commit -a -m 'Bump version to $newmajor.$newminor'" ) == 0 or die "bump version failed";
my $topush = ($dopoint ? "" : "master ") . "$relbranch $reltag";

print "Push dry-run...\n";
system( "git push -n origin master $relbranch $reltag" ) == 0 or die "git push -n failed";
run( "git push -n origin $topush", "push dry run failed" );
print "Now manually push and upload the tarballs :\n\tgit push origin $topush\n\trsync qgis-$version.tar.bz2* qgis.org:/var/www/downloads/\n\n";

print "Now manually push and upload the tarballs :\n\tgit push origin master $relbranch $reltag\n\trsync qgis-$release.0.tar.bz2* qgis.org:/var/www/downloads/\n\n";

=head1 NAME
release.pl - create a new release
=head1 SYNOPSIS
release.pl [options] releasename
release.pl {{-major|-minor} -releasename=releasename|-point}
Options:
-major=newmajor new major number for release (defaults to current major version number)
-minor=newminor new minor number for release (defaults to current minor + 1 or 0 when major version number was increased)
next master will become minor + 1
-major do a new major release
-minor do a new minor release
-point do a new point release
-releasename=name new release name for master/minor release
-dryrun just echo but don't run any commands
=cut

0 comments on commit 01066b6

Please sign in to comment.
You can’t perform that action at this time.