<commit_before>#! /usr/bin/perl -w

use strict;
use warnings;

BEGIN {
  push @INC, "./modules";
}

use Integration;
use Integration::Task::Copy;
use Integration::Task::Checkout;
use Integration::Task::Move;
use Integration::Task::Mkdir;
use Integration::Task::Delete;
use Integration::Task::Test::Ping;
use YAML qw(LoadFile);
use Carp;

my $config_file = "./checkout/sanger-plugins/head/conf/deploy.yml"; 
my $config = undef;
if (-e $config_file) {
  $config = LoadFile($config_file);
} else {
  croak "Error opening config file: $config_file\n $!";
}

my $checkout_location = $config->{checkout_location}; 
my $htdocs_location = $config->{htdocs_location}; 
my $cvs_repository = $config->{repository}; 
my $cvs_root = $config->{root}; 
my $cvs_username = $config->{username}; 
my $log_location = $config->{log_location}; 
my $proxy = $config->{proxy}; 
my $server = $config->{server}; 

my $integration = Integration->new(( 
                                    htdocs => $htdocs_location,
                                    log_location => $log_location
                                  ));

if (-e $checkout_location) {
  my $rm = `rm -r $checkout_location*`;
}

if (-e 'bioperl') {
  my $rm = `rm -r bioperl*`;
}

if (-e 'biomart') {
  my $rm = `rm -r biomart*`;
}

my $checkout_task = Integration::Task::Checkout->new((
                              destination => "checkout",
                              repository  => "cvs.sanger.ac.uk",
                              root        => "/nfs/ensembl/cvsroot/",
                              username    => "mw4",
                              name        => "checkout"
                           ));

$checkout_task->add_module('ensembl-website');
$checkout_task->add_module('ensembl-api');
$checkout_task->add_module('sanger-plugins');

$integration->add_checkout_task($checkout_task);

my $mart_task = Integration::Task::Checkout->new((
                              destination => "biomart",
                              repository  => "cvs.sanger.ac.uk",
                              root        => "/nfs/ensembl/cvsroot/",
                              username    => "mw4",
                              release     => "release-0_4",
                              name        => "biomart"
                           ));

$mart_task->add_module('biomart-plib');
$mart_task->add_module('biomart-web');

$integration->add_checkout_task($mart_task);

$integration->add_checkout_task(Integration::Task::Copy->new((
                                     source      => "biomart/biomart-plib",
                                     destination => "checkout/biomart-plib" 
                                     ))
                               );

$integration->add_checkout_task(Integration::Task::Copy->new((
                                     source      => "biomart/biomart-web",
                                     destination => "checkout/biomart-web" 
                                     ))
                               );

my $bioperl_task = Integration::Task::Checkout->new((
                                     destination => "bioperl",
                                     repository  => "cvs.open-bio.org",
                                     root        => "/home/repository/bioperl",
                                     username    => "cvs",
                                     protocol    => "pserver",
                                     name        => "bioperl"
                                   ));

$bioperl_task->add_module('bioperl-live');
$integration->add_checkout_task($bioperl_task);

$integration->add_checkout_task(Integration::Task::Move->new((
                                     source      => "bioperl",
                                     destination => "checkout/bioperl-live" 
                                     ))
                               );

$integration->checkout;

my $copy_task = Integration::Task::Copy->new((
                             source      => "support/Plugins.pm", 
                             destination => "checkout/conf"
                           ));

my $apache_copy_task = Integration::Task::Copy->new((
                             source      => "/ensemblweb/head/src", 
                             destination => "checkout/src"
                           ));

$integration->add_configuration_task($copy_task);
$integration->add_configuration_task($apache_copy_task);
$integration->add_configuration_task(Integration::Task::Mkdir->new((source => "checkout/img")));
$integration->add_configuration_task(Integration::Task::Mkdir->new((source => "checkout/logs")));
$integration->add_configuration_task(Integration::Task::Mkdir->new((source => "checkout/tmp")));

my $rollback_task = Integration::Task::Rollback->new((
                             source      => "/ensemblweb/head/checkout"
                           ));

$integration->add_configuration_task($rollback_task);

my $checkout_copy_task = Integration::Task::Copy->new((
                             source      => "checkout", 
                             destination => "/ensemblweb/head"
                           ));

$integration->add_configuration_task($checkout_copy_task);

$integration->stop_command('/ensemblweb/head/checkout/ctrl_scripts/stop_server');
$integration->stop_server;

$integration->configure;

$integration->start_command('/ensemblweb/head/checkout/ctrl_scripts/start_server');
$integration->start_server;

my $server_up_test = Integration::Task::Test::Ping->new((
                                               target   => $server,
                                               proxy    => $proxy,
                                               search   => "Mammalian genomes",
                                               name     => "Server start",
                                               critical => "yes"
                                                       ));

$integration->add_test_task($server_up_test);

$integration->test;

if ($integration->critical_fail) {
  warn "CRITICAL FAILURE: " . $integration->test_result . "% pass rate";
  $integration->stop_server;
  $rollback_task->rollback;
  $integration->start_server;
}

if ($integration->test_result < 100) {
  warn "TESTS FAILED: " . $integration->test_result . "% pass rate";
}


$integration->generate_output;
<commit_msg>Updated deploy script with new rollback support.<commit_after>#! /usr/bin/perl -w

use strict;
use warnings;

BEGIN {
  push @INC, "./modules";
}

