Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Daenks/Meridian59_103
Browse files Browse the repository at this point in the history
  • Loading branch information
Daenks committed Jul 13, 2014
2 parents a22ecb2 + ebc36ff commit 8ba5926
Show file tree
Hide file tree
Showing 14 changed files with 469 additions and 90 deletions.
21 changes: 21 additions & 0 deletions qbscripts/CheckHaveBranch.pl
@@ -0,0 +1,21 @@
#CheckHaveBranch.pl

#use strict;
use warnings;
use LWP::Simple;
use Getopt::Long;
use Pithub;

my $branch;

GetOptions("branch=s", => \$branch);

$output = `git checkout $branch 2>&1 1>nul`;
if ($output !~ /did not match any file/)
{
print "1\n";
}
else
{
print "0\n";
}
7 changes: 7 additions & 0 deletions qbscripts/GetAllOpenPullRequests.pl
@@ -0,0 +1,7 @@
#GetAllOpenPullRequests.pl

#use strict;
use warnings;
use LWP::Simple;
use Getopt::Long;
use Pithub;
24 changes: 24 additions & 0 deletions qbscripts/GetKodbase.pl
@@ -0,0 +1,24 @@
use Net::FTP;

my $kodpath = "C:/Meridian59-quickbuilds/kod";
my $host = "10.0.50.220";

chdir $kodpath;

my $ftp = Net::FTP->new($host, Debug => 0)
or die "Cannot connect to $host: $@";

$ftp->login("buildserver",'betafreak!@#')
or die "Cannot login to $host", $ftp->message;

$ftp->cwd("/download")
or die "Cannot change working directory ", $ftp->message;

$ftp->get("kodbase.txt")
or die "get failed ", $ftp->message;

$ftp->quit;

print "GETKODBASE: obtained $kodpath/kodbase.txt via FTP from $host.\n";


29 changes: 29 additions & 0 deletions qbscripts/IsBranchMergedWith.pl
@@ -0,0 +1,29 @@
#IsBranchMergedWith.pl
#--destination=branch to merge into
#--source=branch to merge from
#returns 1 if the source branch has been merged into destionation

#use strict;
use warnings;
use LWP::Simple;
use Getopt::Long;
use Pithub;


my $source;
my $destination;

GetOptions("source=s", => \$source,
"destination=s", => \$destination);

$output = `git checkout $destination 2>&1 1>nul`;
$output = `git branch --merged`;

if ($output =~ m/$source/)
{
print "1\n";
}
else
{
print "0\n";
}
20 changes: 20 additions & 0 deletions qbscripts/MergeWith.pl
@@ -0,0 +1,20 @@
#MergeWith
#--destination=branch to merge into
#--source=branch to merge from

#use strict;
use warnings;
use LWP::Simple;
use Getopt::Long;
use Pithub;


my $source;
my $destination;

GetOptions("source=s", => \$source,
"destination=s", => \$destination);

$output = `git checkout $destination`;

$output = `git merge $source`;
213 changes: 192 additions & 21 deletions qbscripts/autopatch.pl
Expand Up @@ -2,39 +2,210 @@
use warnings;
use LWP::Simple;
use Getopt::Long;
use Git::Repository;
use Pithub;
use Data::Dumper;
use Env;

my $outdir="C:/patchfiles";
#my $changelist=124;
my @changelists;
my $build;
my $buildid;
my $lastbranch = "master";
my $stacked = 0;
my $pullsobject = Pithub::PullRequests->new;
my $output;
my $update;
my $finalize = 0;
my $token = $ENV{'TOKEN'};

my @failed ;

GetOptions ("change=s" => \@changelists,
"build=s" => \$build);
"build=s" => \$build,
"stacked=s" => \$stacked,
"update=s" => \$update,
"finalize=s" => \$finalize,
"buildid=s" => \$buildid);

print "AUTOBUILD: Options: Updating pre-existing branches\n" if ($update);
print "AUTOBUILD: Options: Stacked Build ENABLED\n" if ($stacked);
print "AUTOBUILD: Options: Finalize Build ENABLED\n" if ($finalize);

