-
Notifications
You must be signed in to change notification settings - Fork 9
/
release.pl
executable file
·446 lines (364 loc) · 12.3 KB
/
release.pl
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#!/usr/bin/perl
#
# Release script
#
# This script can help with creating releases from git projects
# and also update debian packages if they are managed
# with git-buildpackage.
#
# Pragmas
use strict;
use warnings;
# Modules
use Getopt::Long;
use Cwd;
use File::Temp qw/tempdir/;
use Config::Std;
# Determine the name of the package
my $name = undef;
{
my @path = split(/\//, getcwd());
$name = $path[-1];
}
# Vars for config loading
my ( $conffile_used, @hooks, %hook, %config );
# Valid config file locations to try
my @conffile_locations = qw(
release.conf
/etc/release.conf
);
# Prepend config in users home dir (~/.release.conf)
unshift(@conffile_locations,$ENV{'HOME'}.'/.release.conf');
# Get Options
my ($opt_major, $opt_minor, $opt_version, $opt_local, $cmd, $changes_file, $dry, $verbose, $nobuild, $keyid, $nodeb, $jobs);
GetOptions(
'major!' => \$opt_major,
'minor!' => \$opt_minor,
'version=s' => \$opt_version,
'local' => \$opt_local,
'dry!' => \$dry,
'verbose+' => \$verbose,
'nobuild' => \$nobuild,
'nodeb' => \$nodeb,
'name=s' => \$name,
'keyid=s' => \$keyid,
'jobs|j=i' => \$jobs,
# shift removes name of the option (config) and leaves the value for unshift
# unshift prepends to the list of valid config files so it is tried first
'config=s' => sub { shift; unshift( @conffile_locations, @_ ); },
) or die("Usage: $0 [--major] [--minor] [--version=<V>] [--nobuild] [--name=<STR>] [--keyid=<KEY>] [--config=<CFG>]\n");
# Try all config file locations
foreach my $loc (@conffile_locations) {
if ( -r $loc ) {
$conffile_used = $loc;
read_config $loc => %config;
last;
}
}
$keyid = $keyid || $config{$name}{'keyid'} || $config{'default'}{'keyid'};
$nobuild = $nobuild || $config{$name}{'nobuild'} || $config{'default'}{'nobuild'};
$nodeb = $nodeb || $config{$name}{'nodeb'} || $config{'default'}{'nodeb'};
# Debian distributions to upload to (must be configured for dupload)
my @dists = qw(lenny squeeze);
# Git Destinations to push to
my @git_dests = qw();
if($config{'default'}{'dist'}) {
if(ref($config{'default'}{'dist'}) eq 'ARRAY') {
push(@dists, @{$config{'default'}{'dist'}});
} else {
push(@dists, $config{'default'}{'dist'});
}
}
if($config{$name}{'dist'}) {
if(ref($config{$name}{'dist'}) eq 'ARRAY') {
push(@dists, @{$config{$name}{'dist'}});
} else {
push(@dists, $config{$name}{'dist'});
}
}
if($config{'default'}{'git_dest'}) {
if(ref($config{'default'}{'git_dest'}) eq 'ARRAY') {
push(@git_dests, @{$config{'default'}{'git_dest'}});
} else {
push(@git_dests, $config{'default'}{'git_dest'});
}
}
if($config{$name}{'git_dest'}) {
if(ref($config{$name}{'git_dest'}) eq 'ARRAY') {
push(@git_dests, @{$config{$name}{'git_dest'}});
} else {
push(@git_dests, $config{$name}{'git_dest'});
}
}
die("Need name for this package!") unless $name;
# This script only works with Makefile built packages
# WARNING: The Makefile must recognize DESTDIR!
if(!-e "./Makefile") {
die("No Makefile found! You're in the wrong directory!\n");
}
# We can only build a .deb if there is prepared debian packaging dir
if(!-e "../../deb/$name/") {
warn("No Debian package dir found. Only creating release tar.gz.\n");
$nodeb = 1;
}
# Determine the current and next version of this package
my $preversion = `git tag | sort -V | tail -1`;
chomp($preversion);
my $version = undef;
if($opt_version) {
$version = $opt_version;
} elsif($opt_major) {
$version = inc_version($preversion, { 'Major' => 1, });
} elsif($opt_minor) {
$version = inc_version($preversion, { 'Minor' => 1, });
} else {
$version = inc_version($preversion);
}
print "$0\n";
print "\n";
print "Package: $name\n";
print "Previous-Version is: $preversion\n";
print "New-Version will be: $version\n";
print "\n";
# Abort if there are uncommited changes
# either in this repository ...
$cmd = 'git status | grep "nothing to commit" >/dev/null';
run_cmd($cmd);
# or the debian package repo
$cmd = 'cd ../../deb/'.$name.'/; git status | grep "nothing to commit" >/dev/null';
run_cmd($cmd) unless $nodeb;
# Do a testinstall to catch any Makefile errors
# create tempdir and perform DESTDIR=tmpdir fakeroot make install, continue on success
$cmd = "make clean";
run_cmd($cmd);
my $tempdir = tempdir( CLEANUP => 1, );
$cmd = "DESTDIR=$tempdir/ fakeroot make install";
run_cmd($cmd);
# automagically add mysqldiff!
# -- VBoxAdm: from the last version to the current release
&sql_diff($tempdir,'vboxadm');
# -- VDnsAdm: from the last version and from the powerdns vanilla schema
my $new_diff = &sql_diff($tempdir,'vdnsadm');
# if there is a new diff we need to do a vanilla diff, too
if($new_diff && -f $new_diff) {
my $new_vanilla_diff = "doc/vdnsadm/mysql/diffs/vanilla-diff-to-".$version.".sql";
$cmd = "mysqldiff doc/vdnsadm/mysql/powerdns-vanilla.sql doc/vdnsadm/mysql/vdnsadm-current.sql > $new_vanilla_diff";
run_cmd($cmd);
$cmd = "git add $new_vanilla_diff";
run_cmd($cmd);
}
# Increase Version number in Makefile
$cmd = 'sed -i "s/^VERSION = .*$/VERSION = '.$version.'/g" Makefile';
run_cmd($cmd);
# Commit the increased Version number
$cmd = 'git commit -a -m "Tag '.$version.'"';
# command may fail if sed didnt yield any changes
run_cmd($cmd, { MayFail => 1, });
# Tag the new release
$cmd = "git tag ".$version;
run_cmd($cmd);
# Push to origins
if(!$opt_local) {
for my $dest (@git_dests) {
$cmd = "git push $dest master";
run_cmd($cmd, { MayFail => 1, });
$cmd = "git push --tags $dest master";
run_cmd($cmd, { MayFail => 1, });
}
}
# Export tagged version from git
$cmd = "git archive --format=tar --prefix=$name-".$version."/ $version | gzip >../../deb/$name-".$version.".tar.gz";
run_cmd($cmd);
if($nodeb) {
print "No debian packaging found. Only prepared tar.gz\n";
exit 0;
}
# Go to debian package dir
chdir("../../deb/$name");
# Remove patches ...
$cmd = "rm -rf debian/patches";
run_cmd($cmd);
# Import new version
$cmd = "git-import-orig ../$name-".$version.".tar.gz";
run_cmd($cmd);
if($nobuild) {
print "Preparation for release of $version finished!\n";
exit 0;
}
# Tag new version
$cmd = "git-dch --release --new-version=${version}-1";
run_cmd($cmd);
# Remove patches ... again
$cmd = "rm -rf debian/patches/";
run_cmd($cmd);
# Remove .pc ...
$cmd = "rm -rf .pc/";
run_cmd($cmd);
# Commit changelog changes
$cmd = "git commit -a -m \"Tag ".$version."-1\"";
run_cmd($cmd);
# TODO can we test if any file which will be installed is in a .install file?
# Build the new package
$cmd = "git-buildpackage --git-tag --git-sign-tags";
if($keyid) {
$cmd .= " --git-keyid=".$keyid;
}
if($opt_local) {
$cmd = "QUICK_TEST=1 ".$cmd;
}
if($jobs) {
$cmd = 'DEB_BUILD_OPTIONS="parallel='.$jobs.'" '.$cmd;
}
run_cmd($cmd);
# .deb file will be placed one level above the package dir
chdir("..");
# Upload to reposity
if(!$opt_local) {
$changes_file = `ls ${name}_*.changes | grep "$version" | sort -n | tail -1`;
chomp($changes_file);
for my $dist (@dists) {
#$cmd = "dupload --force --to ".$dist." ".$changes_file;
$cmd = "reprepro -Vb /srv/data/public.packages/ include ".$dist." ".$changes_file;
run_cmd($cmd);
}
$cmd = "/srv/data/public.packages/rsync.sh";
run_cmd($cmd);
# TODO add to homepage
}
# clean up old package files
if(-d '../deb-archive') {
$cmd = "egrep \"(Package|Source):\" $name/debian/control | cut -d' ' -f2";
my @pkgs = `$cmd`;
foreach my $pkg (@pkgs) {
chomp($pkg);
#print "Package: $pkg\n";
my $glob1 = "./".$pkg."_*";
my $glob2 = "./".$pkg."-*";
#print "Glob: $glob\n";
foreach my $file (glob($glob1),glob($glob2)) {
#print "File: $file\n";
if($file =~ m/${pkg}_([0-9.]+)-/ || $file =~ m/$pkg-([0-9.]+)\.tar\.gz$/) {
my $ver = $1;
#print "Version: $ver\n";
if($ver ne $version) {
my $cmd = "mv $file ../deb-archive/";
print "Archiving old package file - CMD: $cmd\n";
my $rv = system($cmd) >> 8;
}
}
}
}
}
print "Release of $version finished!\n";
exit 0;
sub sql_diff {
my $tempdir = shift;
my $product = shift;
# Get the latest schema from the db
$cmd = "mysqldump --no-data --opt ".$product.q{ | sed 's/AUTO_INCREMENT=[0-9]*\b//' > }.$tempdir.'/'.$product."-current.sql";
run_cmd($cmd);
# see if there are any differences
$cmd = "mysqldiff doc/".$product."/mysql/".$product."-current.sql $tempdir/".$product."-current.sql > $tempdir/".$product."-diff.sql";
run_cmd($cmd);
# only create a diff if there are some changes (diff > 0 bytes)
if((stat("$tempdir/".$product."-diff.sql"))[7] > 0) {
my $new_diff = "doc/".$product."/mysql/diffs/schema-diff-$preversion-to-$version.sql";
$cmd = "mv $tempdir/".$product."-diff.sql ".$new_diff;
run_cmd($cmd);
# add to git
$cmd = "git add ".$new_diff;
run_cmd($cmd);
# move the latest schema to the repo if there were any changes
$cmd = "mv $tempdir/".$product."-current.sql doc/".$product."/mysql/".$product."-current.sql";
run_cmd($cmd);
return $new_diff;
}
return;
}
sub run_cmd {
my $cmd = shift;
my $opts = shift || {};
print "CMD: $cmd\n" if $verbose;
my $rv = 1;
$rv = system($cmd) >> 8 unless $dry;
if(!$dry && $rv != 0 && !$opts->{MayFail}) {
die("Command ($cmd) failed with non-zero exit status: $rv!\n");
} else {
return 1;
}
}
sub inc_version {
my $version = shift;
my $opts = shift || {};
# increase last part infinite until requested by switch
# no switch -> increase last part, tag
# --minor -> reset last part, increase middle part, create new branch, tag
# --major -> reset last two parts, increase first part, create new branch tag
# increase a three component version number
if($version && $version =~ m/^(\d+)\.(\d+)\.(\d+)$/) {
my ($major, $minor, $patch) = ($1, $2, $3);
$patch++;
if($opts->{Major}) {
$patch = 0;
$minor = 0;
$major++;
} elsif($opts->{Minor}) {
$patch = 0;
$minor++;
}
return "$major.$minor.$patch";
} else {
die "No three-part version string given. Aborting.\n";
}
}
__END__
=head1 NAME
release.pl - Tag and package releases
=head1 VERSION
This documentation refers to release.pl version 0.0.5.
=head1 USAGE
doc/release.pl
=head1 REQUIRED ARGUMENTS
None.
=head1 OPTIONS
Specifying neither major nor minor will increase the patch level, i.e. Z from X.Y.Z.
=head2 major
Increase major version number part, i.e. X from X.Y.Z.
=head2 minor
Increate minor version number part, i.e. Y from X.Y.Z.
=head2 version
Specify the new version manually. Be carefull not to give an existing version number!
=head2 local
Local Operation only. No git push or dupload.
=head2 dry
Dry mode. Only tell what would be done.
=head2 verbose
Increase verbosity.
=head2 nobuild
Do not build the debian package.
=head1 DESCRIPTION
Create a new relelase of the given application.
=head1 CONFIGURATION AND ENVIRONMENT
A full explanation of any configuration system(s) used by the application,
including the names and locations of any configuration files, and the
meaning of any environment variables or properties that can be set. These
descriptions must also include details of any configuration language used.
(See also "Configuration Files" in Chapter 19.)
=head1 DEPENDENCIES
File::Temp, Cwd, Getopt::Long.
=head1 INCOMPATIBILITIES
None known.
=head1 BUGS AND LIMITATIONS
There are no known bugs in this module.
Please report problems to Dominik Schulz (dominik.schulz@gauner.org)
Patches are welcome.
=head1 AUTHOR
Dominik Schulz (dominik.schulz@gauner.org)
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2010 Dominik Schulz (dominik.schulz@gauner.org). All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=cut