This commit is contained in:
meadsteve 2013-05-16 09:46:32 +01:00
commit 9a3f1af008
20 changed files with 868 additions and 488 deletions

3
.gitignore vendored
View file

@ -4,3 +4,6 @@ composer.lock
composer.phar
config.php
.DS_Store
.settings/
.project
.buildpath

View file

@ -17,11 +17,17 @@ class Builder
protected $verbose = false;
protected $plugins = array();
protected $build;
protected $logCallback;
public function __construct(Build $build)
public function __construct(Build $build, $logCallback = null)
{
$this->build = $build;
$this->store = Store\Factory::getStore('Build');
if(!is_null($logCallback) && is_callable($logCallback))
{
$this->logCallback = $logCallback;
}
}
public function execute()
@ -87,24 +93,32 @@ class Builder
protected function log($message, $prefix = '')
{
if(is_array($message))
{
$message = array_map(function($item) use ($prefix)
foreach ($message as $item)
{
return $prefix . $item;
}, $message);
$message = implode(PHP_EOL, $message);
$this->log .= $message;
print $message . PHP_EOL;
if(is_callable($this->logCallback))
{
$this->logCallback($prefix . $item);
}
$this->log .= $prefix . $item . PHP_EOL;
}
}
else
{
$message = $prefix . $message . PHP_EOL;
$message = $prefix . $message;
$this->log .= $message;
print $message;
$this->log .= $message . PHP_EOL;
if(isset($this->logCallback) && is_callable($this->logCallback))
{
$cb = $this->logCallback;
$cb($message);
}
}
$this->build->setLog($this->log);
@ -139,8 +153,8 @@ class Builder
switch ($type)
{
case 'local':
$this->buildPath = $this->ciDir . 'build/' . $buildId;
$this->buildPath = substr($this->buildPath, 0, -1);
if(!is_file($reference . '/phpci.yml'))
{
$this->logFailure('Project does not contain a phpci.yml file.');
@ -149,7 +163,7 @@ class Builder
$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'])
@ -161,20 +175,24 @@ class Builder
}
$this->log(sprintf('Symlinking: %s to %s',$reference, $this->buildPath));
symlink($reference, $this->buildPath);
if ( !symlink($reference, $this->buildPath) )
{
$this->logFailure('Failed to symlink.');
return false;
}
}
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:
@ -262,7 +280,7 @@ class Builder
$this->success = false;
}
}
continue;
}
@ -281,7 +299,7 @@ class Builder
$this->success = false;
}
}
$this->logFailure('PLUGIN STATUS: FAILED');
continue;
}
@ -308,7 +326,7 @@ class Builder
{
$this->plugins[$plugin] = true;
}
$this->logSuccess('PLUGIN STATUS: SUCCESS!');
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace PHPCI\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class GenerateCommand extends Command
{
protected function configure()
{
$this
->setName('phpci:generate')
->setDescription('Generate models and stores from the database.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$gen = new \b8\Database\CodeGenerator(\b8\Database::getConnection(), 'PHPCI', PHPCI_DIR . '/PHPCI/');
$gen->generateModels();
$gen->generateStores();
}
}

View file

@ -0,0 +1,114 @@
<?php
namespace PHPCI\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use b8\Store\Factory;
use PHPCI\Builder;
class InstallCommand extends Command
{
protected function configure()
{
$this
->setName('phpci:install')
->setDescription('Install PHPCI.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$dbHost = $this->ask('Enter your MySQL host: ');
$dbName = $this->ask('Enter the database name PHPCI should use: ');
$dbUser = $this->ask('Enter your MySQL username: ');
$dbPass = $this->ask('Enter your MySQL password: ', true);
$ciUrl = $this->ask('Your PHPCI URL (without trailing slash): ', true);
$ghId = $this->ask('(Optional) Github Application ID: ', true);
$ghSecret = $this->ask('(Optional) Github Application Secret: ', true);
$cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost . ' -e "CREATE DATABASE IF NOT EXISTS ' . $dbName . '"';
shell_exec($cmd);
$str = "<?php
define('PHPCI_DB_HOST', '{$dbHost}');
b8\Database::setDetails('{$dbName}', '{$dbUser}', '{$dbPass}');
b8\Database::setWriteServers(array('{$dbHost}'));
b8\Database::setReadServers(array('{$dbHost}'));
\$registry = b8\Registry::getInstance();
\$registry->set('install_url', '{$ciUrl}');
";
if(!empty($ghId) && !empty($ghSecret))
{
$str .= PHP_EOL . "\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" . PHP_EOL;
}
file_put_contents(PHPCI_DIR . 'config.php', $str);
if(!file_exists(PHPCI_DIR . 'composer.phar'))
{
print 'INSTALLING: Composer' . PHP_EOL;
file_put_contents(PHPCI_DIR . 'composerinstaller.php', file_get_contents('https://getcomposer.org/installer'));
shell_exec('php ' . PHPCI_DIR . 'composerinstaller.php');
unlink(PHPCI_DIR . 'composerinstaller.php');
}
print 'RUNNING: Composer' . PHP_EOL;
shell_exec('php '.PHPCI_DIR.'composer.phar install');
require(PHPCI_DIR . 'bootstrap.php');
$gen = new \b8\Database\Generator(\b8\Database::getConnection(), 'PHPCI', './PHPCI/Model/Base/');
$gen->generate();
$adminEmail = $this->ask('Enter your email address: ');
$adminPass = $this->ask('Enter your desired admin password: ');
$adminName = $this->ask('Enter your name: ');
try
{
$user = new \PHPCI\Model\User();
$user->setEmail($adminEmail);
$user->setName($adminName);
$user->setIsAdmin(1);
$user->setHash(password_hash($adminPass, PASSWORD_DEFAULT));
$store = \b8\Store\Factory::getStore('User');
$store->save($user);
print 'User account created!' . PHP_EOL;
}
catch(\Exception $ex)
{
print 'There was a problem creating your account. :(' . PHP_EOL;
print $ex->getMessage();
}
}
function ask($question, $emptyOk = false)
{
print $question . ' ';
$rtn = '';
$fp = fopen('php://stdin', 'r');
$rtn = fgets($fp);
fclose($fp);
$rtn = trim($rtn);
if(!$emptyOk && empty($rtn))
{
$rtn = $this->ask($question, $emptyOk);
}
return $rtn;
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace PHPCI\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use b8\Store\Factory;
use PHPCI\Builder;
class RunCommand extends Command
{
protected function configure()
{
$this
->setName('phpci:run-builds')
->setDescription('Run all pending PHPCI builds.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->output = $output;
$store = Factory::getStore('Build');
$result = $store->getByStatus(0);
foreach($result['items'] as $build)
{
if ($input->getOption('verbose')) {
$builder = new Builder($build, array($this, 'logCallback'));
}
else {
$builder = new Builder($build);
}
$builder->execute();
}
}
public function logCallback($log)
{
$this->output->writeln($log);
}
}

View file

@ -89,6 +89,15 @@ class ProjectController extends b8\Controller
else
{
$tempPath = sys_get_temp_dir() . '/';
// FastCGI fix for Windows machines, where temp path is not available to
// PHP, and defaults to the unwritable system directory. If the temp
// path is pointing to the system directory, shift to the 'TEMP'
// sub-folder, which should also exist, but actually be writable.
if ($tempPath == getenv("SystemRoot") . '/') {
$tempPath = getenv("SystemRoot") . '/TEMP/';
}
$id = $tempPath . md5(microtime(true));
if (!is_dir($tempPath)) {
mkdir($tempPath);

View file

@ -12,144 +12,146 @@ use b8\Model;
*/
class BuildBase extends Model
{
public static $sleepable= array();
protected $_tableName = 'build';
protected $_modelName = 'Build';
protected $_data = array(
'id' => null,
'project_id' => null,
'commit_id' => null,
'status' => null,
'log' => null,
'branch' => null,
'created' => null,
'started' => null,
'finished' => null,
'plugins' => null,
);
protected $_getters = array(
'id' => 'getId',
'project_id' => 'getProjectId',
'commit_id' => 'getCommitId',
'status' => 'getStatus',
'log' => 'getLog',
'branch' => 'getBranch',
'created' => 'getCreated',
'started' => 'getStarted',
'finished' => 'getFinished',
'plugins' => 'getPlugins',
/**
* @var array
*/
public static $sleepable = array();
'Project' => 'getProject',
/**
* @var string
*/
protected $_tableName = 'build';
);
/**
* @var string
*/
protected $_modelName = 'Build';
protected $_setters = array(
'id' => 'setId',
'project_id' => 'setProjectId',
'commit_id' => 'setCommitId',
'status' => 'setStatus',
'log' => 'setLog',
'branch' => 'setBranch',
'created' => 'setCreated',
'started' => 'setStarted',
'finished' => 'setFinished',
'plugins' => 'setPlugins',
/**
* @var array
*/
protected $_data = array(
'id' => null,
'project_id' => null,
'commit_id' => null,
'status' => null,
'log' => null,
'branch' => null,
'created' => null,
'started' => null,
'finished' => null,
'plugins' => null,
);
'Project' => 'setProject',
);
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
/**
* @var array
*/
protected $_getters = array(
'id' => 'getId',
'project_id' => 'getProjectId',
'commit_id' => 'getCommitId',
'status' => 'getStatus',
'log' => 'getLog',
'branch' => 'getBranch',
'created' => 'getCreated',
'started' => 'getStarted',
'finished' => 'getFinished',
'plugins' => 'getPlugins',
'Project' => 'getProject',
);
'primary_key' => true,
'auto_increment' => true,
),
'project_id' => array(
'type' => 'int',
'length' => '11',
),
'commit_id' => array(
'type' => 'varchar',
'length' => '50',
),
'status' => array(
'type' => 'tinyint',
'length' => '4',
),
'log' => array(
'type' => 'text',
'length' => '',
'nullable' => true,
),
'branch' => array(
'type' => 'varchar',
'length' => '50',
),
'created' => array(
'type' => 'datetime',
'length' => '',
'nullable' => true,
),
'started' => array(
'type' => 'datetime',
'length' => '',
'nullable' => true,
),
'finished' => array(
'type' => 'datetime',
'length' => '',
'nullable' => true,
),
'plugins' => array(
'type' => 'text',
'length' => '',
'nullable' => true,
),
);
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'project_id' => array('columns' => 'project_id'),
'idx_status' => array('columns' => 'status'),
);
public $foreignKeys = array(
'build_ibfk_1' => array('local_col' => 'project_id', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'project', 'col' => 'id'),
);
/**
* @var array
*/
protected $_setters = array(
'id' => 'setId',
'project_id' => 'setProjectId',
'commit_id' => 'setCommitId',
'status' => 'setStatus',
'log' => 'setLog',
'branch' => 'setBranch',
'created' => 'setCreated',
'started' => 'setStarted',
'finished' => 'setFinished',
'plugins' => 'setPlugins',
'Project' => 'setProject',
);
/**
* @var array
*/
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'project_id' => array(
'type' => 'int',
'length' => '11',
),
'commit_id' => array(
'type' => 'varchar',
'length' => '50',
),
'status' => array(
'type' => 'tinyint',
'length' => '4',
),
'log' => array(
'type' => 'text',
'length' => '',
'nullable' => true,
),
'branch' => array(
'type' => 'varchar',
'length' => '50',
),
'created' => array(
'type' => 'datetime',
'length' => '',
'nullable' => true,
),
'started' => array(
'type' => 'datetime',
'length' => '',
'nullable' => true,
),
'finished' => array(
'type' => 'datetime',
'length' => '',
'nullable' => true,
),
'plugins' => array(
'type' => 'text',
'length' => '',
'nullable' => true,
),
);
/**
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'project_id' => array('columns' => 'project_id'),
'idx_status' => array('columns' => 'status'),
);
/**
* @var array
*/
public $foreignKeys = array(
'build_ibfk_1' => array('local_col' => 'project_id', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'project', 'col' => 'id'),
);
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->_data['id'];
@ -158,6 +160,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of ProjectId / project_id.
*
* @return int
*/
public function getProjectId()
{
$rtn = $this->_data['project_id'];
@ -166,6 +173,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of CommitId / commit_id.
*
* @return string
*/
public function getCommitId()
{
$rtn = $this->_data['commit_id'];
@ -174,6 +186,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of Status / status.
*
* @return int
*/
public function getStatus()
{
$rtn = $this->_data['status'];
@ -182,6 +199,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of Log / log.
*
* @return string
*/
public function getLog()
{
$rtn = $this->_data['log'];
@ -190,6 +212,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of Branch / branch.
*
* @return string
*/
public function getBranch()
{
$rtn = $this->_data['branch'];
@ -198,6 +225,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of Created / created.
*
* @return \DateTime
*/
public function getCreated()
{
$rtn = $this->_data['created'];
@ -212,6 +244,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of Started / started.
*
* @return \DateTime
*/
public function getStarted()
{
$rtn = $this->_data['started'];
@ -226,6 +263,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of Finished / finished.
*
* @return \DateTime
*/
public function getFinished()
{
$rtn = $this->_data['finished'];
@ -240,6 +282,11 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of Plugins / plugins.
*
* @return string
*/
public function getPlugins()
{
$rtn = $this->_data['plugins'];
@ -248,13 +295,17 @@ class BuildBase extends Model
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
if($this->_data['id'] == $value)
if($this->_data['id'] === $value)
{
return;
}
@ -264,11 +315,17 @@ class BuildBase extends Model
$this->_setModified('id');
}
/**
* Set the value of ProjectId / project_id.
*
* Must not be null.
* @param $value int
*/
public function setProjectId($value)
{
$this->_validateNotNull('ProjectId', $value);
$this->_validateInt('ProjectId', $value);
if($this->_data['project_id'] == $value)
if($this->_data['project_id'] === $value)
{
return;
}
@ -278,11 +335,17 @@ class BuildBase extends Model
$this->_setModified('project_id');
}
/**
* Set the value of CommitId / commit_id.
*
* Must not be null.
* @param $value string
*/
public function setCommitId($value)
{
$this->_validateNotNull('CommitId', $value);
$this->_validateString('CommitId', $value);
if($this->_data['commit_id'] == $value)
if($this->_data['commit_id'] === $value)
{
return;
}
@ -292,11 +355,17 @@ class BuildBase extends Model
$this->_setModified('commit_id');
}
/**
* Set the value of Status / status.
*
* Must not be null.
* @param $value int
*/
public function setStatus($value)
{
$this->_validateNotNull('Status', $value);
$this->_validateInt('Status', $value);
if($this->_data['status'] == $value)
if($this->_data['status'] === $value)
{
return;
}
@ -306,11 +375,16 @@ class BuildBase extends Model
$this->_setModified('status');
}
/**
* Set the value of Log / log.
*
* @param $value string
*/
public function setLog($value)
{
$this->_validateString('Log', $value);
if($this->_data['log'] == $value)
if($this->_data['log'] === $value)
{
return;
}
@ -320,11 +394,17 @@ class BuildBase extends Model
$this->_setModified('log');
}
/**
* Set the value of Branch / branch.
*
* Must not be null.
* @param $value string
*/
public function setBranch($value)
{
$this->_validateNotNull('Branch', $value);
$this->_validateString('Branch', $value);
if($this->_data['branch'] == $value)
if($this->_data['branch'] === $value)
{
return;
}
@ -334,11 +414,16 @@ class BuildBase extends Model
$this->_setModified('branch');
}
/**
* Set the value of Created / created.
*
* @param $value \DateTime
*/
public function setCreated($value)
{
$this->_validateDate('Created', $value);
if($this->_data['created'] == $value)
if($this->_data['created'] === $value)
{
return;
}
@ -348,11 +433,16 @@ class BuildBase extends Model
$this->_setModified('created');
}
/**
* Set the value of Started / started.
*
* @param $value \DateTime
*/
public function setStarted($value)
{
$this->_validateDate('Started', $value);
if($this->_data['started'] == $value)
if($this->_data['started'] === $value)
{
return;
}
@ -362,11 +452,16 @@ class BuildBase extends Model
$this->_setModified('started');
}
/**
* Set the value of Finished / finished.
*
* @param $value \DateTime
*/
public function setFinished($value)
{
$this->_validateDate('Finished', $value);
if($this->_data['finished'] == $value)
if($this->_data['finished'] === $value)
{
return;
}
@ -376,11 +471,16 @@ class BuildBase extends Model
$this->_setModified('finished');
}
/**
* Set the value of Plugins / plugins.
*
* @param $value string
*/
public function setPlugins($value)
{
$this->_validateString('Plugins', $value);
if($this->_data['plugins'] == $value)
if($this->_data['plugins'] === $value)
{
return;
}
@ -390,8 +490,6 @@ class BuildBase extends Model
$this->_setModified('plugins');
}
/**
* Get the Project model for this Build by Id.
*
@ -408,9 +506,23 @@ class BuildBase extends Model
return null;
}
return \b8\Store\Factory::getStore('Project')->getById($key);
$cacheKey = 'Cache.Project.' . $key;
$rtn = $this->registry->get($cacheKey, null);
if(empty($rtn))
{
$rtn = \b8\Store\Factory::getStore('Project')->getById($key);
$this->registry->set($cacheKey, $rtn);
}
return $rtn;
}
/**
* Set Project - Accepts an ID, an array representing a Project or a Project model.
*
* @param $value mixed
*/
public function setProject($value)
{
// Is this an instance of Project?
@ -429,11 +541,14 @@ class BuildBase extends Model
return $this->setProjectId($value);
}
/**
* Set Project - Accepts a Project model.
*
* @param $value \PHPCI\Model\Project
*/
public function setProjectObject(\PHPCI\Model\Project $value)
{
return $this->setProjectId($value->getId());
}
}

View file

@ -12,95 +12,109 @@ use b8\Model;
*/
class ProjectBase extends Model
{
public static $sleepable= array();
protected $_tableName = 'project';
protected $_modelName = 'Project';
protected $_data = array(
'id' => null,
'title' => null,
'reference' => null,
'git_key' => null,
'type' => null,
'token' => null,
);
protected $_getters = array(
'id' => 'getId',
'title' => 'getTitle',
'reference' => 'getReference',
'git_key' => 'getGitKey',
'type' => 'getType',
'token' => 'getToken',
);
protected $_setters = array(
'id' => 'setId',
'title' => 'setTitle',
'reference' => 'setReference',
'git_key' => 'setGitKey',
'type' => 'setType',
'token' => 'setToken',
);
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'title' => array(
'type' => 'varchar',
'length' => '250',
),
'reference' => array(
'type' => 'varchar',
'length' => '250',
),
'git_key' => array(
'type' => 'text',
'length' => '',
),
'type' => array(
'type' => 'varchar',
'length' => '50',
),
'token' => array(
'type' => 'varchar',
'length' => '50',
'nullable' => true,
),
);
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
);
public $foreignKeys = array(
);
/**
* @var array
*/
public static $sleepable = array();
/**
* @var string
*/
protected $_tableName = 'project';
/**
* @var string
*/
protected $_modelName = 'Project';
/**
* @var array
*/
protected $_data = array(
'id' => null,
'title' => null,
'reference' => null,
'git_key' => null,
'type' => null,
'token' => null,
);
/**
* @var array
*/
protected $_getters = array(
'id' => 'getId',
'title' => 'getTitle',
'reference' => 'getReference',
'git_key' => 'getGitKey',
'type' => 'getType',
'token' => 'getToken',
);
/**
* @var array
*/
protected $_setters = array(
'id' => 'setId',
'title' => 'setTitle',
'reference' => 'setReference',
'git_key' => 'setGitKey',
'type' => 'setType',
'token' => 'setToken',
);
/**
* @var array
*/
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'title' => array(
'type' => 'varchar',
'length' => '250',
),
'reference' => array(
'type' => 'varchar',
'length' => '250',
),
'git_key' => array(
'type' => 'text',
'length' => '',
),
'type' => array(
'type' => 'varchar',
'length' => '50',
),
'token' => array(
'type' => 'varchar',
'length' => '50',
'nullable' => true,
),
);
/**
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
);
/**
* @var array
*/
public $foreignKeys = array(
);
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->_data['id'];
@ -109,6 +123,11 @@ class ProjectBase extends Model
return $rtn;
}
/**
* Get the value of Title / title.
*
* @return string
*/
public function getTitle()
{
$rtn = $this->_data['title'];
@ -117,6 +136,11 @@ class ProjectBase extends Model
return $rtn;
}
/**
* Get the value of Reference / reference.
*
* @return string
*/
public function getReference()
{
$rtn = $this->_data['reference'];
@ -125,6 +149,11 @@ class ProjectBase extends Model
return $rtn;
}
/**
* Get the value of GitKey / git_key.
*
* @return string
*/
public function getGitKey()
{
$rtn = $this->_data['git_key'];
@ -133,6 +162,11 @@ class ProjectBase extends Model
return $rtn;
}
/**
* Get the value of Type / type.
*
* @return string
*/
public function getType()
{
$rtn = $this->_data['type'];
@ -141,6 +175,11 @@ class ProjectBase extends Model
return $rtn;
}
/**
* Get the value of Token / token.
*
* @return string
*/
public function getToken()
{
$rtn = $this->_data['token'];
@ -149,13 +188,17 @@ class ProjectBase extends Model
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
if($this->_data['id'] == $value)
if($this->_data['id'] === $value)
{
return;
}
@ -165,11 +208,17 @@ class ProjectBase extends Model
$this->_setModified('id');
}
/**
* Set the value of Title / title.
*
* Must not be null.
* @param $value string
*/
public function setTitle($value)
{
$this->_validateNotNull('Title', $value);
$this->_validateString('Title', $value);
if($this->_data['title'] == $value)
if($this->_data['title'] === $value)
{
return;
}
@ -179,11 +228,17 @@ class ProjectBase extends Model
$this->_setModified('title');
}
/**
* Set the value of Reference / reference.
*
* Must not be null.
* @param $value string
*/
public function setReference($value)
{
$this->_validateNotNull('Reference', $value);
$this->_validateString('Reference', $value);
if($this->_data['reference'] == $value)
if($this->_data['reference'] === $value)
{
return;
}
@ -193,11 +248,17 @@ class ProjectBase extends Model
$this->_setModified('reference');
}
/**
* Set the value of GitKey / git_key.
*
* Must not be null.
* @param $value string
*/
public function setGitKey($value)
{
$this->_validateNotNull('GitKey', $value);
$this->_validateString('GitKey', $value);
if($this->_data['git_key'] == $value)
if($this->_data['git_key'] === $value)
{
return;
}
@ -207,11 +268,17 @@ class ProjectBase extends Model
$this->_setModified('git_key');
}
/**
* Set the value of Type / type.
*
* Must not be null.
* @param $value string
*/
public function setType($value)
{
$this->_validateNotNull('Type', $value);
$this->_validateString('Type', $value);
if($this->_data['type'] == $value)
if($this->_data['type'] === $value)
{
return;
}
@ -221,11 +288,16 @@ class ProjectBase extends Model
$this->_setModified('type');
}
/**
* Set the value of Token / token.
*
* @param $value string
*/
public function setToken($value)
{
$this->_validateString('Token', $value);
if($this->_data['token'] == $value)
if($this->_data['token'] === $value)
{
return;
}
@ -235,10 +307,6 @@ class ProjectBase extends Model
$this->_setModified('token');
}
/**
* Get Build models by ProjectId for this Project.
*

View file

@ -12,85 +12,102 @@ use b8\Model;
*/
class UserBase extends Model
{
public static $sleepable= array();
protected $_tableName = 'user';
protected $_modelName = 'User';
protected $_data = array(
'id' => null,
'email' => null,
'hash' => null,
'is_admin' => null,
'name' => null,
);
protected $_getters = array(
'id' => 'getId',
'email' => 'getEmail',
'hash' => 'getHash',
'is_admin' => 'getIsAdmin',
'name' => 'getName',
);
protected $_setters = array(
'id' => 'setId',
'email' => 'setEmail',
'hash' => 'setHash',
'is_admin' => 'setIsAdmin',
'name' => 'setName',
);
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'email' => array(
'type' => 'varchar',
'length' => '250',
),
'hash' => array(
'type' => 'varchar',
'length' => '250',
),
'is_admin' => array(
'type' => 'tinyint',
'length' => '1',
),
'name' => array(
'type' => 'varchar',
'length' => '250',
),
);
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'idx_email' => array('unique' => true, 'columns' => 'email'),
);
public $foreignKeys = array(
);
/**
* @var array
*/
public static $sleepable = array();
/**
* @var string
*/
protected $_tableName = 'user';
/**
* @var string
*/
protected $_modelName = 'User';
/**
* @var array
*/
protected $_data = array(
'id' => null,
'email' => null,
'hash' => null,
'is_admin' => null,
'name' => null,
);
/**
* @var array
*/
protected $_getters = array(
'id' => 'getId',
'email' => 'getEmail',
'hash' => 'getHash',
'is_admin' => 'getIsAdmin',
'name' => 'getName',
);
/**
* @var array
*/
protected $_setters = array(
'id' => 'setId',
'email' => 'setEmail',
'hash' => 'setHash',
'is_admin' => 'setIsAdmin',
'name' => 'setName',
);
/**
* @var array
*/
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'email' => array(
'type' => 'varchar',
'length' => '250',
),
'hash' => array(
'type' => 'varchar',
'length' => '250',
),
'is_admin' => array(
'type' => 'tinyint',
'length' => '1',
),
'name' => array(
'type' => 'varchar',
'length' => '250',
),
);
/**
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'idx_email' => array('unique' => true, 'columns' => 'email'),
);
/**
* @var array
*/
public $foreignKeys = array(
);
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->_data['id'];
@ -99,6 +116,11 @@ class UserBase extends Model
return $rtn;
}
/**
* Get the value of Email / email.
*
* @return string
*/
public function getEmail()
{
$rtn = $this->_data['email'];
@ -107,6 +129,11 @@ class UserBase extends Model
return $rtn;
}
/**
* Get the value of Hash / hash.
*
* @return string
*/
public function getHash()
{
$rtn = $this->_data['hash'];
@ -115,6 +142,11 @@ class UserBase extends Model
return $rtn;
}
/**
* Get the value of IsAdmin / is_admin.
*
* @return int
*/
public function getIsAdmin()
{
$rtn = $this->_data['is_admin'];
@ -123,6 +155,11 @@ class UserBase extends Model
return $rtn;
}
/**
* Get the value of Name / name.
*
* @return string
*/
public function getName()
{
$rtn = $this->_data['name'];
@ -131,13 +168,17 @@ class UserBase extends Model
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
if($this->_data['id'] == $value)
if($this->_data['id'] === $value)
{
return;
}
@ -147,11 +188,17 @@ class UserBase extends Model
$this->_setModified('id');
}
/**
* Set the value of Email / email.
*
* Must not be null.
* @param $value string
*/
public function setEmail($value)
{
$this->_validateNotNull('Email', $value);
$this->_validateString('Email', $value);
if($this->_data['email'] == $value)
if($this->_data['email'] === $value)
{
return;
}
@ -161,11 +208,17 @@ class UserBase extends Model
$this->_setModified('email');
}
/**
* Set the value of Hash / hash.
*
* Must not be null.
* @param $value string
*/
public function setHash($value)
{
$this->_validateNotNull('Hash', $value);
$this->_validateString('Hash', $value);
if($this->_data['hash'] == $value)
if($this->_data['hash'] === $value)
{
return;
}
@ -175,11 +228,17 @@ class UserBase extends Model
$this->_setModified('hash');
}
/**
* Set the value of IsAdmin / is_admin.
*
* Must not be null.
* @param $value int
*/
public function setIsAdmin($value)
{
$this->_validateNotNull('IsAdmin', $value);
$this->_validateInt('IsAdmin', $value);
if($this->_data['is_admin'] == $value)
if($this->_data['is_admin'] === $value)
{
return;
}
@ -189,11 +248,17 @@ class UserBase extends Model
$this->_setModified('is_admin');
}
/**
* Set the value of Name / name.
*
* Must not be null.
* @param $value string
*/
public function setName($value)
{
$this->_validateNotNull('Name', $value);
$this->_validateString('Name', $value);
if($this->_data['name'] == $value)
if($this->_data['name'] === $value)
{
return;
}
@ -203,8 +268,4 @@ class UserBase extends Model
$this->_setModified('name');
}
}

View file

@ -7,10 +7,15 @@ class PhpUnit implements \PHPCI\Plugin
protected $directory;
protected $args;
protected $phpci;
/**
* @var string $runFrom When running PHPUnit with an XML config, the command is run from this directory
*/
protected $runFrom;
/**
* @var string $xmlConfigFile The path of an xml config for PHPUnit
*/
/**
* @var string $xmlConfigFile The path of an xml config for PHPUnit
*/
protected $xmlConfigFile;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
@ -18,6 +23,7 @@ class PhpUnit implements \PHPCI\Plugin
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $options['directory'] : null;
$this->xmlConfigFile = isset($options['config']) ? $options['config'] : null;
$this->runFrom = isset($options['run_from']) ? $options['run_from'] : null;
$this->args = isset($options['args']) ? $options['args'] : '';
}
@ -48,7 +54,15 @@ class PhpUnit implements \PHPCI\Plugin
}
else
{
return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' -c ' . $this->phpci->buildPath . $configPath);
if ($this->runFrom) {
$curdir = getcwd();
chdir($this->phpci->buildPath.'/'.$this->runFrom);
}
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' -c ' . $this->phpci->buildPath . $configPath);
if ($this->runFrom) {
chdir($curdir);
}
return $success;
}
}

