3 # Copyright 2010 Catalyst IT Ltd.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 # Written by Robin Sheat <robin@catalyst.net.nz>
21 # Based on an sh version by Lars Wirzenius.
27 use POSIX qw/strftime/;
30 my $distribution='squeeze-dev';
32 my $version='3.3-1~git';
38 'buildresult|r=s' => \$buildresult,
39 'distribution|D=s' => \$distribution,
40 'git-checks|g=s' => \$git_checks,
41 'version|v=s' => \$version,
42 'autoversion!' => \$auto_version,
43 'help|h' => \$need_help,
47 help_and_exit() if $need_help;
50 sub sys_command_output {
53 print "$command\n" if $debug;
54 open COMMAND, "$command |"
55 or die qq{Cannot execute "$command": $!"};
56 return map { chomp; $_ } <COMMAND>;
59 sub everything_is_committed {
70 and $filter = "normal",
73 help_and_exit("$0: --git-checks/-g must be one of 'all', 'modified', or 'none'");
75 my $has_changes = grep /^xxx/, sys_command_output("git status --porcelain -u${filter}");
86 This builds Koha deb packages, from a git snapshot. It's not suitable for
87 making upstreamable verions, but handy for your own local packages.
91 the location that the resulting .deb, .changes, etc. will be placed in.
92 Default is whatever pdebuild uses.
94 the distribution value to set in the changelog when editing it. Default
97 what level of git checks are run to determine if the working copy is
98 clean enough. One of 'all' (any changes are bad), 'modified' (only
99 tracked files with untracked changes will cause an error), and 'none'
100 (checking git status is skipped totally.) Default is 'all'.
102 the version string for the resulting package. Default is '3.3-1~git'.
104 whether or not to use the date and git commit ID in the version value.
105 Default is to include it.
112 return sys_command_output("git rev-parse --short=8 HEAD");
115 sub adjust_debian_changelog {
116 my ($newversion) = @_;
118 sys_command_output( qq{dch --force-distribution -D "$distribution" -v "$newversion" "Building git snapshot."} );
119 sys_command_output( qq{dch -r "Building git snapshot."} );
122 sub reset_debian_changelog {
123 sys_command_output( qq{git checkout -- debian/changelog} );
127 my ($newversion) = @_;
128 sys_command_output( qq{git archive --format=tar --prefix="koha-$newversion/" HEAD | gzip -9 > "../koha_$newversion.tar.gz"} );
130 my $pdebuildopts = $buildresult ? "--buildresult $buildresult" : "";
131 sys_command_output( "pdebuild $pdebuildopts" );
134 everything_is_committed() or die "cannot build: uncommited changes";
136 my $newversion = $auto_version
137 ? sprintf ('%s%s.%s', $version, strftime("+%Y%m%d%H%M%S", localtime), latest_sha1())
140 adjust_debian_changelog( $newversion );
141 build_package( $newversion );
142 reset_debian_changelog();