|
| 1 | +#!/usr/bin/perl |
| 2 | +# creates a new release |
| 3 | + |
| 4 | +# Copyright (C) 2014 Jürgen E. Fischer <jef@norbit.de> |
| 5 | + |
| 6 | +# This program is free software; you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation; either version 2 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | + |
| 11 | +use strict; |
| 12 | +use warnings; |
| 13 | +use Getopt::Long; |
| 14 | +use Pod::Usage; |
| 15 | + |
| 16 | +my $newmajor; |
| 17 | +my $newminor; |
| 18 | +my $releasename; |
| 19 | +my $help; |
| 20 | + |
| 21 | +my $result = GetOptions( |
| 22 | + "major" => \$newmajor, |
| 23 | + "minor" => \$newminor, |
| 24 | + "releasename=s" => \$releasename, |
| 25 | + "help" => \$help |
| 26 | + ); |
| 27 | + |
| 28 | +$releasename = shift @ARGV; |
| 29 | + |
| 30 | +pod2usage(1) if $help or !defined $releasename; |
| 31 | + |
| 32 | +my $major; |
| 33 | +my $minor; |
| 34 | +open F, "CMakeLists.txt"; |
| 35 | +while(<F>) { |
| 36 | + if(/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/) { |
| 37 | + $major = $1; |
| 38 | + } elsif(/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/) { |
| 39 | + $minor = $1; |
| 40 | + } |
| 41 | +} |
| 42 | +close F; |
| 43 | + |
| 44 | +if( defined $newmajor ) { |
| 45 | + die "New major must be equal or greater than old major $major" if $newmajor <= $major; |
| 46 | + $newminor = 0 unless defined $newminor; |
| 47 | +} else { |
| 48 | + $newmajor = $major; |
| 49 | +} |
| 50 | + |
| 51 | +if( defined $newminor ) { |
| 52 | + die "New minor must be greater than current minor $minor" if $newmajor==$major && $newminor<=$minor; |
| 53 | +} else { |
| 54 | + $newminor = $minor + 1; |
| 55 | +} |
| 56 | + |
| 57 | +sub updateCMakeLists { |
| 58 | + my($major,$minor,$release) = @_; |
| 59 | + |
| 60 | + rename "CMakeLists.txt", "CMakeLists.txt.orig" or die "cannot rename CMakeLists.txt: $!"; |
| 61 | + open I, "CMakeLists.txt.orig"; |
| 62 | + open O, ">CMakeLists.txt" or die "cannot create CMakeLists.txt: $!"; |
| 63 | + while(<I>) { |
| 64 | + s/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/SET(CPACK_PACKAGE_VERSION_MAJOR "$major")/; |
| 65 | + s/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/SET(CPACK_PACKAGE_VERSION_MINOR "$minor")/; |
| 66 | + s/SET\(RELEASE_NAME "(.+)"\)/SET(RELEASE_NAME "$release")/; |
| 67 | + print O; |
| 68 | + } |
| 69 | + close O; |
| 70 | + close I; |
| 71 | +} |
| 72 | + |
| 73 | +print "Last pull rebase...\n"; |
| 74 | +system("git pull --rebase") == 0 or die "git pull rebase failed"; |
| 75 | + |
| 76 | +my $release = "$newmajor.$newminor"; |
| 77 | +my $relbranch = "release-${newmajor}_${newminor}"; |
| 78 | + |
| 79 | +print "Creating branch...\n"; |
| 80 | +system("git checkout -b $relbranch" ) == 0 or die "git checkout release branch failed"; |
| 81 | +updateCMakeLists($newmajor,$newminor,$releasename); |
| 82 | + |
| 83 | +print "Updating branch...\n"; |
| 84 | +system("dch -r ''" ) == 0 or die "dch failed"; |
| 85 | +system( "dch --newversion $newmajor.$newminor.0 'Release of $release'" ) == 0 or die "dch failed"; |
| 86 | +system( "cp debian/changelog /tmp" ) == 0 or die "backup changelog failed"; |
| 87 | +system( "git commit -a -m 'Release of $release ($releasename)'" ) == 0 or die "release commit failed"; |
| 88 | + |
| 89 | +print "Producing archive...\n"; |
| 90 | +system( "git archive --format tar HEAD | bzip2 -c >qgis-$release.0.tar.bz2" ) == 0 or die "git archive failed"; |
| 91 | +system( "md5sum qgis-$newmajor.$newminor.0.tar.bz2 >qgis-$release.0.tar.bz2.md5" ) == 0 or die "md5sum failed"; |
| 92 | + |
| 93 | +$newminor++; |
| 94 | + |
| 95 | +print "Updating master...\n"; |
| 96 | +system( "git checkout master" ) == 0 or die "checkout master failed"; |
| 97 | +updateCMakeLists($newmajor,$newminor,"Master"); |
| 98 | +system( "cp /tmp/changelog debian" ) == 0 or die "restore changelog failed"; |
| 99 | +system("dch -r ''" ) == 0 or die "dch failed"; |
| 100 | +system( "dch --newversion $newmajor.$newminor.0 'New development version $newmajor.$newminor after branch of $release'" ) == 0 or die "dch failed"; |
| 101 | +system( "git commit -a -m 'Bump version to $newmajor.$newminor'" ) == 0 or die "bump version failed"; |
| 102 | + |
| 103 | +print "Push dry-run...\n"; |
| 104 | +system( "git push -n origin master $relbranch" ) == 0 or die "git push -n failed"; |
| 105 | + |
| 106 | +print "Now manually push and upload the tarballs :\n\tgit push origin master $relbranch\n\trsync qgis-$release.0.tar.bz2* qgis.org:/var/www/downloads/\n\n"; |
| 107 | + |
| 108 | +=head1 NAME |
| 109 | +
|
| 110 | +release.pl - create a new release |
| 111 | +
|
| 112 | +=head1 SYNOPSIS |
| 113 | +
|
| 114 | +release.pl [options] releasename |
| 115 | +
|
| 116 | + Options: |
| 117 | + -major=newmajor new major number for release (defaults to current major version number) |
| 118 | + -minor=newminor new minor number for release (defaults to current minor + 1 or 0 when major version number was increased) |
| 119 | + next master will become minor + 1 |
| 120 | +=cut |
0 commit comments