<commit_before>#!/usr/bin/perl
#
# Simple Daily build script
#
# - make a fresh checkout of pathvisio-trunk in a temp dir
# - compile v1 and v2, check for errors
# - run unit tests
# - if a step goes wrong, send email
#
# Note: this script needs to be run by the user that has
# passwordless ssh access to the target site
#
# If you want to run this from anacron, you'll have to
# make sure root has a key that is on .authorized_hosts on the target
# Pay attention to this, scp fails if you need to enter a password!
#

use warnings;
use strict;

###############
#   globals
###############

use File::Temp qw / tempfile tempdir /;
use File::Find;

# If $fCleanCheckout == 1, svn checkout will be done in a fresh temp directory.
# If $fCleanCheckout == 0, svn checkout will be done in $defaultDir.
my $fCleanCheckout = 0;

# these people will be emailed when a problem occurs
my @emails = (
    '<EMAIL>', 
#    '<EMAIL>',    
#    '<EMAIL>',
    );

my @steps;

# if fSendEmail is false, the email will not be sent but
# displayed on the screen

my $fSendEmail = 1;

my $basedir = "/home/martijn";
my $cytoscapedir= "$basedir/etc/cytoscape-v2.6.0";
my $fnCheckstyle = "$basedir/cs_pathvisio.txt";
my $defaultDir = "$basedir/temp";

# checkout dir
my $dir;

#################
# initialization
#################

if ($fCleanCheckout)
{
	$dir = tempdir ( CLEANUP => 1 );
}
else
{
	$dir = $defaultDir;
	
	mkdir $dir; # make sure dir exists
	
	# clean the working copy if we can. Ignore failure, we'll do a checkout anyway.
	system ("svn-clean $dir");
}

print "Location: $dir\n";

#################
#  subroutines
#################

# do step is used to break the daily build in logical steps
# each step has a name, an action and possibly a log file.
# do_step dies if the action fails, but not before adding the result to the 
# @steps array
sub do_step
{
	my %args = @_;
	
	eval {
		&{$args{action}}();
	};

	my $error = $@;
	my $result =
		{
			name => $args{name},
			log => $args{log},
			status => ($error ? "FAILURE" : "SUCCESS"),
			error => $error,
		};
	
	push @steps, $result;
		
	#die on error
	if ($error)
	{
		die $error;
	}	
}

##################
#  main
##################