if ($finalize)
{
print "AUTOBUILD: creating $build-complete branch\n";
$output =`git checkout -b $build-complete 2>&1`;
if ($output !~ /Switched to a new branch/) #we didn't switch
{
die "AUTOBUILD: Couldn't create branch $build-complete:\n $output";
}
}

foreach my $changelist (@changelists)
{
my $baseurl="https://github.com/Daenks/Meridian59_103/pull/$changelist.patch";
my $skip = 0;

my $p = Pithub::PullRequests->new(prepare_request => sub
{
my ($request) = @_;
$request->header( Authorization => "token $token" );
}
);

my $content = get $baseurl;
die "Couldn't get $baseurl" unless defined $content;

my $patchfilename=$outdir."/$build\_$changelist.patch";
open my $OUT,">",$patchfilename;
print $OUT $content;
close $OUT;

my $output =`git checkout -b $build-$changelist 2>&1`;
if ($output !~ /Switched to a new branch/)
my $pullinfo = $p->get(user => 'Daenks',
repo => 'Meridian59_103',
pull_request_id => $changelist,);



unless ( $pullinfo->success )
{
printf "Unable to make GitHub API Call: '%s' while looking up pull $changelist\n", $pullinfo->response->status_line;
exit 1;
}

print "********************************************************************************\n";
printf "AUTOBUILD: Pull: %d Branch: %s Author: %s\n".
"AUTOBUILD: SHA: %s\n"
,$pullinfo->content->{number}, $pullinfo->content->{head}->{ref}, $pullinfo->content->{head}->{user}->{login},
$pullinfo->content->{head}->{sha};
print "********************************************************************************\n";


my $pullreq = $changelist;
my $cloneurl = $pullinfo->content->{head}->{repo}->{clone_url};
my $branch = $pullinfo->content->{head}->{ref};
my $author = $pullinfo->content->{head}->{user}->{login};
my $sha = $pullinfo->content->{head}->{sha};

my $localbranch = "build.$build-req.$pullreq-br.$branch-auth.$author";

if ($stacked)
{
die "Couldn't create branch: $output";
print "AUTOBUILD: Creating stacked branch $localbranch based from $lastbranch\n";
$output =`git checkout -b $localbranch $lastbranch 2>&1`;
print $output . "\n";
}
#git am --3way --ignore-space-change --keep-cr $patchfilename
$output = `git am --3way --ignore-space-change --keep-cr $patchfilename 2>&1`;
my $RC = system("git am --3way --ignore-space-change --keep-cr $patchfilename");
if ($RC != 0)
else
{
system("git am --abort");
die "Failed Error Code: $RC\n";
print "AUTOBUILD: Creating branch $localbranch based from master\n";
$output =`git checkout -b $localbranch master 2>&1`;
print $output . "\n";
}
print "Success Merging $changelist\n";


if ($output !~ /Switched to a new branch/) #we didn't switch
{
if ($output !~ /already exists./) #we dont already have this branch, oops.
{
die "AUTOBUILD: Couldn't create branch $localbranch:\n $output";
}
print "AUTOBUILD: Using pre-existing branch....\n";
$output =`git checkout $localbranch master 2>&1`; #switch to existing branch
print $output . "\n";
$skip = 1;
}

if ($skip)
{
print "AUTOBUILD: Using existing code in $branch\n";
}
if (!$skip and $update)
{
print "AUTOBUILD: Downloading changes\n";
$output = `git pull $cloneurl $branch`;
print $output . "\n";
if ($output =~ /Automatic merge failed/)
{
print "AUTOBUILD: Merge failed. Resetting $localbranch...\n";
$output = `git reset --hard origin`;
print $output . "\n";
print "AUTOBUILD: Checking out master branch...\n";
$output = `git checkout master`;
print $output . "\n";
print "AUTOBUILD: Deleting failed branch....\n";
$output = `git branch -D $localbranch`;
print $output . "\n";

print $output;
print "**********************************FAILURE***************************************\n";
print "Automatic Merge of $branch ($pullreq) failed.\n";
print "At this stage, what this usually means, is that the code in the above pull was not coded against a fresh version of Meridian59_103\\master.\n";
print "TO RESOLVE: (https://help.github.com/articles/syncing-a-fork)\n";
print "1. Download updates to your repository....\n";
print " a. run: \"git remote add upstream https://github.com/Daenks/Meridian59_103.git\" to add the main repository as a link to your own.\n";
print " b. run: \"git fetch upstream\" to pull the changes down.\n";
print "2. Merge updates into your master branch.....\n";
print " a. run \"git checkout master\" to switch to your master branch\n";
print " b. run \"git merge upstream/master\" to apply changes to your master branch\n";
print "3. Re-Test your code locally and push any changes to the pull request.....\n";
print "4. Re-Merge with this utility.\n";
print "********************************************************************************\n";
push (@failed,$changelist);
print "AUTOBUILD: Continuing merge without $pullreq...\n";



my $statuses = Pithub::Repos::Statuses->new(prepare_request => sub
{
my ($request) = @_;
$request->header( Authorization => "token $token" );
}
);
my $result = $statuses->create(
user => 'Daenks',
repo => 'Meridian59_103',
sha => $sha,
data => {
state => 'error',
description => 'Merge failed!',
target_url => "http://build.openmeridian.org:8810/build/$buildid"
},
);
#print "AUTOBUILD: Status update result:\n" . Dumper(\$result);

}
else
{
#we update the stack of previous merges only if successful, this prevents the rest of the merges from trying against a failed merge.
$lastbranch = $localbranch if ($stacked);
my $statuses = Pithub::Repos::Statuses->new(prepare_request => sub
{
my ($request) = @_;
$request->header( Authorization => "token $token" );
}
);
my $result = $statuses->create(
user => 'Daenks',
repo => 'Meridian59_103',
sha => $sha,
data => {
state => 'success',
description => 'Merge succeded!',
target_url => "http://build.openmeridian.org:8810/build/$buildid"
},
);
#print "AUTOBUILD: Status update result:\n" . Dumper(\$result);
print "AUTOBUILD: Success Merging $changelist\n";
}

if ($finalize)
{
print "AUTOBUILD: checking out $build-complete\n";
$output = `git checkout $build-complete`;
print $output . "\n";
print "AUTOBUILD: merging $localbranch into $build-complete\n";
$output = `git merge $localbranch`;
print $output . "\n";
}

print "AUTOBUILD: Finished Processing $changelist\n";
}
}
if ($#failed > 0)
{
print "********************************************************************************\n";
print "AUTOBUILD: WARNING: Failed Pulls: " . join(",",@failed) . "\n";
print "********************************************************************************\n";
}
2 changes: 1 addition & 1 deletion qbscripts/build.bat
@@ -1,3 +1,3 @@
call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"

call nmake
call nmake DEBUG=1
8 changes: 8 additions & 0 deletions qbscripts/copyprodkod.pl
@@ -0,0 +1,8 @@
use File::Copy;

my $prodkod = "C:/Users/Administrator/Desktop/server/kodbase.txt";
my $buildkod = "C:/Users/Administrator/Desktop/server104/download/kodbase.txt";


print "COPYPRODKOD: Copying production kodbase.txt for download by buildserver...\n";
copy($prodkod,$buildkod);
15 changes: 12 additions & 3 deletions qbscripts/deploy.pl
@@ -1,20 +1,29 @@
use Getopt::Long;
use Net::Telnet ();
use Net::FTP;
use Switch;

my @changelists;
my $build;
my $clientMinVersion;
my $shutdowndelay = 10;
my $server = 104;

GetOptions ("change=s" => \@changelists,
"build=s" => \$build,
"clientMinVersion=s" => \$clientMinVersion);
"clientMinVersion=s" => \$clientMinVersion,
"server=s" => $server);

my $host = "10.0.50.220";
my $port = 9992;

print "Connecting to server 104\n";
switch ($server)
{
case 103 { }
case 104 { $host = "10.0.50.220"; $port = 9992; }
}

print "Connecting to $server 104\n";
$t = new Net::Telnet (Timeout => 10);
$t->port($port);
$t->open($host);
Expand All @@ -34,5 +43,5 @@

$ftp->binary;
$ftp->put("C:/packages/server-$build.zip")
or die "get failed ", $ftp->message;
or die "put failed ", $ftp->message;
$ftp->quit;

0 comments on commit 8ba5926

Please sign in to comment.