#!/usr/local/bin/perl -w use strict; use lib $ENV{LIBS}; use Cwd; use Getopt::Long; use DBExtensions; use Utilities::Mail; use constant RECIPIENTS => ('david.marshall@enews.com'); my $dirname = "/var/tmp/mongocheck.$$"; my $module = '6.3'; my $oldpwd = cwd; my @outcomes; my $ignore_database; GetOptions('no-database' => \$ignore_database); unless (@ARGV == 1) { print STDERR "usage: $0 release-name\n"; exit 1; } my $Database = DBExtensions::login('DB_DEV1') unless $ignore_database; if (!$ignore_database && defined (my $check = $Database->ct_sql_0or1("select compiles_ok, compile_time from enews..backend_releases where release_tag = '$ARGV[0]'"))) { printf "$ARGV[0] was checked on $check->[1] with a result of %s\n", ($check->[0] eq 'Y') ? 'PASSED' : 'FAILED'; exit; } mkdir $dirname, 0700 or die "Cannot create directory $dirname"; chdir $dirname or die "Cannot chdir to $dirname"; system("/usr/local/bin/cvs -Q export -r $ARGV[0] $module > /dev/null") == 0 || die "Unable to do a cvs export: $?"; chdir $module or die "Cannot chdir to $dirname/$module"; for (glob "*.pl") { -x $_ || push @outcomes, "$_ is not executable!"; system("perl -c $_") && push @outcomes, "$_ does not compile!"; } chdir 'lib' or die "Cannot chdir to $dirname/$module/lib"; check_modules('.'); my $status = @outcomes ? 'N' : 'Y'; $Database->ct_sql("insert into enews..backend_releases (release_tag, compiles_ok) values ('$ARGV[0]', '$status')") unless $ignore_database; if (@outcomes) { push @outcomes, "Check of $ARGV[0] FAILED"; } else { push @outcomes, "Check of $ARGV[0] PASSED"; } my $recipients = join ',' => RECIPIENTS; local $" = "\n"; my $mail =< To: $recipients Subject: Compilation Check for $ARGV[0] @outcomes EOF Utilities::Mail::send($recipients, $mail); END { chdir $oldpwd; system("/bin/rm -rf $dirname") == 0 || warn "Unable to remove $dirname, please do the needful"; } sub check_modules { local *LIBDIR; opendir LIBDIR, my $dir = shift; for (grep !/^\./, readdir LIBDIR) { # paymentplus directories have to be checked slightly differently, must chdir to them directly if (-d && /^paymentplus/) { my $module_dir = cwd; chdir "$dir/$_" or die "Cannot chdir to $dir/$_"; check_modules('.'); chdir $module_dir or die "Cannot chdir to $module_dir"; } elsif (-d) { check_modules("$dir/$_"); } elsif (/\.pm$/) { system("perl -c $dir/$_") && push @outcomes, "$_ does not compile!"; } } closedir LIBDIR; }