Merging master to bring github branch into line.

This commit is contained in:
Dan Cryer 2013-05-14 19:57:37 +01:00
commit be838c6765
16 changed files with 151 additions and 89 deletions

View file

@ -3,6 +3,7 @@
namespace PHPCI;
use PHPCI\Model\Build;
use b8\Store;
use Symfony\Component\Yaml\Parser as YamlParser;
class Builder
{
@ -126,38 +127,81 @@ class Builder
$commitId = $this->build->getCommitId();
$url = $this->build->getProject()->getGitUrl();
$key = $this->build->getProject()->getGitKey();
$type = $this->build->getProject()->getType();
$reference = $this->build->getProject()->getReference();
$reference = substr($reference, -1) == '/' ? substr($reference, 0, -1) : $reference;
$buildId = 'project' . $this->build->getProject()->getId() . '-build' . $this->build->getId();
$yamlParser = new YamlParser();
$this->ciDir = realpath(dirname(__FILE__) . '/../') . '/';
$this->buildPath = $this->ciDir . 'build/' . $buildId . '/';
mkdir($this->buildPath, 0777, true);
switch ($type)
{
case 'local':
$this->buildPath = $this->ciDir . 'build/' . $buildId;
if(!is_file($reference . '/phpci.yml'))
{
$this->logFailure('Project does not contain a phpci.yml file.');
return false;
}
if(!empty($key))
{
// Do an SSH clone:
$keyFile = $this->ciDir . 'build/' . $buildId . '.key';
file_put_contents($keyFile, $key);
chmod($keyFile, 0600);
$this->executeCommand('ssh-agent ssh-add '.$keyFile.' && git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath.' && ssh-agent -k');
unlink($keyFile);
}
else
{
// Do an HTTP clone:
$this->executeCommand('git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath);
}
if(!is_file($this->buildPath . 'phpci.yml'))
{
$this->logFailure('Project does not contain a phpci.yml file.');
return false;
$yamlFile = file_get_contents($reference . '/phpci.yml');
$this->config = $yamlParser->parse($yamlFile);
if(array_key_exists('build_settings', $this->config)
&& is_array($this->config['build_settings'])
&& array_key_exists('prefer_symlink', $this->config['build_settings'])
&& true === $this->config['build_settings']['prefer_symlink'])
{
if(is_link($this->buildPath) && is_file($this->buildPath))
{
unlink($this->buildPath);
}
$this->log(sprintf('Symlinking: %s to %s',$reference, $this->buildPath));
symlink($reference, $this->buildPath);
}
else
{
$this->executeCommand(sprintf("cp -Rf %s %s/", $reference, $this->buildPath));
}
$this->buildPath .= '/';
break;
case 'github':
case 'bitbucket':
mkdir($this->buildPath, 0777, true);
if(!empty($key))
{
// Do an SSH clone:
$keyFile = $this->ciDir . 'build/' . $buildId . '.key';
file_put_contents($keyFile, $key);
chmod($keyFile, 0600);
$this->executeCommand('ssh-agent ssh-add '.$keyFile.' && git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath.' && ssh-agent -k');
unlink($keyFile);
}
else
{
// Do an HTTP clone:
$this->executeCommand('git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath);
}
if(!is_file($this->buildPath . 'phpci.yml'))
{
$this->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$yamlFile = file_get_contents($this->buildPath . 'phpci.yml');
$this->config = $yamlParser->parse($yamlFile);
break;
}
$this->config = yaml_parse_file($this->buildPath . 'phpci.yml');
if(!isset($this->config['verbose']) || !$this->config['verbose'])
if(!isset($this->config['build_settings']['verbose']) || !$this->config['build_settings']['verbose'])
{
$this->verbose = false;
}
@ -166,9 +210,9 @@ class Builder
$this->verbose = true;
}
if(isset($this->config['ignore']))
if(isset($this->config['build_settings']['ignore']))
{
$this->ignore = $this->config['ignore'];
$this->ignore = $this->config['build_settings']['ignore'];
}
$this->log('Set up build: ' . $this->buildPath);
@ -184,6 +228,12 @@ class Builder
protected function executePlugins($stage)
{
// Ignore any stages for which we don't have plugins set:
if(!array_key_exists($stage, $this->config) || !is_array($this->config[$stage]))
{
return;
}
foreach($this->config[$stage] as $plugin => $options)
{
$this->log('');

View file

@ -88,7 +88,11 @@ class ProjectController extends b8\Controller
}
else
{
$id = '/tmp/' . md5(microtime(true));
$tempPath = sys_get_temp_dir() . '/';
$id = $tempPath . md5(microtime(true));
if (!is_dir($tempPath)) {
mkdir($tempPath);
}
shell_exec('ssh-keygen -q -t rsa -b 2048 -f '.$id.' -N "" -C "deploy@phpci"');
$pub = file_get_contents($id . '.pub');
@ -192,8 +196,8 @@ class ProjectController extends b8\Controller
$field = new Form\Element\Select('type');
$field->setRequired(true);
$field->setPattern('^(github|bitbucket)');
$field->setOptions(array('choose' => 'Select repository type...', 'github' => 'Github', 'bitbucket' => 'Bitbucket'));
$field->setPattern('^(github|bitbucket|local)');
$field->setOptions(array('choose' => 'Select repository type...', 'github' => 'Github', 'bitbucket' => 'Bitbucket', 'local' => 'Local Path'));
$field->setLabel('Where is your project hosted?');
$field->setClass('span4');
$form->addField($field);
@ -209,8 +213,8 @@ class ProjectController extends b8\Controller
$field = new Form\Element\Text('reference');
$field->setRequired(true);
$field->setPattern('[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+');
$field->setLabel('Repository Name / URL:');
$field->setPattern('[a-zA-Z0-9_\-\/]+');
$field->setLabel('Repository Name / URL (Remote) or Path (Local)');
$field->setClass('span4');
$form->addField($field);
@ -222,7 +226,7 @@ class ProjectController extends b8\Controller
$field = new Form\Element\TextArea('key');
$field->setRequired(false);
$field->setLabel('Private key to use to access repository (leave blank to use anonymous HTTP repository access)');
$field->setLabel('Private key to use to access repository (leave blank for local and/or anonymous remotes)');
$field->setClass('span7');
$field->setRows(6);
$form->addField($field);

View file

@ -13,11 +13,11 @@ class PhpSpec implements \PHPCI\Plugin
public function execute()
{
$cwd = getcwd();
$command = 'cd ' . $this->phpci->buildPath . ' && ';
$command .= PHPCI_BIN_DIR . 'phpspec';
$command .= ' && cd ' . $cwd;
return $this->phpci->executeCommand($command);
$curdir = getcwd();
chdir($this->phpci->buildPath);
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpspec');
chdir($curdir);
return $success;
}
}

View file

@ -17,6 +17,11 @@ class PhpUnit implements \PHPCI\Plugin
public function execute()
{
return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' ' . $this->phpci->buildPath . $this->directory);
$curdir = getcwd();
chdir($this->phpci->buildPath);
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' ' . $this->phpci->buildPath . $this->directory);
chdir($curdir);
return $success;
}
}

View file

@ -1,6 +1,6 @@
<div id="title">
<h1 style="display: inline-block">Build #<?= $build->getId(); ?></h1>
<h3 style="margin-left: 40px; display: inline-block">Branch: <?= $build->getBranch(); ?> - <?= $build->getCommitId() == 'Manual' ? 'Manual Build' : 'Commit: ' . $build->getCommitId(); ?></h3>
<h1 style="display: inline-block">Build #<?php print $build->getId(); ?></h1>
<h3 style="margin-left: 40px; display: inline-block">Branch: <?php print $build->getBranch(); ?> - <?php print $build->getCommitId() == 'Manual' ? 'Manual Build' : 'Commit: ' . $build->getCommitId(); ?></h3>
</div>
<div class="row">
@ -8,12 +8,12 @@
<div class="well" style="padding: 8px 0">
<ul class="nav nav-list">
<li><a href="/"><i class="icon-home"></i> Dashboard</a></li>
<li><a href="/project/view/<?= $build->getProject()->getId(); ?>"><i class="icon-folder-open"></i> <?= $build->getProject()->getTitle(); ?></a></li>
<li><a href="/project/view/<?php print $build->getProject()->getId(); ?>"><i class="icon-folder-open"></i> <?php print $build->getProject()->getTitle(); ?></a></li>
<li class="divider"></li>
<li class="nav-header">Options</li>
<li><a href="/build/rebuild/<?= $build->getId(); ?>"><i class="icon-cog"></i> Rebuild</a></li>
<li><a href="/build/rebuild/<?php print $build->getId(); ?>"><i class="icon-cog"></i> Rebuild</a></li>
<?php if($this->User()->getIsAdmin()): ?>
<li><a href="javascript:confirmDelete('/build/delete/<?= $build->getId(); ?>')"><i class="icon-trash"></i> Delete Build</a></li>
<li><a href="javascript:confirmDelete('/build/delete/<?php print $build->getId(); ?>')"><i class="icon-trash"></i> Delete Build</a></li>
<?php endif; ?>
</ul>
</div>
@ -25,7 +25,7 @@
</tr>
</thead>
<tbody id="plugins">
<?= $plugins; ?>
<?php print $plugins; ?>
</tbody>
</table>
</div>
@ -68,13 +68,13 @@
<script>
setInterval(function()
{
$.getJSON('/build/data/<?= $build->getId(); ?>', updateBuildView);
$.getJSON('/build/data/<?php print $build->getId(); ?>', updateBuildView);
}, 10000);
</script>
<?php endif; ?>
<script>
window.initial = <?= $data; ?>;
window.initial = <?php print $data; ?>;
function updateBuildView(data)
{

View file

@ -30,21 +30,21 @@ switch($build->getStatus())
break;
}
?>
<tr class="<?= $cls; ?>">
<td><a href="/build/view/<?= $build->getId(); ?>">#<?= str_pad($build->getId(), 6, '0', STR_PAD_LEFT); ?></a></td>
<td><a href="/project/view/<?= $build->getProjectId(); ?>"><?= $build->getProject()->getTitle(); ?></a></td>
<td><a href="<?= $build->getCommitLink(); ?>"><?= $build->getCommitId(); ?></a></td>
<td><a href="<?= $build->getBranchLink(); ?>"><?= $build->getBranch(); ?></a></td>
<td><?= $status; ?></td>
<tr class="<?php print $cls; ?>">
<td><a href="/build/view/<?php print $build->getId(); ?>">#<?php print str_pad($build->getId(), 6, '0', STR_PAD_LEFT); ?></a></td>
<td><a href="/project/view/<?php print $build->getProjectId(); ?>"><?php print $build->getProject()->getTitle(); ?></a></td>
<td><a href="<?php print $build->getCommitLink(); ?>"><?php print $build->getCommitId(); ?></a></td>
<td><a href="<?php print $build->getBranchLink(); ?>"><?php print $build->getBranch(); ?></a></td>
<td><?php print $status; ?></td>
<td>
<div class="btn-group">
<a class="btn" href="/build/view/<?= $build->getId(); ?>">View</a>
<a class="btn" href="/build/view/<?php print $build->getId(); ?>">View</a>
<?php if($this->User()->getIsAdmin()): ?>
<button class="btn dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="javascript:confirmDelete('/build/delete/<?= $build->getId(); ?>');">Delete Build</a></li>
<li><a href="javascript:confirmDelete('/build/delete/<?php print $build->getId(); ?>');">Delete Build</a></li>
</ul>
<?php endif; ?>
</div>

View file

@ -11,7 +11,7 @@
<li class="nav-header">Projects</li>
<?php foreach($projects as $project): ?>
<li><a href="/project/view/<?= $project->getId(); ?>"><i class="icon-folder-open"></i> <?= $project->getTitle(); ?></a></li>
<li><a href="/project/view/<?php print $project->getId(); ?>"><i class="icon-folder-open"></i> <?php print $project->getTitle(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
@ -29,7 +29,7 @@
</tr>
</thead>
<tbody id="latest-builds">
<?= $builds; ?>
<?php print $builds; ?>
</tbody>
</table>
</div>

View file

@ -91,7 +91,7 @@
</div>
<div id="content" class="container">
<?= $content; ?>
<?php print $content; ?>
</div>
</body>
</html>

View file

@ -1,4 +1,3 @@
<!DOCTYPE html>
<html lang="en">
<head>
@ -43,7 +42,7 @@
<div class="container">
<div class="row" style="margin-top: 10%; text-align: center">
<div class="" id="login-box">
<?= $form; ?>
<?php print $form; ?>
</div>
<a id="logo" href="http://www.block8.co.uk/"><img src="http://cms.block8.co.uk/assets/img/small-logo-trans-white.png"></a>

View file

@ -1,5 +1,5 @@
<div id="title">
<h1>Project: <?= $project->getTitle(); ?></h1>
<h1>Project: <?php print $project->getTitle(); ?></h1>
</div>
<div class="row">
@ -7,14 +7,14 @@
<div class="well" style="padding: 8px 0">
<ul class="nav nav-list">
<li><a href="/"><i class="icon-home"></i> Dashboard</a></li>
<li><a href="/project/view/<?= $project->getId(); ?>"><i class="icon-folder-open"></i> <?= $project->getTitle(); ?></a></li>
<li><a href="/project/view/<?php print $project->getId(); ?>"><i class="icon-folder-open"></i> <?php print $project->getTitle(); ?></a></li>
<li class="divider"></li>
<li class="nav-header">Options</li>
<li><a href="/project/build/<?= $project->getId(); ?>"><i class="icon-cog"></i> Build Now</a></li>
<li><a href="/project/build/<?php print $project->getId(); ?>"><i class="icon-cog"></i> Build Now</a></li>
<?php if($this->User()->getIsAdmin()): ?>
<li><a href="/project/edit/<?= $project->getId(); ?>"><i class="icon-edit"></i> Edit Project</a></li>
<li><a href="javascript:confirmDelete('/project/delete/<?= $project->getId(); ?>')"><i class="icon-trash"></i> Delete Project</a></li>
<li><a href="/project/edit/<?php print $project->getId(); ?>"><i class="icon-edit"></i> Edit Project</a></li>
<li><a href="javascript:confirmDelete('/project/delete/<?php print $project->getId(); ?>')"><i class="icon-trash"></i> Delete Project</a></li>
<?php endif; ?>
</ul>
</div>
@ -51,7 +51,7 @@
</tr>
</thead>
<tbody id="latest-builds">
<?= $builds; ?>
<?php print $builds; ?>
</tbody>
</table>
@ -80,7 +80,7 @@
<script>
setInterval(function()
{
$('#latest-builds').load('/project/builds/<?= $project->getId(); ?>');
$('#latest-builds').load('/project/builds/<?php print $project->getId(); ?>');
}, 10000);
</script>
<?php endif; ?>

View file

@ -1,5 +1,5 @@
<div id="title">
<h1><?= $type == 'add' ? 'Add Project' : 'Edit Project' ?></h1>
<h1><?php print $type == 'add' ? 'Add Project' : 'Edit Project' ?></h1>
</div>
<div class="row">
@ -8,7 +8,7 @@
<?php if(!is_null($key)): ?>
<p>To make it easier to get started, we've generated a public / private key pair for you to use for this project. To use it, just add the following public key to the "deploy keys" section of your repository settings on Github / Bitbucket.</p>
<textarea style="width: 90%; height: 150px;"><?= $key ?></textarea>
<textarea style="width: 90%; height: 150px;"><?php print $key ?></textarea>
<?php elseif($type == 'add'): ?>
<p>Fill in the form to the right to add your new project.</p>
<?php else: ?>
@ -17,7 +17,7 @@
</div>
</div>
<div class="span8">
<?= $form; ?>
<?php print $form; ?>
</div>
</div>

View file

@ -40,19 +40,19 @@
break;
}
?>
<tr class="<?= $cls; ?>">
<td><a href="/user/edit/<?= $user->getId(); ?>"><?= $user->getEmail(); ?></a></td>
<td><?= $user->getName(); ?></td>
<td><?= $status; ?></td>
<tr class="<?php print $cls; ?>">
<td><a href="/user/edit/<?php print $user->getId(); ?>"><?php print $user->getEmail(); ?></a></td>
<td><?php print $user->getName(); ?></td>
<td><?php print $status; ?></td>
<td>
<?php if($this->User()->getIsAdmin()): ?>
<div class="btn-group">
<a class="btn" href="/user/edit/<?= $user->getId(); ?>">Edit</a>
<a class="btn" href="/user/edit/<?php print $user->getId(); ?>">Edit</a>
<button class="btn dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="javascript:confirmDelete('/user/delete/<?= $user->getId(); ?>');">Delete User</a></li>
<li><a href="javascript:confirmDelete('/user/delete/<?php print $user->getId(); ?>');">Delete User</a></li>
</ul>
</div>
<?php endif; ?>

View file

@ -1,5 +1,5 @@
<div id="title">
<h1><?= $type == 'add' ? 'Add User' : 'Edit ' . $user->getName() ?></h1>
<h1><?php print $type == 'add' ? 'Add User' : 'Edit ' . $user->getName() ?></h1>
</div>
<div class="row">
@ -13,6 +13,6 @@
</div>
</div>
<div class="span8">
<?= $form; ?>
<?php print $form; ?>
</div>
</div>

View file

@ -6,7 +6,7 @@ PHPCI is a free and open source continuous integration tool specifically designe
_**Please be aware that this is a brand new project, in an alpha state, so there will be bugs and missing features.**_
##What it does:
* Clones your repository from Github or Bitbucket (support for standard Git repositories coming soon.)
* Clones your project from Github, Bitbucket or a local path (support for standard remote Git repositories coming soon.)
* Allows you to set up and tear down test databases.
* Installs your project's Composer dependencies.
* Runs through any combination of the following plugins:
@ -14,6 +14,7 @@ _**Please be aware that this is a brand new project, in an alpha state, so there
* PHP Mess Detector
* PHP Copy/Paste Detector
* PHP Code Sniffer
* PHP Spec
* You can mark directories for the plugins to ignore.
* You can mark certain plugins as being allowed to fail (but still run.)
@ -67,7 +68,12 @@ Obviously, make sure you change the `/path/to/phpci` to the directory in which y
##Adding support for PHPCI to your projects:
Similar to Travis CI, to support PHPCI in your project, you simply need to add a `phpci.yml` file to the root of your repository. The file should look something like this:
setup:
build_settings:
ignore:
- "vendor"
- "tests"
setup:
mysql:
- "DROP DATABASE IF EXISTS test;"
- "CREATE DATABASE test;"
@ -75,10 +81,6 @@ Similar to Travis CI, to support PHPCI in your project, you simply need to add a
composer:
action: "install"
ignore:
- "vendor"
- "tests"
test:
php_unit:
directory: "tests/"

View file

@ -30,6 +30,6 @@
"squizlabs/php_codesniffer": "1.*",
"ircmaxell/password-compat": "1.x",
"phpspec/phpspec": "2.*",
"ext-yaml": "*"
"symfony/yaml": "2.2.x-dev"
}
}
}

View file

@ -1,10 +1,12 @@
build_settings:
verbose: false
ignore:
- "vendor"
setup:
composer:
action: "install"
ignore:
- "vendor/"
test:
php_mess_detector:
allow_failures: true