2013-05-16 00:47:37 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2013-05-16 03:16:56 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2013, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link http://www.phptesting.org/
|
|
|
|
*/
|
2013-05-16 00:47:37 +02:00
|
|
|
|
2013-05-16 01:51:12 +02:00
|
|
|
namespace PHPCI\Model\Build;
|
2013-05-16 16:40:40 +02:00
|
|
|
|
|
|
|
use PHPCI\Model\Build;
|
|
|
|
use PHPCI\Builder;
|
|
|
|
use Symfony\Component\Yaml\Parser as YamlParser;
|
2013-05-16 00:47:37 +02:00
|
|
|
|
|
|
|
/**
|
2013-05-16 03:30:48 +02:00
|
|
|
* Local Build Model
|
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Core
|
|
|
|
*/
|
2013-05-16 00:47:37 +02:00
|
|
|
class LocalBuild extends Build
|
|
|
|
{
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
|
|
|
* Create a working copy by cloning, copying, or similar.
|
|
|
|
*/
|
2013-05-16 16:40:40 +02:00
|
|
|
public function createWorkingCopy(Builder $builder, $buildPath)
|
2013-06-30 10:55:25 +02:00
|
|
|
{
|
2013-05-16 16:40:40 +02:00
|
|
|
$reference = $this->getProject()->getReference();
|
|
|
|
$reference = substr($reference, -1) == '/' ? substr($reference, 0, -1) : $reference;
|
|
|
|
$buildPath = substr($buildPath, 0, -1);
|
|
|
|
$yamlParser = new YamlParser();
|
2013-06-30 10:55:25 +02:00
|
|
|
|
2013-06-30 11:44:02 +02:00
|
|
|
if(is_file($reference.'/config')) {
|
2013-06-30 10:55:25 +02:00
|
|
|
//We're probably looing at a bare repository. We'll open the config and check
|
2013-06-30 11:44:02 +02:00
|
|
|
$gitConfig = parse_ini_file($reference.'/config',TRUE);
|
2013-06-30 10:55:25 +02:00
|
|
|
if($gitConfig["core"]["bare"]) {
|
|
|
|
// Looks like we're right. We need to extract the archive!
|
|
|
|
$guid = uniqid();
|
2013-06-30 16:17:41 +02:00
|
|
|
$builder->executeCommand('mkdir "/tmp/%s" && git --git-dir="%s" archive master | tar -x -C "/tmp/%s"', $guid, $reference, $guid);
|
2013-06-30 10:55:25 +02:00
|
|
|
$reference = '/tmp/'.$guid;
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 16:40:40 +02:00
|
|
|
|
|
|
|
if (!is_file($reference . '/phpci.yml')) {
|
|
|
|
$builder->logFailure('Project does not contain a phpci.yml file.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$yamlFile = file_get_contents($reference . '/phpci.yml');
|
|
|
|
$builder->setConfigArray($yamlParser->parse($yamlFile));
|
|
|
|
|
|
|
|
$buildSettings = $builder->getConfig('build_settings');
|
|
|
|
|
|
|
|
if (isset($buildSettings['prefer_symlink']) && $buildSettings['prefer_symlink'] === true) {
|
|
|
|
if (is_link($buildPath) && is_file($buildPath)) {
|
|
|
|
unlink($buildPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
$builder->log(sprintf('Symlinking: %s to %s', $reference, $buildPath));
|
|
|
|
|
|
|
|
if (!symlink($reference, $buildPath)) {
|
|
|
|
$builder->logFailure('Failed to symlink.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$builder->executeCommand('cp -Rf "%s" "%s/"', $reference, $buildPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-16 00:47:37 +02:00
|
|
|
}
|