# in the eval below, each step is done consecutively until 
# one step dies, which causes a break out of the eval statement.
eval
{	
	# create a temp dir and do a fresh checkout
	chdir ($dir);

	# First step: do a fresh checkout
	do_step ( 
		name => "SVN CHECKOUT",
		log => "$dir/svnerr.txt",
		action => sub
		{
			# For some reason, our svn server sometimes fails on the first attempt but then works fine afterwards.
			# So if it fails, retry a few times
			my $retries = 5;
			my $fail_delay = 5;
			my $i = 0;
			unlink "$dir/svnerr.txt";
			while (1)
			{
				$i++;

				eval {
					system ("svn checkout http://svn.bigcat.unimaas.nl/pathvisio/trunk . 2>>$dir/svnerr.txt") == 0
						or die "svn checkout failed: $?";
				};
				unless ($@) { last; } # break if success
				if ($i == $retries)
				{
					die ("svn checkout failed after $i attempts\n");
				}
				print "SVN co failed, trying again...\n";
				sleep ($fail_delay);
			}
		}
	);

	# Next step: compile the main project
	do_step (
		name => "COMPILE ALL",
		log => "$dir/compile1.txt",
		action => sub
		{
			# compile
			system ("ant all > $dir/compile1.txt") == 0 or 
				die ("compile all failed with error code ", $? >> 8, "\n");
		}
	);

	# Next step: compile the webservice client library
	do_step (
		name => "COMPILE WEBSERVICE CLIENT LIB",
		log => "$dir/compile-wpc.txt",
		action => sub
		{
			# compile
			system ("ant jar-wpclient " . 
				"-Dwsdl.url=http://192.168.127.12/wikipathways-test/wpi/webservice/webservice.php?wsdl " .
				"> $dir/compile-wpc.txt") == 0 or 
				die ("compile webservice client lib failed with error code ", $? >> 8, "\n");
		}
	);

	# Next step: do all JUnit unit tests
	do_step (
		name => "JUNIT TEST",
		log => "$dir/junit.txt",
		action => sub
		{
			system ("ant test > $dir/junit.txt") == 0 or 
				die ("test failed with error code ", $? >> 8, "\n");
		}
	);

	# Next step: ogretest (test dependencies of core)
	do_step (
		name => "OGRETEST",
		log => "$dir/ogretest.txt",<commit_msg>Adjusted daily build script to new wp server location<commit_after>#!/usr/bin/perl
#
# Simple Daily build script
#
# - make a fresh checkout of pathvisio-trunk in a temp dir
# - compile v1 and v2, check for errors
# - run unit tests
# - if a step goes wrong, send email
#
# Note: this script needs to be run by the user that has
# passwordless ssh access to the target site
#
# If you want to run this from anacron, you'll have to
# make sure root has a key that is on .authorized_hosts on the target
# Pay attention to this, scp fails if you need to enter a password!
#

use warnings;
use strict;

###############
#   globals
###############

use File::Temp qw / tempfile tempdir /;
use File::Find;

# If $fCleanCheckout == 1, svn checkout will be done in a fresh temp directory.
# If $fCleanCheckout == 0, svn checkout will be done in $defaultDir.
my $fCleanCheckout = 0;

# these people will be emailed when a problem occurs
my @emails = (
    '<EMAIL>', 
#    '<EMAIL>',    
#    '<EMAIL>',
    );

my @steps;

# if fSendEmail is false, the email will not be sent but
# displayed on the screen

my $fSendEmail = 1;

my $basedir = "/home/martijn";
my $cytoscapedir= "$basedir/etc/cytoscape-v2.6.0";
my $fnCheckstyle = "$basedir/cs_pathvisio.txt";
my $defaultDir = "$basedir/temp";

# checkout dir
my $dir;

#################
# initialization
#################

if ($fCleanCheckout)
{
	$dir = tempdir ( CLEANUP => 1 );
}
else
{
	$dir = $defaultDir;
	
	mkdir $dir; # make sure dir exists
	
	# clean the working copy if we can. Ignore failure, we'll do a checkout anyway.
	system ("svn-clean $dir");
}

print "Location: $dir\n";

#################
#  subroutines
#################

# do step is used to break the daily build in logical steps
# each step has a name, an action and possibly a log file.
# do_step dies if the action fails, but not before adding the result to the 
# @steps array
sub do_step
{
	my %args = @_;
	
	eval {
		&{$args{action}}();
	};

	my $error = $@;
	my $result =
		{
			name => $args{name},
			log => $args{log},
			status => ($error ? "FAILURE" : "SUCCESS"),
			error => $error,
		};
	
	push @steps, $result;
		
	#die on error
	if ($error)
	{
		die $error;
	}	
}

##################
#  main
##################

# in the eval below, each step is done consecutively until 
# one step dies, which causes a break out of the eval statement.
eval
{	
	# create a temp dir and do a fresh checkout
	chdir ($dir);

	# First step: do a fresh checkout
	do_step ( 
		name => "SVN CHECKOUT",
		log => "$dir/svnerr.txt",
		action => sub
		{
			# For some reason, our svn server sometimes fails on the first attempt but then works fine afterwards.
			# So if it fails, retry a few times
			my $retries = 5;
			my $fail_delay = 5;
			my $i = 0;
			unlink "$dir/svnerr.txt";
			while (1)
			{
				$i++;

				eval {
					system ("svn checkout http://svn.bigcat.unimaas.nl/pathvisio/trunk . 2>>$dir/svnerr.txt") == 0
						or die "svn checkout failed: $?";
				};
				unless ($@) { last; } # break if success
				if ($i == $retries)
				{
					die ("svn checkout failed after $i attempts\n");
				}
				print "SVN co failed, trying again...\n";
				sleep ($fail_delay);
			}
		}
	);

	# Next step: compile the main project
	do_step (
		name => "COMPILE ALL",
		log => "$dir/compile1.txt",
		action => sub
		{
			# compile
			system ("ant all > $dir/compile1.txt") == 0 or 
				die ("compile all failed with error code ", $? >> 8, "\n");
		}
	);

	# Next step: compile the webservice client library
	do_step (
		name => "COMPILE WEBSERVICE CLIENT LIB",
		log => "$dir/compile-wpc.txt",
		action => sub
		{
			# compile
			system ("ant jar-wpclient " . 
				"-Dwsdl.url=http://172.16.58.3/wikipathways-test/wpi/webservice/webservice.php?wsdl " .
				"> $dir/compile-wpc.txt") == 0 or 
				die ("compile webservice client lib failed with error code ", $? >> 8, "\n");
		}
	);

	# Next step: do all JUnit unit tests
	do_step (
		name => "JUNIT TEST",
		log => "$dir/junit.txt",
		action => sub
		{
			system ("ant test > $dir/junit.txt") == 0 or 
				die ("test failed with error code ", $? >> 8, "\n");
		}
	);

	# Next step: ogretest (test dependencies of core)
	do_step (
		name => "OGRETEST",
		log => "$dir/ogretest.txt",
{'fraction_non_alphanumeric': 0.16379821958456972, 'fraction_numerical': 0.007952522255192879, 'mean_word_length': 3.0451272203552566, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '921011', 'n_tokens_mistral': 3267, 'n_tokens_neox': 2919, 'n_words': 1033}