View file

@ -68,7 +68,7 @@ $(document).ready(function()
// Show sign in with Github button.
var el = $('#element-reference');
var rtn = <?= json_encode((empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>;
var rtn = <?php print json_encode((empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>;
var url = 'https://github.com/login/oauth/authorize?client_id=' + window.github_app_id + '&scope=repo&redirect_uri=' + rtn;
var btn = $('<a>').addClass('btn btn-inverse').text('Sign in with Github').attr('href', url);

0
PHPCI/build/.gitkeep Normal file
View file

View file

@ -28,9 +28,8 @@ _**Please be aware that this is a brand new project, in an alpha state, so there
##Installing PHPCI:
####Pre-requisites:
* PHP 5.3+
* PHP 5.3.3+
* A web server. We prefer nginx.
* The YAML extension: `pecl install yaml`
* A MySQL server to connect to (doesn't have to be on the same server.)
* PHPCI needs to be able to run `exec()`, so make sure this is not disabled.
@ -38,7 +37,7 @@ _**Please be aware that this is a brand new project, in an alpha state, so there
####Installing from Github:
* Step 1: `git clone https://github.com/Block8/PHPCI.git`
* Step 2: `cd PHPCI`
* Step 3: `php install.php`
* Step 3: `chmod +x ./console && ./console phpci:install`
* When prompted, enter your database host, username, password and the database name that PHPCI should use.
* The script will attempt to create the database if it does not exist already.
* If you intend to use the MySQL plugin to create / destroy databases, the user you entered above will need CREATE / DELETE permissions on the server.
@ -61,7 +60,7 @@ _**Please be aware that this is a brand new project, in an alpha state, so there
Finally, you'll want to set up PHPCI to run as a regular cronjob, so run `crontab -e` and enter the following:
* * * * * /usr/bin/php /path/to/phpci/cron.php
* * * * * /usr/bin/php /path/to/phpci/console phpci:run-builds
Obviously, make sure you change the `/path/to/phpci` to the directory in which you installed PHPCI, and update the PHP path if necessary.
@ -88,6 +87,7 @@ Similar to Travis CI, to support PHPCI in your project, you simply need to add a
- "PHPUnit-ubuntu-fix.xml"
directory:
- "tests/"
run_from: "phpunit/"
php_mess_detector:
allow_failures: true
php_code_sniffer:
@ -110,7 +110,9 @@ As mentioned earlier, PHPCI is powered by plugins, there are several phases in w
The `ignore` section is merely an array of paths that should be ignored in all tests (where possible.)
##Contributing
Contributions from others would be very much appreciated! Simply fork the repository, and send us a pull request when you're ready.
Contributions from others would be very much appreciated! If you just want to make a simple change, simply fork the repository, and send us a pull request when you're ready.
If you'd like to get more involved in developing PHPCI or to become a maintainer / committer on the main PHPCI repository, join the [mailing list](https://groups.google.com/forum/#!forum/php-ci).
##Questions?
Email us at hello+phpci@block8.co.uk and we'll do our best to help!
Your best place to go is the [mailing list](https://groups.google.com/forum/#!forum/php-ci), if you're already a member of the mailing list, you can simply email php-ci@googlegroups.com.

View file

@ -1,5 +1,7 @@
<?php
date_default_timezone_set(@date_default_timezone_get());
spl_autoload_register(function ($class)
{
$file = str_replace(array('\\', '_'), '/', $class);
@ -21,7 +23,11 @@ spl_autoload_register(function ($class)
define('APPLICATION_PATH', dirname(__FILE__) . '/');
require_once('vendor/autoload.php');
require_once('config.php');
if(file_exists(APPLICATION_PATH . 'config.php'))
{
require('config.php');
}
b8\Registry::getInstance()->set('app_namespace', 'PHPCI');
b8\Registry::getInstance()->set('DefaultController', 'Index');

0
build/.gitkeep Normal file
View file

View file

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

17
console Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php
require_once('bootstrap.php');
use PHPCI\Command\RunCommand;
use PHPCI\Command\GenerateCommand;
use PHPCI\Command\InstallCommand;
use Symfony\Component\Console\Application;
define('PHPCI_BIN_DIR', dirname(__FILE__) . '/vendor/bin/');
define('PHPCI_DIR', dirname(__FILE__) . '/');
$application = new Application();
$application->add(new RunCommand);
$application->add(new InstallCommand);
$application->add(new GenerateCommand);
$application->run();

View file

@ -1,18 +0,0 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
require_once('bootstrap.php');
define('PHPCI_BIN_DIR', dirname(__FILE__) . '/vendor/bin/');
define('PHPCI_DIR', dirname(__FILE__) . '/');
$store = b8\Store\Factory::getStore('Build');
$result = $store->getByStatus(0);
foreach($result['items'] as $build)
{
$builder = new PHPCI\Builder($build);
$builder->execute();
}

View file

@ -1,7 +0,0 @@
<?php
require_once('bootstrap.php');
$gen = new b8\Database\CodeGenerator(b8\Database::getConnection(), 'PHPCI', './PHPCI/');
$gen->generateModels();
$gen->generateStores();

View file

@ -1,95 +0,0 @@
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
$dbHost = ask('Enter your MySQL host: ');
$dbName = ask('Enter the database name PHPCI should use: ');
$dbUser = ask('Enter your MySQL username: ');
$dbPass = ask('Enter your MySQL password: ', true);
$ciUrl = ask('Your PHPCI URL (without trailing slash): ', true);
$ghId = ask('(Optional) Github Application ID: ', true);
$ghSecret = ask('(Optional) Github Application Secret: ', true);
$cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost . ' -e "CREATE DATABASE IF NOT EXISTS ' . $dbName . '"';
shell_exec($cmd);
$str = "<?php
define('PHPCI_DB_HOST', '{$dbHost}');
b8\Database::setDetails('{$dbName}', '{$dbUser}', '{$dbPass}');
b8\Database::setWriteServers(array('{$dbHost}'));
b8\Database::setReadServers(array('{$dbHost}'));
\$registry = b8\Registry::getInstance();
\$registry->set('install_url', '{$ciUrl}');
";
if(!empty($ghId) && !empty($ghSecret))
{
$str .= PHP_EOL . "\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" . PHP_EOL;
}
file_put_contents('./config.php', $str);
if(!file_exists('./composer.phar'))
{
print 'INSTALLING: Composer' . PHP_EOL;
file_put_contents('./composerinstaller.php', file_get_contents('https://getcomposer.org/installer'));
shell_exec('php composerinstaller.php');
unlink('./composerinstaller.php');
}
print 'RUNNING: Composer' . PHP_EOL;
shell_exec('php composer.phar install');
require_once('bootstrap.php');
$gen = new b8\Database\Generator(b8\Database::getConnection(), 'PHPCI', './PHPCI/Model/Base/');
$gen->generate();
$adminEmail = ask('Enter your email address: ');
$adminPass = ask('Enter your desired admin password: ');
$adminName = ask('Enter your name: ');
try
{
$user = new PHPCI\Model\User();
$user->setEmail($adminEmail);
$user->setName($adminName);
$user->setIsAdmin(1);
$user->setHash(password_hash($adminPass, PASSWORD_DEFAULT));
$store = b8\Store\Factory::getStore('User');
$store->save($user);
print 'User account created!' . PHP_EOL;
}
catch(Exception $ex)
{
print 'There was a problem creating your account. :(' . PHP_EOL;
print $ex->getMessage();
}
function ask($question, $emptyOk = false)
{
print $question . ' ';
$rtn = '';
$fp = fopen('php://stdin', 'r');
$rtn = fgets($fp);
fclose($fp);
$rtn = trim($rtn);
if(!$emptyOk && empty($rtn))
{
$rtn = ask($question, $emptyOk);
}
return $rtn;
}