-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease-tool.pl
executable file
·1241 lines (978 loc) · 35.4 KB
/
release-tool.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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
# release-tool.pl - script to manage the Koha release process
#
# Copyright (C) 2012 C & P Bibliography Services
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# 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. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 NAME
release-tool.pl
=head1 SYNOPSIS
release-tool.pl
release-tool.pl --version 3.06.05
=head1 DESCRIPTION
This script takes care of most of the Koha release process, as it is
done by Jared Camins-Esakov and C & P Bibliography Services. This may
not perfectly meet the needs of other Release Maintainers and/or
organizations.
=cut
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Spec;
use File::Copy;
use Data::Dumper;
use File::Basename;
use File::Path qw/make_path remove_tree/;
use Term::ANSIColor;
use Time::HiRes qw/time/;
use POSIX qw/strftime ceil/;
use TAP::Harness;
use DBI;
use MIME::Lite;
use Template;
use Config::Simple;
use Net::OpenSSH;
$SIG{INT} = \&interrupt;
sub usage {
pod2usage( -verbose => 2 );
exit;
}
$| = 1;
$Term::ANSIColor::AUTORESET = 1;
my %defaults = (
alert => '',
autoversion => 0,
branch => '',
'build-result' => '',
clean => 0,
deploy => 0,
'email-file' => '',
errorlog => '',
kohaclone => '',
'maintainer-email' => '',
'maintainer-name' => '',
package => '',
'post-deploy-script' => [ '' ],
quiet => 0,
rnotes => '',
sign => 0,
since => '',
'skip-deb' => 0,
'skip-install' => 0,
'skip-marc21' => 0,
'skip-normarc' => 0,
'skip-pbuilder' => 0,
'skip-rnotes' => 0,
'skip-stats' => 0,
'skip-tests' => 0,
'skip-tgz' => 0,
'skip-unimarc' => 0,
'skip-webinstall' => 0,
stats => '',
tag => 0,
tarball => '',
'use-dist-rnotes' => 0,
verbose => 0,
version => '',
# database settings
database => $ENV{KOHA_DATABASE} || 'koha',
user => $ENV{KOHA_USER} || 'kohaadmin',
password => $ENV{KOHA_PASS} || 'katikoan',
# announcement settings
'email-template' => 'announcement.eml.tt',
'email-recipients' =>
'koha@lists.katipo.co.nz, koha-devel@lists.koha-community.org',
'email-subject' => "New Koha version",
'website-template' => 'announcement.html.tt',
);
my $deployed = 'no';
my $signed_tarball = 'no';
my $signed_packages = 'no';
my $tagged = 'no';
my $cleaned = 'no';
my $pushed = 'no';
my $skipped = '';
my $finished_tests = 'no';
my $built_tarball = 'no';
my $built_packages = 'no';
my $version_mismatch;
my $output;
my @tested_tarball_installs;
my @tested_package_installs;
my %cmdline;
my $config = new Config::Simple( syntax => 'http' );
my $log = '';
my $lxc_host = '';
=head2 General options
=over 8
=item B<--help>
Prints this help
=item B<--quiet, -q>
Don't display any status information while running. When specified
twice, also suppress the summary.
=item B<--verbose, -v>
Provide verbose diagnostic information
=item B<--config>
Read configuration settings from the specified file. Options set on the
command line will override options in the configuration file.
=back
=head2 Action control options
=over 8
=item B<--clean, -c>
Delete all the files created in the course of the test
=item B<--deploy, -d>
Deploy the package to the apt repository
=item B<--release>
Equivalent to I<--sign --deploy --tag --tarball=koha-${VERSION}.tar.gz>
=item B<--sign, -s>
Sign the tarball and package and tag (if created)
=item B<--tag, -g>
Tag the git repository
=item B<--push, -p>
Push the branch to the specified remote(s).
=item B<--skip-THING>
Most actions are performed automatically, unless the user requests that they
be skipped. Skip THING. Currently the following can be skipped:
=over 4
=item B<tests>
Unit tests
=item B<deb>
Debian package-related tasks
=item B<tgz>
Tarball-related tasks
=item B<install>
Installation-related tasks
=item B<marc21>
MARC21 instance installation
=item B<unimarc>
UNIMARC instance installation
=item B<normarc>
NORMARC instance installation
=item B<webinstall>
Running the webinstaller
=item B<pbuilder>
Updating the pbuilder environment
=item B<rnotes>
Generating release notes
=item B<stats>
Generating git statistics
=back
=back
=cut
=head2 Source description options
=over 8
=item B<--kohaclone, -k>
Kohaclone directory. Defaults to the current working directory
=item B<--branch>
The name of the git branch in use. Defaults to current git branch
=item B<--distribution>
The name of the distribution. Defaults to the current git branch
=item B<--version>
The version of Koha that is being created. Defaults to the version listed in
kohaversion.pl
=item B<--autoversion, -a>
Automatically include the git commit id and timestamp in the package version
=item B<--since>
Tag or commit from which to generate release notes and statistics. Defaults
to last tag on branch.
=back
=head2 Execution options
=over 8
=item B<--database>
Name of the MySQL database to use for tarball installs. Defaults to koharel
=item B<--user>
Name of the MySQL user for tarball installs. Defaults to koharel
=item B<--password>
Name of the MySQL password for tarball installs. Defaults to koharel
=item B<--maintainer-name>
The name of the maintainer. Defaults to global git config user.name
=item B<--maintainer-email>
The e-mail address of the maintainer. Defaults to the value of git config
--global user.email
=item B<--use-dist-rnotes>
Use the release notes included in the distribution. I<--rnotes> moust be
specified if this option is used.
=item B<--post-deploy-script>
Run the specified script at the end of the deploy phase with the summary
config file as an argument.
=back
=head2 Output options
=over 8
=item B<--build-result, -b>
Directory to put the output into. Defaults to ~/releases/[branch]/[version]
=item B<--errorlog>
File to store error information in. Defaults to [build-result]/errors.log
=item B<--rnotes, -r>
The name of the release notes file to generate or use (see I<--use-dist-rnotes>).
Defaults to [build-result]/release_notes.txt
=item B<--stats>
The base name of the files into which statistics should be placed.
Defaults to [build-result]/statistics (statistics will be generated
in .txt and .html format)
=item B<--tarball, -t>
The name of the tarball file to generate. Defaults to
[build-result]/koha-[branch]-[version].tar.gz
=item B<--alert>
E-mail address to which an an alert summarizing the result should be sent.
=item B<--email-template>
Template file for the release announcement e-mail. Defaults to
"announcement.eml.tt" in the same directory as this script
=item B<--bzlogin>
Your login on bugzilla. If provided, it will be used to retrieve
the comment 0 for each enhancement. This information will be
added in the release notes
=item B<--bzpassword>
Your password on bugzilla. Must be provided if you provide bzlogin
=back
=head2 Announcement options
=over 8
=item B<--email-recipients>
Who to generate the e-mail announcement for. Defaults to
"koha@lists.katipo.co.nz, koha-devel@lists.koha-community.org"
=item B<--email-subject>
Subject of the generated e-mail announcement. Defaults to "New Koha version"
=item B<--email-file>
File to store the generated e-mail announcement in. Defaults to
[build-result]/announcement.eml
=item B<--email-template>
Template file for the release announcement e-mail. Defaults to
"announcement.eml.tt" in the same directory as this script
=back
=cut
my $options = GetOptions(
\%cmdline,
# General options
'help|h', 'quiet|q+',
'verbose|v+', 'config=s',
# Action control options
'clean|c', 'deploy|d',
'push|p:s@', 'release',
'sign|s', 'tag|g',
'skip-tests',
'skip-deb', 'skip-tgz',
'skip-install', 'skip-marc21',
'skip-unimarc', 'skip-normarc',
'skip-webinstall', 'skip-pbuilder',
'skip-rnotes', 'skip-stats',
# Source description options
'version=s', 'autoversion|a',
'kohaclone|k=s',
'branch=s', 'since=s',
'distribution=s',
# Execution options
'database=s',
'user=s', 'password=s',
'use-dist-rnotes',
'maintainer-name=s', 'maintainer-email=s',
'post-deploy-script=s@',
# Output options
'build-result|b=s', 'errorlog=s',
'tarball|t=s', 'rnotes|r=s',
'stats=s', 'alert=s',
# Announcement options
'email-file=s',
'email-recipients=s', 'email-subject=s',
'email-template=s',
# Bugzilla options
'bzlogin:s','bzpassword:s',
);
binmode( STDOUT, ":utf8" );
if ( $cmdline{help} ) {
usage();
}
if ( defined( $cmdline{config} ) && -f File::Spec->rel2abs( $cmdline{config} ) )
{
$config->read( $cmdline{config} );
}
foreach my $key ( keys %defaults ) {
$config->param( $key, $defaults{$key} ) unless $config->param($key);
}
foreach my $key ( keys %cmdline ) {
$config->param( $key, $cmdline{$key} );
}
my $starttime = time();
chdir $config->param('kohaclone')
if ( $config->param('kohaclone') && -d $config->param('kohaclone') );
my $reltools = File::Spec->rel2abs( dirname(__FILE__) );
$config->param( 'kohaclone', File::Spec->rel2abs( File::Spec->curdir() ) )
unless ( $config->param('kohaclone') && -d $config->param('kohaclone') );
$ENV{PERL5LIB} = $config->param('kohaclone');
my @marcflavours;
push @marcflavours, 'MARC21' unless $config->param('skip-marc21');
push @marcflavours, 'UNIMARC' unless $config->param('skip-unimarc');
push @marcflavours, 'NORMARC' unless $config->param('skip-normarc');
set_default( 'branch', `git branch | grep '*' | sed -e 's/^* //'` );
my $dist = $config->param('branch');
$dist =~ s#[/_]#-#g;
set_default( 'distribution', $dist );
my $kohaversion = `grep 'VERSION = ' kohaversion.pl | sed -e "s/^[^']*'//" -e "s/';//"`;
set_default( 'version', $kohaversion );
set_default( 'maintainer-name', `git config --global --get user.name` );
set_default( 'maintainer-email', `git config --global --get user.email` );
set_default( 'build-result',
"$ENV{HOME}/releases/"
. $config->param('distribution') . '/'
. $config->param('version') );
make_path( $config->param('build-result') );
opendir( DIR, $config->param('build-result') );
while ( my $file = readdir(DIR) ) {
# We only want files
$file = $config->param('build-result') . "$file";
next unless ( -f $file );
unlink $file;
}
$ENV{TEST_QA} = 1;
if ( $config->param('tarball') =~ m#/# ) {
$config->param( 'tarball', '' )
unless ( -d dirname( $config->param('tarball') ) );
}
elsif ( $config->param('tarball') ) {
$config->param( 'tarball', build_result( $config->param('tarball') ) );
}
set_default( 'email-file', build_result('announcement.eml') );
set_default(
'tarball',
build_result(
'koha-'
. $config->param('distribution') . '-'
. $config->param('version')
. '.tar.gz'
)
);
set_default( 'rnotes', build_result('release_notes.txt') );
set_default( 'stats', build_result('statistics') );
my $lasttag = `git describe --abbrev=0`;
chomp $lasttag;
set_default( 'since', $lasttag );
set_default( 'errorlog', build_result('errors.log') );
unlink $config->param('tarball');
unlink $config->param('rnotes') unless $config->param('use-dist-rnotes');
unlink $config->param('errorlog');
print_log(
colored(
"Starting release test at "
. strftime( '%D %T', localtime($starttime) ),
'blue'
)
);
print_log( "\tBranch: "
. $config->param('branch')
. "\n\tDistribution: "
. $config->param('distribution')
. "\n\tVersion: "
. $config->param('version')
. "\n" );
unless ( index $config->param('version'), $kohaversion ) {
$version_mismatch = 1;
}
unless ( $config->param('skip-tests') ) {
tap_task(
"Running unit tests",
0,
undef,
tap_dir( $config->param('kohaclone') . '/t' ),
tap_dir( $config->param('kohaclone') . '/t/db_dependent' ),
tap_dir( $config->param('kohaclone') . '/t/db_dependent/Labels' ),
$config->param('kohaclone') . '/xt/author/icondirectories.t',
$config->param('kohaclone') . '/xt/author/podcorrectness.t',
$config->param('kohaclone') . '/xt/author/translatable-templates.t',
$config->param('kohaclone') . '/xt/author/valid-templates.t',
$config->param('kohaclone') . '/xt/permissions.t',
$config->param('kohaclone') . '/xt/single_quotes.t',
$config->param('kohaclone') . '/xt/tt_valid.t'
);
$finished_tests = 'yes';
}
unless ( $config->param('skip-deb') ) {
unless ( $config->param('skip-pbuilder') ) {
print_log("Updating pbuilder...");
run_cmd("sudo pbuilder update --keyring '$reltools/debian.koha-community.org.gpg' 2>&1");
warn colored( "Error updating pbuilder. Continuing anyway.",
'bold red' )
if ($?);
}
$ENV{DEBEMAIL} = $config->param('maintainer-email');
$ENV{DEBFULLNAME} = $config->param('maintainer-name');
my $extra_args = '';
$extra_args = ' --noautoversion' unless ( $config->param('autoversion') );
shell_task(
"Building packages",
"debian/build-git-snapshot --distribution="
. $config->param('distribution') . " -r "
. $config->param('build-result') . " -v "
. $config->param('version')
. "$extra_args 2>&1"
);
fail('Building package')
unless $output =~
m#^dpkg-deb: building package `koha-common' in `[^'`/]*/([^']*)'.$#m;
$config->param( 'package', build_result($1) );
fail('Building package') unless ( -f $config->param('package') );
$built_packages = 'yes';
}
unless ( $config->param('skip-tgz') ) {
print_log("Preparing release tarball...");
shell_task(
"Creating archive",
'git archive --format=tar --prefix=koha-'
. $config->param('version') . '/ '
. $config->param('branch')
. ' | gzip > '
. $config->param('tarball'),
1
);
$built_tarball = 'yes';
shell_task( "Signing archive", "gpg -sb " . $config->param('tarball'), 1 )
if ( $config->param('sign') );
shell_task(
"md5summing archive",
"md5sum "
. $config->param('tarball') . " > "
. $config->param('tarball') . ".MD5",
1
);
if ( $config->param('sign') ) {
shell_task( "Signing md5sum",
"gpg --clearsign " . $config->param('tarball') . ".MD5", 1 );
$signed_tarball = 'yes';
}
if ( $config->param('deploy') ) {
$config->param('staging', build_result('staging'));
mkdir $config->param('staging');
symlink $config->param('tarball'), $config->param('staging') . '/' . basename($config->param('tarball'));
symlink $config->param('tarball') . '.MD5', $config->param('staging') . '/' . basename($config->param('tarball') . '.MD5');
if ($signed_tarball) {
symlink $config->param('tarball') . '.MD5.asc', $config->param('staging') .'/' . basename($config->param('tarball') . '.MD5.asc');
symlink $config->param('tarball') . '.sig', $config->param('staging') .'/' . basename($config->param('tarball') . '.sig');
}
}
}
unless ( $config->param('skip-rnotes') || $config->param('use-dist-rnotes') ) {
print_log("Generating release notes...");
run_cmd(
"$reltools/get_bugs.pl -r "
. $config->param('rnotes') . " -t "
. $config->param('since') . " -v "
. $config->param('version')
.($config->param('bzlogin')?" -u ".$config->param('bzlogin')." -p ".$config->param('bzpassword'):"")
. " --verbose 2>&1"
);
warn colored( "Error generating release notes. Continuing anyway.",
'bold red' ) if ($?);
}
system('which gitdm 2>&1 > /dev/null');
$config->param('skip-stats', 1) if $?;
unless ( $config->param('skip-stats') ) {
shell_task(
"Generating statistics",
"git log -p -M " . $config->param('since')
. "..HEAD | gitdm -b $reltools -c $reltools/gitdm.config -u -s -a -o "
. $config->param('stats') . ".txt -h "
. $config->param('stats') . ".html 2>&1"
);
}
unless ( $config->param('skip-deb') || $config->param('skip-install') ) {
for my $flavour (@marcflavours) {
my $lflavour = lc $flavour;
print_log("Installing from package for $flavour...");
my ($lxc_ip, $ssh) = create_lxc();
ssh_task( $ssh, "Downloading package...", "wget -nv http://10.0.3.1" . $config->param('package') . ' 2>&1', '', 1 );
ssh_task( $ssh, "Installing package...", "sudo dpkg --no-debsig -i " . basename($config->param('package')) . ' 2>&1; sudo apt-get update; sudo apt-get -y -f --force-yes install 2>&1', '', 1 );
ssh_task( $ssh, "Running koha-create for $flavour",
"sudo koha-create --marcflavor=$lflavour --create-db pkgrel 2>&1", '',
1 );
print_log("Unable to run webinstaller for $flavour package due to Koha breakage") if (! $config->param('skip-webinstall'));
unless ( $config->param('skip-webinstall') || 1 ) {
my $pkg_user = $ssh->capture("sudo xmlstarlet sel -t -v 'yazgfs/config/user' '/etc/koha/sites/pkgrel/koha-conf.xml'");
my $pkg_pass = $ssh->capture("sudo xmlstarlet sel -t -v 'yazgfs/config/pass' '/etc/koha/sites/pkgrel/koha-conf.xml'");
chomp $pkg_user;
chomp $pkg_pass;
my $harness_args = {
test_args => [
"http://$lxc_ip:8080", "http://$lxc_ip",
"$flavour", "$pkg_user",
"$pkg_pass"
]
};
tap_task( "Running webinstaller for $flavour",
1, $harness_args, "$reltools/install-fresh.pl" );
push @tested_package_installs, $flavour;
}
clean_lxc();
$lxc_host = '';
}
}
if ( $config->param('sign') && !$config->param('skip-deb') ) {
shell_task( "Signing packages", "debsign " . build_result('*.changes') );
$signed_packages = 'yes';
}
if ( $config->param('deploy') && !$config->param('skip-deb') ) {
shell_task(
"Importing packages to apt repo",
"dput koha " . build_result('*.changes')
);
$deployed = 'yes';
}
unless ( $config->param('skip-tgz') || $config->param('skip-install') ) {
for my $flavour (@marcflavours) {
my $lflavour = lc $flavour;
print_log("Installing from tarball for $flavour...");
my ($lxc_ip, $ssh) = create_lxc();
my $subdir = 'koha-' . $config->param('version');
ssh_task( $ssh, "Downloading tarball...", "wget -nv http://10.0.3.1" . $config->param('tarball') . ' 2>&1', '', 1 );
ssh_task( $ssh, "Untarring tarball...", "tar zxvf " . basename($config->param('tarball')) . ' 2>&1', '', 1 );
ssh_task( $ssh, "Installing dependencies...", "sudo apt-get -y --force-yes install `cat install_misc/ubuntu.12.04.packages | grep install | sed -e 's/install\$//' | tr -d ' \\t' | tr '\\n' ' '` 2>&1", $subdir, 1 );
my $env_vars = "DB_HOST=localhost DB_NAME=" . $config->param('database') . " DB_USER=" . $config->param('user') . " DB_PASS=" . $config->param('password') . " ZEBRA_MARC_FORMAT=$lflavour PERL_MM_USE_DEFAULT=1";
ssh_task( $ssh, "Running perl Makefile.PL for $flavour",
"$env_vars perl Makefile.PL 2>&1", $subdir, 1 );
ssh_task( $ssh, "Running make for $flavour...", "make 2>&1", $subdir, 1 );
ssh_task( $ssh, "Rewriting Apache config for $flavour",
"sed -i -e 's/<VirtualHost 127.0.1.1:80>/<VirtualHost *:80>/' -e 's/<VirtualHost 127.0.1.1:8080>/<VirtualHost *:8080>/' blib/KOHA_CONF_DIR/koha-httpd.conf",
$subdir, 1 );
ssh_task( $ssh, "Running make test for $flavour...", "make test 2>&1", $subdir, 1 );
ssh_task( $ssh, "Running make install for $flavour...",
"sudo make install 2>&1", $subdir, 1 );
ssh_task( $ssh, "Linking and loading Apache site for $flavour...", "sudo ln -s /etc/koha/koha-httpd.conf /etc/apache2/sites-available/koha && sudo a2ensite koha && sudo apache2ctl restart", '', 1 );
print_log("Unable to run webinstaller for $flavour tarball due to Koha breakage") if (! $config->param('skip-webinstall'));
unless ( $config->param('skip-webinstall') || 1 ) {
my $harness_args = {
test_args => [
"http://$lxc_ip:8080", "http://$lxc_ip",
"$flavour", $config->param('user'),
$config->param('password')
]
};
tap_task( "Running webinstaller for $flavour",
1, $harness_args, "$reltools/install-fresh.pl" );
push @tested_tarball_installs, $flavour;
}
clean_lxc();
$lxc_host = '';
}
}
if ( $config->param('tag') ) {
my $tag_action = $config->param('sign') ? '-s' : '-a';
shell_task(
"Tagging current commit",
"git tag $tag_action -m 'Koha release "
. $config->param('version') . "' v"
. $config->param('version') . " 2>&1"
);
$tagged = 'yes';
}
generate_email() unless $config->param('skip-rnotes');
if ( defined $config->param('push') ) {
foreach my $target ($config->param('push')) {
if ( $target =~ m/^([^:]*):(.*)$/ ) {
shell_task( "Pushing to branch $2 on remote $1",
"git push $1 " . $config->param('branch') . ":$2" );
if ( $config->param('tag') ) {
shell_task( "Pushing tag to remote $1",
"git push $1 v" . $config->param('version') );
}
} else {
shell_task( "Pushing to default remote/branch",
"git push" );
if ( $config->param('tag') ) {
shell_task( "Pushing tag to default remote",
"git push v" . $config->param('version') );
}
}
}
$pushed = 'yes';
}
my $configfile = build_result('summary.cfg');
$config->write($configfile);
if ( $config->param('deploy') && $config->param('post-deploy-script') ) {
foreach my $script ($config->param('post-deploy-script')) {
shell_task( "Running post-deploy script",
$script . ' ' . $configfile );
}
}
if ( $config->param('clean') ) {
clean_lxc();
remove_tree( $config->param('build-result') );
$cleaned = 'yes';
}
success();
sub build_result {
my @components = @_;
my $path = $config->param('build-result');
foreach my $component (@components) {
$path .= "/$component";
}
return $path;
}
sub set_default {
my $key = shift;
my $value = shift;
chomp($value);
$config->param( $key, $value ) unless $config->param($key);
}
sub clean_lxc {
shell_task( "Shutting down lxc container...", "sudo lxc-stop -n $lxc_host", 1 ) if $lxc_host;
}
sub summary {
my ($capsule_summary) = @_;
my $endtime = time();
my $totaltime = ceil( ( $endtime - $starttime ) * 1000 );
$starttime = strftime( '%D %T', localtime($starttime) );
$endtime = strftime( '%D %T', localtime($endtime) );
my $skipped = '';
my $tested_tarball_install = 'no';
my $tested_package_install = 'no';
$tested_tarball_install = join( ', ', @tested_tarball_installs )
if ( scalar(@tested_tarball_installs) );
$tested_package_install = join( ', ', @tested_package_installs )
if ( scalar(@tested_package_installs) );
my %vars = $config->vars();
foreach my $key ( sort keys %vars ) {
if ( $key =~ m/^skip-([a-z]+)$/ ) {
$skipped .= ", $1" if ( $config->param($key) );
}
}
$skipped =~ s/^, //;
$skipped = 'none' unless $skipped;
$config->param( 'package', 'none' )
unless ( -s $config->param('package') && not $config->param('skip-deb') );
$config->param( 'tarball', 'none' )
unless ( -s $config->param('tarball') && not $config->param('skip-tgz') );
$config->param( 'rnotes', 'none' )
unless ( -s $config->param('rnotes')
&& not $config->param('skip-rnotes') );
return if $config->param('quiet') > 1;
my $branch = $config->param('branch');
my $distribution = $config->param('distribution');
my $version = $config->param('version');
my $maintainer =
$config->param('maintainer-name') . ' <'
. $config->param('maintainer-email') . '>';
my $tarball = $config->param('tarball');
my $package = $config->param('package');
my $rnotes = $config->param('rnotes');
my $stats = $config->param('stats');
my $emailfile = $config->param('email-file');
my $logfile = build_result('release-tool.log');
my $summary = <<_SUMMARY_;
$capsule_summary
Release test report
=======================================================
Branch: $branch
Distribution: $distribution
Version: $version
Maintainer: $maintainer
Run started at: $starttime
Run ended at: $endtime
Total run time: $totaltime ms
Skipped: $skipped
Finished tests: $finished_tests
Built packages: $built_packages
Tested package install: $tested_package_install
Deployed packages: $deployed
Signed packages: $signed_packages
Built tarball: $built_tarball
Tested tarball install: $tested_tarball_install
Signed tarball: $signed_tarball
Tagged git repository: $tagged
Pushed git branch: $pushed
Cleaned: $cleaned
Tarball file: $tarball
Package file: $package
Release notes: $rnotes
Statistics: $stats\[.txt/.html\]
E-mail file: $emailfile
Summary config file: $configfile
Log file: $logfile
_SUMMARY_
$summary .= colored( "Version mismatch between requested version " .
$config->param('version') . " and Koha version $kohaversion!", 'red' ) . "\n"
if $version_mismatch;
$summary .= $capsule_summary;
print $summary unless $config->param('quiet') > 1;
$log .= "\n$summary";
open my $logfh, '>', $logfile;
print $logfh $log;
close($logfh);
if ( $config->param('alert') ) {
$summary =~ s/\x1b\[[0-9]*m//g;
$summary .= "=======================================================\n\n";
my $msg = MIME::Lite->new(
From => $config->param('maintainer-email'),
To => $config->param('alert'),
Subject => 'Release tool completed',
Data => $summary,
Type => 'multipart/mixed'
);
$msg->attach(
Type => 'text/plain',
Data => $summary
);
$log =~ s/\x1b\[[0-9]*m//g;
$msg->attach(
Type => 'text/plain',
Data => $log,
Filename => 'release-tool.log'
);
$msg->send;
}
}
sub success {
summary(colored( "Successfully finished release test", 'green' ) . "\n");
exit 0;
}
sub fail {
my $component = shift;
my $callback = shift;
summary(colored( $component, 'bold red' ) . ' ' .
colored( " failed in release test", 'red' ) . "\n");
if ($output) {
open( my $errorlog, ">", $config->param('errorlog') )
or die "Unable to open error log for writing";
print $errorlog $output;
close($errorlog);
}
print colored( "Error report at " . $config->param('errorlog'), 'red' ),
"\n"
unless $config->param('quiet') > 1;
$callback->() if ( ref $callback eq 'CODE' );
exit 1;
}
sub print_log {
$log .= join(' ', @_) . "\n";
print @_, "\n" unless $config->param('quiet');
}
sub tap_dir {
my $directory = shift;
my @tests;
opendir( DIR, $directory );
while ( my $file = readdir(DIR) ) {
# We only want files
next unless ( -f "$directory/$file" );
# Use a regular expression to find files ending in .t
next unless ( $file =~ m/\.t$/ );
push @tests, "$directory/$file";
}
return sort @tests;
}
sub create_lxc {
# Sorry, creating the lxc container sucks. Deal with it.
print_log(" Creating lxc container...");
my $command = "sudo lxc-start-ephemeral -d -o ubuntu";
$log .= "> $command\n";
print colored( "> $command\n", 'cyan' )
if ( $config->param('verbose') >= 1 );
my $pid = open( my $outputfh, "-|", "$command" )