Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/filesystem #2

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 64 additions & 19 deletions PHPCI/Builder.php
Expand Up @@ -121,36 +121,76 @@ protected function setupBuild()
$commitId = $this->build->getCommitId();
$url = $this->build->getProject()->getGitUrl();
$key = $this->build->getProject()->getGitKey();
$type = $this->build->getProject()->getType();

$buildId = 'project' . $this->build->getProject()->getId() . '-build' . $this->build->getId();

$this->ciDir = realpath(dirname(__FILE__) . '/../') . '/';
$this->buildPath = $this->ciDir . 'build/' . $buildId . '/';
$reference = $this->build->getProject()->getReference();

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);
// don't want no slash on the end
if(substr($reference, -1) == '/') {
$reference = substr($reference, 0, -1);
}
else
{
// Do an HTTP clone:
$this->executeCommand('git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath);

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;
}

$this->config = yaml_parse_file($reference . '/phpci.yml');

if ( array_key_exists('prebuild', $this->config)
&& is_array($this->config['prebuild'])
&& array_key_exists('preferSymlink', $this->config['prebuild'])
&& true === $this->config['prebuild']['preferSymlink'] ) {

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;
default:
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);
}
break;
}
if(!is_file($this->buildPath . 'phpci.yml'))

if(!is_file($this->buildPath . '/phpci.yml'))
{
$this->logFailure('Project does not contain a phpci.yml file.');
return false;
}

$this->config = yaml_parse_file($this->buildPath . 'phpci.yml');
$this->config = yaml_parse_file($this->buildPath . '/phpci.yml');

if(!isset($this->config['verbose']) || !$this->config['verbose'])
{
Expand Down Expand Up @@ -179,6 +219,11 @@ protected function removeBuild()

protected function executePlugins($stage)
{
if ( !array_key_exists($stage, $this->config) || !is_array($this->config[$stage]) )
{
return;
}

foreach($this->config[$stage] as $plugin => $options)
{
$this->log('');
Expand All @@ -202,7 +247,7 @@ protected function executePlugins($stage)
{
$this->success = false;
}

continue;
}

Expand All @@ -216,7 +261,7 @@ protected function executePlugins($stage)
{
$this->success = false;
}

$this->logFailure('PLUGIN STATUS: FAILED');
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions PHPCI/Controller/ProjectController.php
Expand Up @@ -128,7 +128,7 @@ public function edit($id)
{
throw new \Exception('You do not have permission to do that.');
}

$method = Registry::getInstance()->get('requestMethod');
$project = $this->_projectStore->getById($id);

Expand Down Expand Up @@ -180,15 +180,15 @@ protected function projectForm($values, $type = 'add')

$field = new Form\Element\Select('type');
$field->setRequired(true);
$field->setOptions(array('github' => 'Github', 'bitbucket' => 'Bitbucket'));
$field->setOptions(array('github' => 'Github', 'bitbucket' => 'Bitbucket', 'local' => 'Local FS'));
$field->setLabel('Where is your project hosted?');
$field->setClass('span4');
$form->addField($field);

$field = new Form\Element\Text('reference');
$field->setRequired(true);
$field->setPattern('[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+');
$field->setLabel('Repository Name on Github / Bitbucket (e.g. block8/phpci)');
// $field->setPattern('[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+');
$field->setLabel('Repository Name on Github / Bitbucket (e.g. block8/phpci) or directory location');
$field->setClass('span4');
$form->addField($field);

Expand Down