use Integration;
use Integration::Task::Copy;
use Integration::Task::Checkout;
use Integration::Task::Move;
use Integration::Task::Mkdir;
use Integration::Task::Delete;
use Integration::Task::Rollback;
use Integration::Task::Test::Ping;
use YAML qw(LoadFile);
use Carp;

my $config_file = "./checkout/sanger-plugins/head/conf/deploy.yml"; 
my $config = undef;
if (-e $config_file) {
  $config = LoadFile($config_file);
} else {
  croak "Error opening config file: $config_file\n $!";
}

my $checkout_location = $config->{checkout_location}; 
my $htdocs_location = $config->{htdocs_location}; 
my $cvs_repository = $config->{repository}; 
my $cvs_root = $config->{root}; 
my $cvs_username = $config->{username}; 
my $log_location = $config->{log_location}; 
my $proxy = $config->{proxy}; 
my $server = $config->{server}; 

my $integration = Integration->new(( 
                                    htdocs => $htdocs_location,
                                    log_location => $log_location
                                  ));

if (-e $checkout_location) {
  my $rm = `rm -r $checkout_location*`;
}

if (-e 'bioperl') {
  my $rm = `rm -r bioperl*`;
}

if (-e 'biomart') {
  my $rm = `rm -r biomart*`;
}

my $checkout_task = Integration::Task::Checkout->new((
                              destination => "checkout",
                              repository  => "cvs.sanger.ac.uk",
                              root        => "/nfs/ensembl/cvsroot/",
                              username    => "mw4",
                              name        => "checkout"
                           ));

$checkout_task->add_module('ensembl-website');
$checkout_task->add_module('ensembl-api');
$checkout_task->add_module('sanger-plugins');

$integration->add_checkout_task($checkout_task);

my $mart_task = Integration::Task::Checkout->new((
                              destination => "biomart",
                              repository  => "cvs.s<EMAIL>",
                              root        => "/nfs/ensembl/cvsroot/",
                              username    => "mw4",
                              release     => "release-0_4",
                              name        => "biomart"
                           ));

$mart_task->add_module('biomart-plib');
$mart_task->add_module('biomart-web');

$integration->add_checkout_task($mart_task);

$integration->add_checkout_task(Integration::Task::Copy->new((
                                     source      => "biomart/biomart-plib",
                                     destination => "checkout/biomart-plib" 
                                     ))
                               );

$integration->add_checkout_task(Integration::Task::Copy->new((
                                     source      => "biomart/biomart-web",
                                     destination => "checkout/biomart-web" 
                                     ))
                               );

my $bioperl_task = Integration::Task::Checkout->new((
                                     destination => "bioperl",
                                     repository  => "cvs.open-bio.org",
                                     root        => "/home/repository/bioperl",
                                     username    => "cvs",
                                     protocol    => "pserver",
                                     name        => "bioperl"
                                   ));

$bioperl_task->add_module('bioperl-live');
$integration->add_checkout_task($bioperl_task);

$integration->add_checkout_task(Integration::Task::Move->new((
                                     source      => "bioperl",
                                     destination => "checkout/bioperl-live" 
                                     ))
                               );

$integration->checkout;

my $rollback_task = Integration::Task::Rollback->new((
                             source      => "/ensemblweb/head/checkout",
                             prefix      => "rollback_"
                           ));

$integration->add_rollback_task($rollback_task);

my $copy_task = Integration::Task::Copy->new((
                             source      => "support/Plugins.pm", 
                             destination => "checkout/conf"
                           ));

my $apache_copy_task = Integration::Task::Copy->new((
                             source      => "/ensemblweb/head/src", 
                             destination => "checkout/src"
                           ));

$integration->add_configuration_task($copy_task);
$integration->add_configuration_task($apache_copy_task);
$integration->add_configuration_task(Integration::Task::Mkdir->new((source => "checkout/img")));
$integration->add_configuration_task(Integration::Task::Mkdir->new((source => "checkout/logs")));
$integration->add_configuration_task(Integration::Task::Mkdir->new((source => "checkout/tmp")));

my $checkout_copy_task = Integration::Task::Copy->new((
                             source      => "checkout", 
                             destination => "/ensemblweb/head"
                           ));

$integration->add_configuration_task($checkout_copy_task);

$integration->stop_command('/ensemblweb/head/checkout/ctrl_scripts/stop_server');
$integration->stop_server;

$integration->configure;

$integration->start_command('/ensemblweb/head/checkout/ctrl_scripts/start_server');
$integration->start_server;

my $server_up_test = Integration::Task::Test::Ping->new((
                                               target   => $server,
                                               proxy    => $proxy,
                                               search   => "Mammalian genomes",
                                               name     => "Server start",
                                               critical => "yes"
                                                       ));

$integration->add_test_task($server_up_test);

$integration->test;

if ($integration->critical_fail) {
  warn "CRITICAL FAILURE: " . $integration->test_result . "% pass rate";
  $integration->rollback;
} else {
  $rollback_task->purge;
}

if ($integration->test_result < 100) {
  warn "TESTS FAILED: " . $integration->test_result . "% pass rate";
}

$integration->generate_output;
$integration->update_log;
{'fraction_non_alphanumeric': 0.13419506462984723, 'fraction_numerical': 0.0010967489228358794, 'mean_word_length': 1.5748285599031868, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 201, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 74, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '636975', 'n_tokens_mistral': 3560, 'n_tokens_neox': 3354, 'n_words': 511}