Adding the ability to run projects with no build configuration. Runs what plugins it can automatically. Closes #235
This commit is contained in:
parent
099d342871
commit
2e4e3129b7
9 changed files with 224 additions and 28 deletions
|
|
@ -88,20 +88,73 @@ class Build extends BuildBase
|
|||
*/
|
||||
protected function handleConfig(Builder $builder, $buildPath)
|
||||
{
|
||||
$build_config = null;
|
||||
|
||||
// Try phpci.yml first:
|
||||
if (is_file($buildPath . '/phpci.yml')) {
|
||||
$build_config = file_get_contents($buildPath . '/phpci.yml');
|
||||
}
|
||||
|
||||
if (!is_file($buildPath . '/phpci.yml') || !$build_config) {
|
||||
// Try getting the project build config from the database:
|
||||
if (empty($build_config)) {
|
||||
$build_config = $this->getProject()->getBuildConfig();
|
||||
if (!$build_config) {
|
||||
$builder->logFailure('Project does not contain a phpci.yml file.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fall back to zero config plugins:
|
||||
if (empty($build_config)) {
|
||||
$build_config = $this->getZeroConfigPlugins($builder);
|
||||
}
|
||||
|
||||
if (is_string($build_config)) {
|
||||
$yamlParser = new YamlParser();
|
||||
$build_config = $yamlParser->parse($build_config);
|
||||
}
|
||||
|
||||
$builder->setConfigArray($build_config);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getZeroConfigPlugins(Builder $builder)
|
||||
{
|
||||
$pluginDir = PHPCI_DIR . 'PHPCI/Plugin/';
|
||||
$dir = new \DirectoryIterator($pluginDir);
|
||||
|
||||
$config = array(
|
||||
'build_settings' => array(
|
||||
'ignore' => array(
|
||||
'vendor/',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($dir as $item) {
|
||||
if ($item->isDot()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$item->isFile()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$className = '\PHPCI\Plugin\\'.$item->getBasename('.php');
|
||||
|
||||
$reflectedPlugin = new \ReflectionClass($className);
|
||||
|
||||
if (!$reflectedPlugin->implementsInterface('\PHPCI\ZeroConfigPlugin')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (array('setup', 'test', 'complete', 'success', 'failure') as $stage) {
|
||||
if ($className::canExecute($stage, $builder, $this)) {
|
||||
$config[$stage][$className] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$yamlParser = new YamlParser();
|
||||
$builder->setConfigArray($yamlParser->parse($build_config));
|
||||
return $builder->getConfig('build_settings');
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue