Added database-based yml build config

This commit is contained in:
Dmitry Khomutov 2014-03-15 12:18:12 +07:00
parent ca13b65022
commit 60bf262ee7
5 changed files with 88 additions and 32 deletions

View file

@ -318,6 +318,14 @@ class ProjectController extends \PHPCI\Controller
$field->setRows(6);
$form->addField($field);
$field = new Form\Element\TextArea('build_config');
$field->setRequired(false);
$field->setLabel('PHPCI build config for this project (instead phpci.yml in the project repository)');
$field->setClass('form-control');
$field->setContainerClass('form-group');
$field->setRows(6);
$form->addField($field);
$field = new Form\Element\Submit();
$field->setValue('Save Project');
$field->setContainerClass('form-group');

View file

@ -37,6 +37,7 @@ class ProjectBase extends Model
'title' => null,
'reference' => null,
'git_key' => null,
'build_config' => null,
'type' => null,
'token' => null,
'access_information' => null,
@ -52,6 +53,7 @@ class ProjectBase extends Model
'title' => 'getTitle',
'reference' => 'getReference',
'git_key' => 'getGitKey',
'build_config' => 'getBuildConfig',
'type' => 'getType',
'token' => 'getToken',
'access_information' => 'getAccessInformation',
@ -69,6 +71,7 @@ class ProjectBase extends Model
'title' => 'setTitle',
'reference' => 'setReference',
'git_key' => 'setGitKey',
'build_config' => 'setBuildConfig',
'type' => 'setType',
'token' => 'setToken',
'access_information' => 'setAccessInformation',
@ -103,6 +106,11 @@ class ProjectBase extends Model
'nullable' => true,
'default' => null,
),
'build_config' => array(
'type' => 'text',
'nullable' => true,
'default' => null,
),
'type' => array(
'type' => 'varchar',
'length' => 50,
@ -132,8 +140,8 @@ class ProjectBase extends Model
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'idx_project_title' => array('columns' => 'title'),
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'idx_project_title' => array('columns' => 'title'),
);
/**
@ -149,7 +157,7 @@ class ProjectBase extends Model
*/
public function getId()
{
$rtn = $this->data['id'];
$rtn = $this->data['id'];
return $rtn;
}
@ -161,7 +169,7 @@ class ProjectBase extends Model
*/
public function getTitle()
{
$rtn = $this->data['title'];
$rtn = $this->data['title'];
return $rtn;
}
@ -173,7 +181,7 @@ class ProjectBase extends Model
*/
public function getReference()
{
$rtn = $this->data['reference'];
$rtn = $this->data['reference'];
return $rtn;
}
@ -185,7 +193,19 @@ class ProjectBase extends Model
*/
public function getGitKey()
{
$rtn = $this->data['git_key'];
$rtn = $this->data['git_key'];
return $rtn;
}
/**
* Get the value of BuildConfig / build_config.
*
* @return string
*/
public function getBuildConfig()
{
$rtn = $this->data['build_config'];
return $rtn;
}
@ -197,7 +217,7 @@ class ProjectBase extends Model
*/
public function getType()
{
$rtn = $this->data['type'];
$rtn = $this->data['type'];
return $rtn;
}
@ -209,7 +229,7 @@ class ProjectBase extends Model
*/
public function getToken()
{
$rtn = $this->data['token'];
$rtn = $this->data['token'];
return $rtn;
}
@ -221,7 +241,7 @@ class ProjectBase extends Model
*/
public function getAccessInformation()
{
$rtn = $this->data['access_information'];
$rtn = $this->data['access_information'];
return $rtn;
}
@ -233,7 +253,7 @@ class ProjectBase extends Model
*/
public function getLastCommit()
{
$rtn = $this->data['last_commit'];
$rtn = $this->data['last_commit'];
return $rtn;
}
@ -316,6 +336,24 @@ class ProjectBase extends Model
$this->_setModified('git_key');
}
/**
* Set the value of BuildConfig / build_config.
*
* @param $value string
*/
public function setBuildConfig($value)
{
$this->_validateString('BuildConfig', $value);
if ($this->data['build_config'] === $value) {
return;
}
$this->data['build_config'] = $value;
$this->_setModified('build_config');
}
/**
* Set the value of Type / type.
*

View file

@ -86,15 +86,18 @@ class LocalBuild extends Build
protected function handleConfig(Builder $builder, $reference)
{
/** @todo Add support for database-based yml definition */
if (!is_file($reference . '/phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$build_config = $this->getProject()->getBuildConfig();
if (!$build_config)
{
if (!is_file($reference . '/phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$build_config = file_get_contents($reference . '/phpci.yml');
}
$yamlParser = new YamlParser();
$yamlFile = file_get_contents($reference . '/phpci.yml');
$builder->setConfigArray($yamlParser->parse($yamlFile));
$builder->setConfigArray($yamlParser->parse($build_config));
return $builder->getConfig('build_settings');
}
}

View file

@ -34,17 +34,20 @@ class MercurialBuild extends Build
*/
public function createWorkingCopy(Builder $builder, $buildPath)
{
$yamlParser = new YamlParser();
$this->cloneByHttp($builder, $buildPath);
if (!is_file($buildPath . 'phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$build_config = $this->getProject()->getBuildConfig();
if (!$build_config)
{
if (!is_file($buildPath . '/phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$build_config = file_get_contents($buildPath . '/phpci.yml');
}
$yamlFile = file_get_contents($buildPath . 'phpci.yml');
$builder->setConfigArray($yamlParser->parse($yamlFile));
$yamlParser = new YamlParser();
$builder->setConfigArray($yamlParser->parse($build_config));
return true;
}

View file

@ -34,7 +34,6 @@ class RemoteGitBuild extends Build
*/
public function createWorkingCopy(Builder $builder, $buildPath)
{
$yamlParser = new YamlParser();
$key = trim($this->getProject()->getGitKey());
if (!empty($key)) {
@ -48,13 +47,18 @@ class RemoteGitBuild extends Build
return false;
}
if (!is_file($buildPath . 'phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$build_config = $this->getProject()->getBuildConfig();
if (!$build_config)
{
if (!is_file($buildPath . '/phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$build_config = file_get_contents($buildPath . '/phpci.yml');
}
$yamlFile = file_get_contents($buildPath . 'phpci.yml');
$builder->setConfigArray($yamlParser->parse($yamlFile));
$yamlParser = new YamlParser();
$builder->setConfigArray($yamlParser->parse($build_config));
return true;
}